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; |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 36 | import android.compat.annotation.ChangeId; |
| 37 | import android.compat.annotation.EnabledSince; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 38 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 39 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 40 | import android.content.Context; |
| 41 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 42 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 43 | import android.content.pm.ComponentInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 44 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.net.Uri; |
| 46 | import android.os.AsyncResult; |
| 47 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 48 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 49 | import android.os.Bundle; |
| 50 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 51 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 52 | import android.os.Looper; |
| 53 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 54 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 55 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 56 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 57 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 58 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 59 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 60 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 61 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 62 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 63 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 64 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 65 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 66 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 67 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 68 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 69 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 70 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 71 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 72 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 73 | import android.telecom.TelecomManager; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 74 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 75 | import android.telephony.Annotation.ThermalMitigationResult; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 76 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 77 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 78 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 79 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 80 | import android.telephony.CellIdentityCdma; |
| 81 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 82 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 83 | import android.telephony.CellInfoGsm; |
| 84 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 85 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 86 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 87 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 88 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 89 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 90 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 91 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 92 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 93 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 94 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 95 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 96 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 97 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 98 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 99 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 100 | import android.telephony.SignalStrengthUpdateRequest; |
| 101 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 102 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 103 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 104 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 105 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 106 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 107 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 108 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 109 | import android.telephony.UiccCardInfo; |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 110 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 111 | import android.telephony.UiccSlotInfo; |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 112 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 113 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 114 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 115 | import android.telephony.data.ApnSetting; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 116 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 117 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 118 | import android.telephony.gba.GbaAuthRequest; |
| 119 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 120 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 121 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 122 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 123 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 124 | import android.telephony.ims.RegistrationManager; |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 125 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 126 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 127 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 128 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 129 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 130 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 131 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 132 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 133 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 134 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 135 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 136 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 137 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 138 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 139 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 140 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 141 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 142 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 143 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 144 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 145 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 146 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 147 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d457521 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | a743688 | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 155 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 160 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | c7ebc0f | 2021-11-15 23:46:41 +0000 | [diff] [blame] | 162 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 164 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.IccCard; |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 173 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 178 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 179 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 181 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 183 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 184 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 185 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 187 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 188 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 189 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 191 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | fa31464 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 192 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 193 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 194 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 195 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 196 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 197 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 198 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 199 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 200 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 201 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 202 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 203 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 204 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 205 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 206 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 207 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 208 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 209 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 210 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 211 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 212 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 213 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 214 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 215 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 216 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 217 | import com.android.services.telephony.TelecomAccountRegistry; |
| 218 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 219 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 220 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 221 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 222 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 223 | import java.io.IOException; |
| 224 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 225 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 226 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 227 | import java.util.Arrays; |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 228 | import java.util.Collection; |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 229 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 230 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 231 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 232 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 233 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 234 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 235 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 236 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 237 | import java.util.Set; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 238 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 239 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 240 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 241 | |
| 242 | /** |
| 243 | * Implementation of the ITelephony interface. |
| 244 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 245 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 246 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 247 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 248 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 249 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 250 | |
| 251 | // Message codes used with mMainThreadHandler |
| 252 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 253 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 254 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 255 | private static final int CMD_OPEN_CHANNEL = 9; |
| 256 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 257 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 258 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 259 | private static final int CMD_NV_READ_ITEM = 13; |
| 260 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 261 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 262 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 263 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 264 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 265 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 266 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 267 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 268 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 269 | private static final int CMD_SEND_ENVELOPE = 25; |
| 270 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 271 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 272 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 273 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 274 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 275 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 276 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 277 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 278 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 279 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 280 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 281 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 282 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 283 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 284 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 285 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 286 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 287 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 288 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 289 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 290 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 291 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 292 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 293 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 294 | private static final int CMD_SWITCH_SLOTS = 50; |
| 295 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 296 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 297 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 298 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 299 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 300 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 301 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 302 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 303 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 304 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 305 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 306 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 307 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 308 | private static final int CMD_MODEM_REBOOT = 64; |
| 309 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 310 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 311 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 312 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 313 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 314 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 315 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 316 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 317 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 318 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 319 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 320 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 321 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 322 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 323 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 324 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 325 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 326 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 327 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 328 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 329 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 330 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 331 | private static final int CMD_GET_CALL_WAITING = 87; |
| 332 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 333 | private static final int CMD_SET_CALL_WAITING = 89; |
| 334 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 335 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 336 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 337 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 338 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 339 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 340 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 341 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 342 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 343 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 344 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 345 | private static final int CMD_SET_SIM_POWER = 101; |
| 346 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 347 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 348 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 349 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 350 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 351 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 352 | 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] | 353 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 354 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 355 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 356 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | bf5c79c | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 357 | private static final int CMD_ENABLE_VONR = 113; |
| 358 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 359 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 360 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 361 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 362 | // Parameters of select command. |
| 363 | private static final int SELECT_COMMAND = 0xA4; |
| 364 | private static final int SELECT_P1 = 0x04; |
| 365 | private static final int SELECT_P2 = 0; |
| 366 | private static final int SELECT_P3 = 0x10; |
| 367 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 368 | /** The singleton instance. */ |
| 369 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 370 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 371 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 372 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 373 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 374 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 375 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 376 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 377 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 378 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 379 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 380 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 381 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 382 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 383 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 384 | /** User Activity */ |
| 385 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 386 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 387 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 388 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 389 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 390 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 391 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 392 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 393 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 394 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 395 | // String to store multi SIM allowed |
| 396 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 397 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 398 | // The AID of ISD-R. |
| 399 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 400 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 401 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 402 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 403 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 404 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 405 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 406 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 407 | 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] | 408 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 409 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 410 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 411 | */ |
| 412 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 413 | "reset_network_erase_modem_config_enabled"; |
| 414 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 415 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 416 | /** |
| 417 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 418 | * one ICCID active at the same time. |
| 419 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 420 | * |
| 421 | * @hide |
| 422 | */ |
| 423 | @ChangeId |
| 424 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 425 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 426 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 427 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 428 | * A request object to use for transmitting data to an ICC. |
| 429 | */ |
| 430 | private static final class IccAPDUArgument { |
| 431 | public int channel, cla, command, p1, p2, p3; |
| 432 | public String data; |
| 433 | |
| 434 | public IccAPDUArgument(int channel, int cla, int command, |
| 435 | int p1, int p2, int p3, String data) { |
| 436 | this.channel = channel; |
| 437 | this.cla = cla; |
| 438 | this.command = command; |
| 439 | this.p1 = p1; |
| 440 | this.p2 = p2; |
| 441 | this.p3 = p3; |
| 442 | this.data = data; |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 447 | * A request object to use for transmitting data to an ICC. |
| 448 | */ |
| 449 | private static final class ManualNetworkSelectionArgument { |
| 450 | public OperatorInfo operatorInfo; |
| 451 | public boolean persistSelection; |
| 452 | |
| 453 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 454 | this.operatorInfo = operatorInfo; |
| 455 | this.persistSelection = persistSelection; |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 460 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 461 | * request after sending. The main thread will notify the request when it is complete. |
| 462 | */ |
| 463 | private static final class MainThreadRequest { |
| 464 | /** The argument to use for the request */ |
| 465 | public Object argument; |
| 466 | /** The result of the request that is run on the main thread */ |
| 467 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 468 | // The subscriber id that this request applies to. Defaults to |
| 469 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 470 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 471 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 472 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 473 | public Phone phone; |
| 474 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 475 | public WorkSource workSource; |
| 476 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 477 | public MainThreadRequest(Object argument) { |
| 478 | this.argument = argument; |
| 479 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 480 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 481 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 482 | this.argument = argument; |
| 483 | if (phone != null) { |
| 484 | this.phone = phone; |
| 485 | } |
| 486 | this.workSource = workSource; |
| 487 | } |
| 488 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 489 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 490 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 491 | if (subId != null) { |
| 492 | this.subId = subId; |
| 493 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 494 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 495 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 496 | } |
| 497 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 498 | private static final class IncomingThirdPartyCallArgs { |
| 499 | public final ComponentName component; |
| 500 | public final String callId; |
| 501 | public final String callerDisplayName; |
| 502 | |
| 503 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 504 | String callerDisplayName) { |
| 505 | this.component = component; |
| 506 | this.callId = callId; |
| 507 | this.callerDisplayName = callerDisplayName; |
| 508 | } |
| 509 | } |
| 510 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 511 | /** |
| 512 | * A handler that processes messages on the main thread in the phone process. Since many |
| 513 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 514 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 515 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 516 | * on, which will be notified when the operation completes and will contain the result of the |
| 517 | * request. |
| 518 | * |
| 519 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 520 | * note that request.result must be set to something non-null for the calling thread to |
| 521 | * unblock. |
| 522 | */ |
| 523 | private final class MainThreadHandler extends Handler { |
| 524 | @Override |
| 525 | public void handleMessage(Message msg) { |
| 526 | MainThreadRequest request; |
| 527 | Message onCompleted; |
| 528 | AsyncResult ar; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 529 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 530 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 531 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 532 | |
| 533 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 534 | case CMD_HANDLE_USSD_REQUEST: { |
| 535 | request = (MainThreadRequest) msg.obj; |
| 536 | final Phone phone = getPhoneFromRequest(request); |
| 537 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 538 | String ussdRequest = ussdObject.first; |
| 539 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 540 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 541 | if (!isUssdApiAllowed(request.subId)) { |
| 542 | // Carrier does not support use of this API, return failure. |
| 543 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 544 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 545 | Bundle returnData = new Bundle(); |
| 546 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 547 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 548 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 549 | request.result = true; |
| 550 | notifyRequester(request); |
| 551 | return; |
| 552 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 553 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 554 | try { |
| 555 | request.result = phone != null |
| 556 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 557 | } catch (CallStateException cse) { |
| 558 | request.result = false; |
| 559 | } |
| 560 | // Wake up the requesting thread |
| 561 | notifyRequester(request); |
| 562 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 565 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 566 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 567 | final Phone phone = getPhoneFromRequest(request); |
| 568 | request.result = phone != null ? |
| 569 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 570 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 571 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 572 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 573 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 574 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 575 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 576 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 577 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 578 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 579 | uiccPort = getUiccPortFromRequest(request); |
| 580 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 581 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 582 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 583 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 584 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 585 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 586 | request); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 587 | uiccPort.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 588 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 589 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 590 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 591 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 592 | break; |
| 593 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 594 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 595 | ar = (AsyncResult) msg.obj; |
| 596 | request = (MainThreadRequest) ar.userObj; |
| 597 | if (ar.exception == null && ar.result != null) { |
| 598 | request.result = ar.result; |
| 599 | } else { |
| 600 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 601 | if (ar.result == null) { |
| 602 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 603 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 604 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 605 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 606 | } else { |
| 607 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 608 | } |
| 609 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 610 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 611 | break; |
| 612 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 613 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 614 | request = (MainThreadRequest) msg.obj; |
| 615 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 616 | uiccPort = getUiccPortFromRequest(request); |
| 617 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 618 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 619 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 620 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 621 | } else { |
| 622 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 623 | request); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 624 | uiccPort.iccTransmitApduBasicChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 625 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 626 | iccArgument.p3, iccArgument.data, onCompleted); |
| 627 | } |
| 628 | break; |
| 629 | |
| 630 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 631 | ar = (AsyncResult) msg.obj; |
| 632 | request = (MainThreadRequest) ar.userObj; |
| 633 | if (ar.exception == null && ar.result != null) { |
| 634 | request.result = ar.result; |
| 635 | } else { |
| 636 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 637 | if (ar.result == null) { |
| 638 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 639 | } else if (ar.exception instanceof CommandException) { |
| 640 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 641 | ar.exception); |
| 642 | } else { |
| 643 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 644 | } |
| 645 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 646 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 647 | break; |
| 648 | |
| 649 | case CMD_EXCHANGE_SIM_IO: |
| 650 | request = (MainThreadRequest) msg.obj; |
| 651 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 652 | uiccPort = getUiccPortFromRequest(request); |
| 653 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 654 | loge("iccExchangeSimIO: No UICC"); |
| 655 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
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 | } else { |
| 658 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 659 | request); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 660 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 661 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 662 | iccArgument.data, onCompleted); |
| 663 | } |
| 664 | break; |
| 665 | |
| 666 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 667 | ar = (AsyncResult) msg.obj; |
| 668 | request = (MainThreadRequest) ar.userObj; |
| 669 | if (ar.exception == null && ar.result != null) { |
| 670 | request.result = ar.result; |
| 671 | } else { |
| 672 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 673 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 674 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 675 | break; |
| 676 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 677 | case CMD_SEND_ENVELOPE: |
| 678 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 679 | uiccPort = getUiccPortFromRequest(request); |
| 680 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 681 | loge("sendEnvelopeWithStatus: No UICC"); |
| 682 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 683 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 684 | } else { |
| 685 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 686 | uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 687 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 688 | break; |
| 689 | |
| 690 | case EVENT_SEND_ENVELOPE_DONE: |
| 691 | ar = (AsyncResult) msg.obj; |
| 692 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 693 | if (ar.exception == null && ar.result != null) { |
| 694 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 695 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 696 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 697 | if (ar.result == null) { |
| 698 | loge("sendEnvelopeWithStatus: Empty response"); |
| 699 | } else if (ar.exception instanceof CommandException) { |
| 700 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 701 | ar.exception); |
| 702 | } else { |
| 703 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 704 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 705 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 706 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 707 | break; |
| 708 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 709 | case CMD_OPEN_CHANNEL: |
| 710 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 711 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 712 | IccLogicalChannelRequest openChannelRequest = |
| 713 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 714 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 715 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 716 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 717 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 718 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 719 | } else { |
| 720 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 721 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 722 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 723 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 724 | break; |
| 725 | |
| 726 | case EVENT_OPEN_CHANNEL_DONE: |
| 727 | ar = (AsyncResult) msg.obj; |
| 728 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 729 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 730 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 731 | int[] result = (int[]) ar.result; |
| 732 | int channelId = result[0]; |
| 733 | byte[] selectResponse = null; |
| 734 | if (result.length > 1) { |
| 735 | selectResponse = new byte[result.length - 1]; |
| 736 | for (int i = 1; i < result.length; ++i) { |
| 737 | selectResponse[i - 1] = (byte) result[i]; |
| 738 | } |
| 739 | } |
| 740 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 741 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 742 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 743 | if (ar.result == null) { |
| 744 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 745 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 746 | if (ar.exception != null) { |
| 747 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 748 | } |
| 749 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 750 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 751 | if (ar.exception instanceof CommandException) { |
| 752 | CommandException.Error error = |
| 753 | ((CommandException) (ar.exception)).getCommandError(); |
| 754 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 755 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 756 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 757 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 758 | } |
| 759 | } |
| 760 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 761 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 762 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 763 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 764 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 765 | break; |
| 766 | |
| 767 | case CMD_CLOSE_CHANNEL: |
| 768 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 769 | uiccPort = getUiccPortFromRequest(request); |
| 770 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 771 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 772 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 773 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 774 | } else { |
| 775 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 776 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 777 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 778 | break; |
| 779 | |
| 780 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 781 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 782 | break; |
| 783 | |
| 784 | case CMD_NV_READ_ITEM: |
| 785 | request = (MainThreadRequest) msg.obj; |
| 786 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 787 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 788 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 789 | break; |
| 790 | |
| 791 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 792 | ar = (AsyncResult) msg.obj; |
| 793 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 794 | if (ar.exception == null && ar.result != null) { |
| 795 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 796 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 797 | request.result = ""; |
| 798 | if (ar.result == null) { |
| 799 | loge("nvReadItem: Empty response"); |
| 800 | } else if (ar.exception instanceof CommandException) { |
| 801 | loge("nvReadItem: CommandException: " + |
| 802 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 803 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 804 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 805 | } |
| 806 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 807 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 808 | break; |
| 809 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 810 | case CMD_NV_WRITE_ITEM: |
| 811 | request = (MainThreadRequest) msg.obj; |
| 812 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 813 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 814 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 815 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 816 | break; |
| 817 | |
| 818 | case EVENT_NV_WRITE_ITEM_DONE: |
| 819 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 820 | break; |
| 821 | |
| 822 | case CMD_NV_WRITE_CDMA_PRL: |
| 823 | request = (MainThreadRequest) msg.obj; |
| 824 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 825 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 826 | break; |
| 827 | |
| 828 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 829 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 830 | break; |
| 831 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 832 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 833 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 834 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 835 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 836 | break; |
| 837 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 838 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 839 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 840 | break; |
| 841 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 842 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 843 | request = (MainThreadRequest) msg.obj; |
| 844 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 845 | request); |
| 846 | Phone phone = getPhoneFromRequest(request); |
| 847 | if (phone != null) { |
| 848 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 849 | } else { |
| 850 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 851 | request.result = false; |
| 852 | notifyRequester(request); |
| 853 | } |
| 854 | break; |
| 855 | } |
| 856 | |
| 857 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 858 | ar = (AsyncResult) msg.obj; |
| 859 | request = (MainThreadRequest) ar.userObj; |
| 860 | if (ar.exception == null && ar.result != null) { |
| 861 | request.result = ar.result; |
| 862 | } else { |
| 863 | // request.result must be set to something non-null |
| 864 | // for the calling thread to unblock |
Sooraj Sasindran | bf5c79c | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 865 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 866 | request.result = ar.result; |
| 867 | } else { |
| 868 | request.result = false; |
| 869 | } |
| 870 | if (ar.result == null) { |
| 871 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 872 | } else if (ar.exception instanceof CommandException) { |
| 873 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 874 | + ar.exception); |
| 875 | } else { |
| 876 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 877 | } |
| 878 | } |
| 879 | notifyRequester(request); |
| 880 | break; |
| 881 | |
Sooraj Sasindran | bf5c79c | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 882 | case CMD_IS_VONR_ENABLED: { |
| 883 | request = (MainThreadRequest) msg.obj; |
| 884 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 885 | request); |
| 886 | Phone phone = getPhoneFromRequest(request); |
| 887 | if (phone != null) { |
| 888 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 889 | } else { |
| 890 | loge("isVoNrEnabled: No phone object"); |
| 891 | request.result = false; |
| 892 | notifyRequester(request); |
| 893 | } |
| 894 | break; |
| 895 | } |
| 896 | |
| 897 | case EVENT_IS_VONR_ENABLED_DONE: |
| 898 | ar = (AsyncResult) msg.obj; |
| 899 | request = (MainThreadRequest) ar.userObj; |
| 900 | if (ar.exception == null && ar.result != null) { |
| 901 | request.result = ar.result; |
| 902 | } else { |
| 903 | // request.result must be set to something non-null |
| 904 | // for the calling thread to unblock |
| 905 | if (ar.result != null) { |
| 906 | request.result = ar.result; |
| 907 | } else { |
| 908 | request.result = false; |
| 909 | } |
| 910 | if (ar.result == null) { |
| 911 | loge("isVoNrEnabled: Empty response"); |
| 912 | } else if (ar.exception instanceof CommandException) { |
| 913 | loge("isVoNrEnabled: CommandException: " |
| 914 | + ar.exception); |
| 915 | } else { |
| 916 | loge("isVoNrEnabled: Unknown exception"); |
| 917 | } |
| 918 | } |
| 919 | notifyRequester(request); |
| 920 | break; |
| 921 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 922 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 923 | request = (MainThreadRequest) msg.obj; |
| 924 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 925 | Phone phone = getPhoneFromRequest(request); |
| 926 | if (phone != null) { |
| 927 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 928 | request.workSource); |
| 929 | } else { |
| 930 | loge("enableNrDualConnectivity: No phone object"); |
| 931 | request.result = |
| 932 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 933 | notifyRequester(request); |
| 934 | } |
| 935 | break; |
| 936 | } |
| 937 | |
| 938 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 939 | ar = (AsyncResult) msg.obj; |
| 940 | request = (MainThreadRequest) ar.userObj; |
| 941 | if (ar.exception == null) { |
| 942 | request.result = |
| 943 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 944 | } else { |
| 945 | request.result = |
| 946 | TelephonyManager |
| 947 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 948 | if (ar.exception instanceof CommandException) { |
| 949 | CommandException.Error error = |
| 950 | ((CommandException) (ar.exception)).getCommandError(); |
| 951 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 952 | request.result = |
| 953 | TelephonyManager |
| 954 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 955 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 956 | request.result = |
| 957 | TelephonyManager |
| 958 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 959 | } |
| 960 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 961 | + ar.exception); |
| 962 | } else { |
| 963 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 964 | } |
| 965 | } |
| 966 | notifyRequester(request); |
| 967 | break; |
| 968 | } |
| 969 | |
Sooraj Sasindran | bf5c79c | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 970 | case CMD_ENABLE_VONR: { |
| 971 | request = (MainThreadRequest) msg.obj; |
| 972 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 973 | Phone phone = getPhoneFromRequest(request); |
| 974 | if (phone != null) { |
| 975 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 976 | request.workSource); |
| 977 | } else { |
| 978 | loge("setVoNrEnabled: No phone object"); |
| 979 | request.result = |
| 980 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 981 | notifyRequester(request); |
| 982 | } |
| 983 | break; |
| 984 | } |
| 985 | |
| 986 | case EVENT_ENABLE_VONR_DONE: { |
| 987 | ar = (AsyncResult) msg.obj; |
| 988 | request = (MainThreadRequest) ar.userObj; |
| 989 | if (ar.exception == null) { |
| 990 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 991 | } else { |
| 992 | request.result = TelephonyManager.ENABLE_VONR_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 = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 998 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 999 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1000 | } else { |
| 1001 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1002 | } |
| 1003 | loge("setVoNrEnabled" + ": CommandException: " |
| 1004 | + ar.exception); |
| 1005 | } else { |
| 1006 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1007 | } |
| 1008 | } |
| 1009 | notifyRequester(request); |
| 1010 | break; |
| 1011 | } |
| 1012 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1013 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1014 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1015 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1016 | request); |
| 1017 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1018 | break; |
| 1019 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1020 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1021 | ar = (AsyncResult) msg.obj; |
| 1022 | request = (MainThreadRequest) ar.userObj; |
| 1023 | if (ar.exception == null && ar.result != null) { |
| 1024 | request.result = ar.result; // Integer |
| 1025 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1026 | // request.result must be set to something non-null |
| 1027 | // for the calling thread to unblock |
| 1028 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1029 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1030 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1031 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1032 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1033 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1034 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1035 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1036 | } |
| 1037 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1038 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1039 | break; |
| 1040 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1041 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1042 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1043 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1044 | request); |
| 1045 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1046 | (Pair<Integer, Long>) request.argument; |
| 1047 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1048 | reasonWithNetworkTypes.first, |
| 1049 | reasonWithNetworkTypes.second, |
| 1050 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1051 | break; |
| 1052 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1053 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1054 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1055 | break; |
| 1056 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1057 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1058 | request = (MainThreadRequest)msg.obj; |
| 1059 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1060 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1061 | break; |
| 1062 | |
| 1063 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1064 | ar = (AsyncResult)msg.obj; |
| 1065 | request = (MainThreadRequest)ar.userObj; |
| 1066 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1067 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1068 | break; |
| 1069 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1070 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1071 | request = (MainThreadRequest) msg.obj; |
| 1072 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1073 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1074 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1075 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1076 | break; |
| 1077 | |
| 1078 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1079 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1080 | break; |
| 1081 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1082 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1083 | request = (MainThreadRequest) msg.obj; |
| 1084 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1085 | request); |
| 1086 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1087 | break; |
| 1088 | |
| 1089 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1090 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1091 | break; |
| 1092 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1093 | case CMD_PERFORM_NETWORK_SCAN: |
| 1094 | request = (MainThreadRequest) msg.obj; |
| 1095 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1096 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1097 | break; |
| 1098 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1099 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1100 | request = (MainThreadRequest) msg.obj; |
| 1101 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1102 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1103 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1104 | request.argument; |
| 1105 | int callForwardingReason = args.first; |
| 1106 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1107 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1108 | } |
| 1109 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1110 | ar = (AsyncResult) msg.obj; |
| 1111 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1112 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1113 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1114 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1115 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1116 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1117 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1118 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1119 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1120 | // any service for voice call. |
| 1121 | if ((callForwardInfo.serviceClass |
| 1122 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1123 | callForwardingInfo = new CallForwardingInfo( |
| 1124 | callForwardInfo.status |
| 1125 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1126 | callForwardInfo.reason, |
| 1127 | callForwardInfo.number, |
| 1128 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1129 | break; |
| 1130 | } |
| 1131 | } |
| 1132 | // Didn't find a call forward info for voice call. |
| 1133 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1134 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1135 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1136 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1137 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1138 | } else { |
| 1139 | if (ar.result == null) { |
| 1140 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1141 | } |
| 1142 | if (ar.exception != null) { |
| 1143 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1144 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1145 | int errorCode = TelephonyManager |
| 1146 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1147 | if (ar.exception instanceof CommandException) { |
| 1148 | CommandException.Error error = |
| 1149 | ((CommandException) (ar.exception)).getCommandError(); |
| 1150 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1151 | errorCode = TelephonyManager |
| 1152 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1153 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1154 | errorCode = TelephonyManager |
| 1155 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1156 | } |
| 1157 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1158 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1159 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1160 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1161 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1162 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1163 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1164 | request = (MainThreadRequest) msg.obj; |
| 1165 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1166 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1167 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1168 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1169 | request.argument).first; |
| 1170 | request.phone.setCallForwardingOption( |
| 1171 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1172 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1173 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1174 | callForwardingInfoToSet.getReason(), |
| 1175 | callForwardingInfoToSet.getNumber(), |
| 1176 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1177 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1178 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1179 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1180 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1181 | ar = (AsyncResult) msg.obj; |
| 1182 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1183 | Consumer<Integer> callback = |
| 1184 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1185 | request.argument).second; |
| 1186 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1187 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1188 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1189 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1190 | if (ar.exception instanceof CommandException) { |
| 1191 | CommandException.Error error = |
| 1192 | ((CommandException) (ar.exception)).getCommandError(); |
| 1193 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1194 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1195 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1196 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1197 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1198 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1199 | } |
| 1200 | } |
| 1201 | callback.accept(errorCode); |
| 1202 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1203 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
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_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1209 | request = (MainThreadRequest) msg.obj; |
| 1210 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1211 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1212 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1213 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1214 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1215 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1216 | ar = (AsyncResult) msg.obj; |
| 1217 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1218 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1219 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1220 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1221 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1222 | // Service Class is a bit mask per 3gpp 27.007. |
| 1223 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1224 | if (callForwardResults.length > 1 |
| 1225 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1226 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1227 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1228 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1229 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1230 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1231 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1232 | } |
| 1233 | } else { |
| 1234 | if (ar.result == null) { |
| 1235 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1236 | } |
| 1237 | if (ar.exception != null) { |
| 1238 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1239 | } |
| 1240 | if (ar.exception instanceof CommandException) { |
| 1241 | CommandException.Error error = |
| 1242 | ((CommandException) (ar.exception)).getCommandError(); |
| 1243 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1244 | callForwardingStatus = |
| 1245 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1246 | } |
| 1247 | } |
| 1248 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1249 | callback.accept(callForwardingStatus); |
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_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1254 | request = (MainThreadRequest) msg.obj; |
| 1255 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1256 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1257 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1258 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1259 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1260 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1261 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1262 | ar = (AsyncResult) msg.obj; |
| 1263 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1264 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1265 | Consumer<Integer> callback = |
| 1266 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1267 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1268 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1269 | if (ar.exception instanceof CommandException) { |
| 1270 | CommandException.Error error = |
| 1271 | ((CommandException) (ar.exception)).getCommandError(); |
| 1272 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1273 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1274 | } else { |
| 1275 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1276 | } |
| 1277 | } else { |
| 1278 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1279 | } |
| 1280 | } else { |
| 1281 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1282 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1283 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1284 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1285 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1286 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1287 | ar = (AsyncResult) msg.obj; |
| 1288 | request = (MainThreadRequest) ar.userObj; |
| 1289 | CellNetworkScanResult cellScanResult; |
| 1290 | if (ar.exception == null && ar.result != null) { |
| 1291 | cellScanResult = new CellNetworkScanResult( |
| 1292 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1293 | (List<OperatorInfo>) ar.result); |
| 1294 | } else { |
| 1295 | if (ar.result == null) { |
| 1296 | loge("getCellNetworkScanResults: Empty response"); |
| 1297 | } |
| 1298 | if (ar.exception != null) { |
| 1299 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1300 | } |
| 1301 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1302 | if (ar.exception instanceof CommandException) { |
| 1303 | CommandException.Error error = |
| 1304 | ((CommandException) (ar.exception)).getCommandError(); |
| 1305 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1306 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1307 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1308 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1309 | } |
| 1310 | } |
| 1311 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1312 | } |
| 1313 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1314 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1315 | break; |
| 1316 | |
| 1317 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1318 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1319 | ManualNetworkSelectionArgument selArg = |
| 1320 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1321 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1322 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1323 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1324 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1325 | break; |
| 1326 | |
| 1327 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1328 | ar = (AsyncResult) msg.obj; |
| 1329 | request = (MainThreadRequest) ar.userObj; |
| 1330 | if (ar.exception == null) { |
| 1331 | request.result = true; |
| 1332 | } else { |
| 1333 | request.result = false; |
| 1334 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1335 | } |
| 1336 | notifyRequester(request); |
| 1337 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1338 | break; |
| 1339 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1340 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1341 | request = (MainThreadRequest) msg.obj; |
| 1342 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1343 | if (defaultPhone != null) { |
| 1344 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1345 | } else { |
| 1346 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1347 | Bundle bundle = new Bundle(); |
| 1348 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1349 | new ModemActivityInfo(0, 0, 0, |
| 1350 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1351 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1352 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1353 | break; |
| 1354 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1355 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1356 | ar = (AsyncResult) msg.obj; |
| 1357 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1358 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1359 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1360 | ModemActivityInfo ret = null; |
| 1361 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1362 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1363 | // Update the last modem activity info and the result of the request. |
| 1364 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1365 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1366 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1367 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1368 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1369 | .getTransmitTimeMillis(); |
| 1370 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1371 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1372 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1373 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1374 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1375 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1376 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1377 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1378 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1379 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1380 | info.getReceiveTimeMillis() |
| 1381 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1382 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1383 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1384 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1385 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1386 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1387 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1388 | } else { |
| 1389 | if (ar.result == null) { |
| 1390 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1391 | error = TelephonyManager.ModemActivityInfoException |
| 1392 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1393 | } else if (ar.exception instanceof CommandException) { |
| 1394 | loge("queryModemActivityInfo: CommandException: " + |
| 1395 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1396 | error = TelephonyManager.ModemActivityInfoException |
| 1397 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1398 | } else { |
| 1399 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1400 | error = TelephonyManager.ModemActivityInfoException |
| 1401 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1402 | } |
| 1403 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1404 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1405 | if (ret != null) { |
| 1406 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1407 | } else { |
| 1408 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1409 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1410 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1411 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1412 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1413 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1414 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1415 | case CMD_SET_ALLOWED_CARRIERS: |
| 1416 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1417 | CarrierRestrictionRules argument = |
| 1418 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1419 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1420 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1421 | break; |
| 1422 | |
| 1423 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1424 | ar = (AsyncResult) msg.obj; |
| 1425 | request = (MainThreadRequest) ar.userObj; |
| 1426 | if (ar.exception == null && ar.result != null) { |
| 1427 | request.result = ar.result; |
| 1428 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1429 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1430 | if (ar.exception instanceof CommandException) { |
| 1431 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1432 | CommandException.Error error = |
| 1433 | ((CommandException) (ar.exception)).getCommandError(); |
| 1434 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1435 | request.result = |
| 1436 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1437 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1438 | } else { |
| 1439 | loge("setAllowedCarriers: Unknown exception"); |
| 1440 | } |
| 1441 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1442 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1443 | break; |
| 1444 | |
| 1445 | case CMD_GET_ALLOWED_CARRIERS: |
| 1446 | request = (MainThreadRequest) msg.obj; |
| 1447 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1448 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1449 | break; |
| 1450 | |
| 1451 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1452 | ar = (AsyncResult) msg.obj; |
| 1453 | request = (MainThreadRequest) ar.userObj; |
| 1454 | if (ar.exception == null && ar.result != null) { |
| 1455 | request.result = ar.result; |
| 1456 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1457 | request.result = new IllegalStateException( |
| 1458 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1459 | if (ar.result == null) { |
| 1460 | loge("getAllowedCarriers: Empty response"); |
| 1461 | } else if (ar.exception instanceof CommandException) { |
| 1462 | loge("getAllowedCarriers: CommandException: " + |
| 1463 | ar.exception); |
| 1464 | } else { |
| 1465 | loge("getAllowedCarriers: Unknown exception"); |
| 1466 | } |
| 1467 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1468 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1469 | break; |
| 1470 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1471 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1472 | ar = (AsyncResult) msg.obj; |
| 1473 | request = (MainThreadRequest) ar.userObj; |
| 1474 | if (ar.exception == null && ar.result != null) { |
| 1475 | request.result = ar.result; |
| 1476 | } else { |
| 1477 | request.result = new IllegalArgumentException( |
| 1478 | "Failed to retrieve Forbidden Plmns"); |
| 1479 | if (ar.result == null) { |
| 1480 | loge("getForbiddenPlmns: Empty response"); |
| 1481 | } else { |
| 1482 | loge("getForbiddenPlmns: Unknown exception"); |
| 1483 | } |
| 1484 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1485 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1486 | break; |
| 1487 | |
| 1488 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1489 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1490 | uiccPort = getUiccPortFromRequest(request); |
| 1491 | if (uiccPort == null) { |
| 1492 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1493 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1494 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1495 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1496 | break; |
| 1497 | } |
| 1498 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1499 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1500 | if (uiccApp == null) { |
| 1501 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1502 | + appType); |
| 1503 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1504 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1505 | break; |
| 1506 | } else { |
| 1507 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1508 | + " specified type -- " + appType); |
| 1509 | } |
| 1510 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1511 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1512 | onCompleted); |
| 1513 | break; |
| 1514 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1515 | case CMD_SWITCH_SLOTS: |
| 1516 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1517 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1518 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1519 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1520 | break; |
| 1521 | |
| 1522 | case EVENT_SWITCH_SLOTS_DONE: |
| 1523 | ar = (AsyncResult) msg.obj; |
| 1524 | request = (MainThreadRequest) ar.userObj; |
| 1525 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1526 | notifyRequester(request); |
| 1527 | break; |
| 1528 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1529 | request = (MainThreadRequest) msg.obj; |
| 1530 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1531 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1532 | break; |
| 1533 | |
| 1534 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1535 | ar = (AsyncResult) msg.obj; |
| 1536 | request = (MainThreadRequest) ar.userObj; |
| 1537 | if (ar.exception != null) { |
| 1538 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1539 | } else { |
| 1540 | int mode = ((int[]) ar.result)[0]; |
| 1541 | if (mode == 0) { |
| 1542 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1543 | } else { |
| 1544 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1545 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1546 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1547 | notifyRequester(request); |
| 1548 | break; |
| 1549 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1550 | request = (MainThreadRequest) msg.obj; |
| 1551 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1552 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1553 | break; |
| 1554 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1555 | ar = (AsyncResult) msg.obj; |
| 1556 | request = (MainThreadRequest) ar.userObj; |
| 1557 | if (ar.exception != null) { |
| 1558 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1559 | } else { |
| 1560 | request.result = ((int[]) ar.result)[0]; |
| 1561 | } |
| 1562 | notifyRequester(request); |
| 1563 | break; |
| 1564 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1565 | request = (MainThreadRequest) msg.obj; |
| 1566 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1567 | int mode = (int) request.argument; |
| 1568 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1569 | break; |
| 1570 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1571 | ar = (AsyncResult) msg.obj; |
| 1572 | request = (MainThreadRequest) ar.userObj; |
| 1573 | request.result = ar.exception == null; |
| 1574 | notifyRequester(request); |
| 1575 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1576 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1577 | request = (MainThreadRequest) msg.obj; |
| 1578 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1579 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1580 | break; |
| 1581 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1582 | ar = (AsyncResult) msg.obj; |
| 1583 | request = (MainThreadRequest) ar.userObj; |
| 1584 | if (ar.exception != null) { |
| 1585 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1586 | } else { |
| 1587 | request.result = ((int[]) ar.result)[0]; |
| 1588 | } |
| 1589 | notifyRequester(request); |
| 1590 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1591 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1592 | request = (MainThreadRequest) msg.obj; |
| 1593 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1594 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1595 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1596 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1597 | break; |
| 1598 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1599 | ar = (AsyncResult) msg.obj; |
| 1600 | request = (MainThreadRequest) ar.userObj; |
| 1601 | request.result = ar.exception == null; |
| 1602 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1603 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1604 | case CMD_GET_ALL_CELL_INFO: |
| 1605 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1606 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1607 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1608 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1609 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1610 | ar = (AsyncResult) msg.obj; |
| 1611 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1612 | // If a timeout occurs, the response will be null |
| 1613 | request.result = (ar.exception == null && ar.result != null) |
| 1614 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1615 | synchronized (request) { |
| 1616 | request.notifyAll(); |
| 1617 | } |
| 1618 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1619 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1620 | request = (MainThreadRequest) msg.obj; |
| 1621 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1622 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1623 | break; |
| 1624 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1625 | ar = (AsyncResult) msg.obj; |
| 1626 | request = (MainThreadRequest) ar.userObj; |
| 1627 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1628 | try { |
| 1629 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1630 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1631 | cb.onError( |
| 1632 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1633 | ar.exception.getClass().getName(), |
| 1634 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1635 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1636 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1637 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1638 | } else { |
| 1639 | // use the result as returned |
| 1640 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1641 | } |
| 1642 | } catch (RemoteException re) { |
| 1643 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1644 | } |
| 1645 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1646 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1647 | request = (MainThreadRequest) msg.obj; |
| 1648 | WorkSource ws = (WorkSource) request.argument; |
| 1649 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1650 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1651 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1652 | } |
| 1653 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1654 | ar = (AsyncResult) msg.obj; |
| 1655 | request = (MainThreadRequest) ar.userObj; |
| 1656 | if (ar.exception == null) { |
| 1657 | request.result = ar.result; |
| 1658 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1659 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1660 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1661 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1662 | } |
| 1663 | |
| 1664 | synchronized (request) { |
| 1665 | request.notifyAll(); |
| 1666 | } |
| 1667 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1668 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1669 | case CMD_MODEM_REBOOT: |
| 1670 | request = (MainThreadRequest) msg.obj; |
| 1671 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1672 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1673 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1674 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1675 | handleNullReturnEvent(msg, "rebootModem"); |
| 1676 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1677 | case CMD_REQUEST_ENABLE_MODEM: |
| 1678 | request = (MainThreadRequest) msg.obj; |
| 1679 | boolean enable = (boolean) request.argument; |
| 1680 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1681 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1682 | PhoneConfigurationManager.getInstance() |
| 1683 | .enablePhone(request.phone, enable, onCompleted); |
| 1684 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1685 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1686 | ar = (AsyncResult) msg.obj; |
| 1687 | request = (MainThreadRequest) ar.userObj; |
| 1688 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1689 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1690 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1691 | if ((boolean) request.result) { |
| 1692 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1693 | updateModemStateMetrics(); |
| 1694 | } else { |
| 1695 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1696 | + ar.exception); |
| 1697 | } |
| 1698 | notifyRequester(request); |
| 1699 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1700 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1701 | case CMD_GET_MODEM_STATUS: |
| 1702 | request = (MainThreadRequest) msg.obj; |
| 1703 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1704 | PhoneConfigurationManager.getInstance() |
| 1705 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1706 | break; |
| 1707 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1708 | ar = (AsyncResult) msg.obj; |
| 1709 | request = (MainThreadRequest) ar.userObj; |
| 1710 | int id = request.phone.getPhoneId(); |
| 1711 | if (ar.exception == null && ar.result != null) { |
| 1712 | request.result = ar.result; |
| 1713 | //update the cache as modem status has changed |
| 1714 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1715 | (boolean) request.result); |
| 1716 | } else { |
| 1717 | // Return true if modem status cannot be retrieved. For most cases, |
| 1718 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1719 | // and disable modem are not supported. Modem is always on. |
| 1720 | // TODO: this should be fixed in R to support a third |
| 1721 | // status UNKNOWN b/131631629 |
| 1722 | request.result = true; |
| 1723 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1724 | + ar.exception); |
| 1725 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1726 | notifyRequester(request); |
| 1727 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1728 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1729 | request = (MainThreadRequest) msg.obj; |
| 1730 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1731 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1732 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1733 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1734 | break; |
| 1735 | } |
| 1736 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1737 | ar = (AsyncResult) msg.obj; |
| 1738 | request = (MainThreadRequest) ar.userObj; |
| 1739 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1740 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1741 | args.second.accept(ar.exception == null); |
| 1742 | notifyRequester(request); |
| 1743 | break; |
| 1744 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1745 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1746 | request = (MainThreadRequest) msg.obj; |
| 1747 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1748 | Phone phone = getPhoneFromRequest(request); |
| 1749 | if (phone != null) { |
| 1750 | phone.getSystemSelectionChannels(onCompleted); |
| 1751 | } else { |
| 1752 | loge("getSystemSelectionChannels: No phone object"); |
| 1753 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1754 | notifyRequester(request); |
| 1755 | } |
| 1756 | break; |
| 1757 | } |
| 1758 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1759 | ar = (AsyncResult) msg.obj; |
| 1760 | request = (MainThreadRequest) ar.userObj; |
| 1761 | if (ar.exception == null && ar.result != null) { |
| 1762 | request.result = ar.result; |
| 1763 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1764 | request.result = new IllegalStateException( |
| 1765 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1766 | if (ar.result == null) { |
| 1767 | loge("getSystemSelectionChannels: Empty response"); |
| 1768 | } else { |
| 1769 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1770 | } |
| 1771 | } |
| 1772 | notifyRequester(request); |
| 1773 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1774 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1775 | ar = (AsyncResult) msg.obj; |
| 1776 | request = (MainThreadRequest) ar.userObj; |
| 1777 | if (ar.exception == null && ar.result != null) { |
| 1778 | request.result = ar.result; |
| 1779 | } else { |
| 1780 | request.result = -1; |
| 1781 | loge("Failed to set Forbidden Plmns"); |
| 1782 | if (ar.result == null) { |
| 1783 | loge("setForbidenPlmns: Empty response"); |
| 1784 | } else if (ar.exception != null) { |
| 1785 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1786 | request.result = -1; |
| 1787 | } else { |
| 1788 | loge("setForbiddenPlmns: Unknown exception"); |
| 1789 | } |
| 1790 | } |
| 1791 | notifyRequester(request); |
| 1792 | break; |
| 1793 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1794 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1795 | uiccPort = getUiccPortFromRequest(request); |
| 1796 | if (uiccPort == null) { |
| 1797 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1798 | request.result = -1; |
| 1799 | notifyRequester(request); |
| 1800 | break; |
| 1801 | } |
| 1802 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1803 | (Pair<Integer, List<String>>) request.argument; |
| 1804 | appType = setFplmnsArgs.first; |
| 1805 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1806 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1807 | if (uiccApp == null) { |
| 1808 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1809 | request.result = -1; |
| 1810 | loge("Failed to get UICC App"); |
| 1811 | notifyRequester(request); |
| 1812 | } else { |
| 1813 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1814 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1815 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1816 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1817 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1818 | case CMD_ERASE_MODEM_CONFIG: |
| 1819 | request = (MainThreadRequest) msg.obj; |
| 1820 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1821 | defaultPhone.eraseModemConfig(onCompleted); |
| 1822 | break; |
| 1823 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1824 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1825 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1826 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1827 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1828 | request = (MainThreadRequest) msg.obj; |
| 1829 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1830 | notifyRequester(request); |
| 1831 | break; |
| 1832 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1833 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1834 | request = (MainThreadRequest) msg.obj; |
| 1835 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1836 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1837 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1838 | changed.first, changed.second, onCompleted); |
| 1839 | break; |
| 1840 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1841 | ar = (AsyncResult) msg.obj; |
| 1842 | request = (MainThreadRequest) ar.userObj; |
| 1843 | if (ar.exception == null) { |
| 1844 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1845 | // If the operation is successful, update the PIN storage |
| 1846 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1847 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | bb77752 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1848 | UiccController.getInstance().getPinStorage() |
| 1849 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1850 | } else { |
| 1851 | request.result = msg.arg1; |
| 1852 | } |
| 1853 | notifyRequester(request); |
| 1854 | break; |
| 1855 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1856 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1857 | request = (MainThreadRequest) msg.obj; |
| 1858 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1859 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1860 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1861 | enabled.first, enabled.second, onCompleted); |
| 1862 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1863 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1864 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1865 | ar = (AsyncResult) msg.obj; |
| 1866 | request = (MainThreadRequest) ar.userObj; |
| 1867 | if (ar.exception == null) { |
| 1868 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1869 | // If the operation is successful, update the PIN storage |
| 1870 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1871 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1872 | if (enabled.first) { |
Jon Spivack | bb77752 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1873 | UiccController.getInstance().getPinStorage() |
| 1874 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1875 | } else { |
| 1876 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1877 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1878 | } else { |
| 1879 | request.result = msg.arg1; |
| 1880 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1881 | |
| 1882 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1883 | notifyRequester(request); |
| 1884 | break; |
| 1885 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1886 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1887 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1888 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1889 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1890 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1891 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1892 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1893 | |
| 1894 | case CMD_SET_DATA_THROTTLING: { |
| 1895 | request = (MainThreadRequest) msg.obj; |
| 1896 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1897 | DataThrottlingRequest dataThrottlingRequest = |
| 1898 | (DataThrottlingRequest) request.argument; |
| 1899 | Phone phone = getPhoneFromRequest(request); |
| 1900 | if (phone != null) { |
| 1901 | phone.setDataThrottling(onCompleted, |
| 1902 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1903 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1904 | } else { |
| 1905 | loge("setDataThrottling: No phone object"); |
| 1906 | request.result = |
| 1907 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1908 | notifyRequester(request); |
| 1909 | } |
| 1910 | |
| 1911 | break; |
| 1912 | } |
| 1913 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1914 | ar = (AsyncResult) msg.obj; |
| 1915 | request = (MainThreadRequest) ar.userObj; |
| 1916 | |
| 1917 | if (ar.exception == null) { |
| 1918 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1919 | } else if (ar.exception instanceof CommandException) { |
| 1920 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1921 | CommandException.Error error = |
| 1922 | ((CommandException) (ar.exception)).getCommandError(); |
| 1923 | |
| 1924 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1925 | request.result = TelephonyManager |
| 1926 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1927 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1928 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 1929 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1930 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1931 | } else { |
| 1932 | request.result = |
| 1933 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1934 | } |
| 1935 | } else { |
| 1936 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1937 | } |
| 1938 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1939 | notifyRequester(request); |
| 1940 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1941 | |
| 1942 | case CMD_SET_SIM_POWER: { |
| 1943 | request = (MainThreadRequest) msg.obj; |
| 1944 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1945 | request = (MainThreadRequest) msg.obj; |
| 1946 | int stateToSet = |
| 1947 | ((Pair<Integer, IIntegerConsumer>) |
| 1948 | request.argument).first; |
| 1949 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1950 | break; |
| 1951 | } |
| 1952 | case EVENT_SET_SIM_POWER_DONE: { |
| 1953 | ar = (AsyncResult) msg.obj; |
| 1954 | request = (MainThreadRequest) ar.userObj; |
| 1955 | IIntegerConsumer callback = |
| 1956 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1957 | if (ar.exception != null) { |
| 1958 | loge("setSimPower exception: " + ar.exception); |
| 1959 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1960 | .RESULT_ERROR_UNKNOWN; |
| 1961 | if (ar.exception instanceof CommandException) { |
| 1962 | CommandException.Error error = |
| 1963 | ((CommandException) (ar.exception)).getCommandError(); |
| 1964 | if (error == CommandException.Error.SIM_ERR) { |
| 1965 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1966 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1967 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1968 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1969 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1970 | } else { |
| 1971 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1972 | } |
| 1973 | } |
| 1974 | try { |
| 1975 | callback.accept(errorCode); |
| 1976 | } catch (RemoteException e) { |
| 1977 | // Ignore if the remote process is no longer available to call back. |
| 1978 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1979 | } |
| 1980 | } else { |
| 1981 | try { |
| 1982 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1983 | } catch (RemoteException e) { |
| 1984 | // Ignore if the remote process is no longer available to call back. |
| 1985 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1986 | } |
| 1987 | } |
| 1988 | break; |
| 1989 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1990 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1991 | request = (MainThreadRequest) msg.obj; |
| 1992 | |
| 1993 | final Phone phone = getPhoneFromRequest(request); |
| 1994 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1995 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1996 | notifyRequester(request); |
| 1997 | break; |
| 1998 | } |
| 1999 | |
| 2000 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2001 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2002 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2003 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2004 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2005 | request.subId, pair.first /*callingUid*/, |
| 2006 | pair.second /*request*/, onCompleted); |
| 2007 | break; |
| 2008 | } |
| 2009 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2010 | ar = (AsyncResult) msg.obj; |
| 2011 | request = (MainThreadRequest) ar.userObj; |
| 2012 | // request.result will be the exception of ar if present, true otherwise. |
| 2013 | // Be cautious not to leave result null which will wait() forever |
| 2014 | request.result = ar.exception != null ? ar.exception : true; |
| 2015 | notifyRequester(request); |
| 2016 | break; |
| 2017 | } |
| 2018 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2019 | request = (MainThreadRequest) msg.obj; |
| 2020 | |
| 2021 | Phone phone = getPhoneFromRequest(request); |
| 2022 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2023 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2024 | notifyRequester(request); |
| 2025 | break; |
| 2026 | } |
| 2027 | |
| 2028 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2029 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2030 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2031 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2032 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2033 | request.subId, pair.first /*callingUid*/, |
| 2034 | pair.second /*request*/, onCompleted); |
| 2035 | break; |
| 2036 | } |
| 2037 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2038 | ar = (AsyncResult) msg.obj; |
| 2039 | request = (MainThreadRequest) ar.userObj; |
| 2040 | request.result = ar.exception != null ? ar.exception : true; |
| 2041 | notifyRequester(request); |
| 2042 | break; |
| 2043 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2044 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2045 | case CMD_GET_SLICING_CONFIG: { |
| 2046 | request = (MainThreadRequest) msg.obj; |
| 2047 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2048 | request.phone.getSlicingConfig(onCompleted); |
| 2049 | break; |
| 2050 | } |
| 2051 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2052 | ar = (AsyncResult) msg.obj; |
| 2053 | request = (MainThreadRequest) ar.userObj; |
| 2054 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2055 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2056 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2057 | Bundle bundle = new Bundle(); |
| 2058 | int resultCode = 0; |
| 2059 | if (ar.exception != null) { |
| 2060 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2061 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2062 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2063 | } else if (ar.result == null) { |
| 2064 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2065 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2066 | } else { |
| 2067 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2068 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2069 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2070 | } |
| 2071 | |
| 2072 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2073 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2074 | } |
| 2075 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2076 | result.send(resultCode, bundle); |
| 2077 | notifyRequester(request); |
| 2078 | break; |
| 2079 | } |
| 2080 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2081 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2082 | request = (MainThreadRequest) msg.obj; |
| 2083 | request.result = |
| 2084 | UiccController.getInstance().getPinStorage().prepareUnattendedReboot(); |
| 2085 | notifyRequester(request); |
| 2086 | break; |
| 2087 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2088 | default: |
| 2089 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2090 | break; |
| 2091 | } |
| 2092 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2093 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2094 | private void notifyRequester(MainThreadRequest request) { |
| 2095 | synchronized (request) { |
| 2096 | request.notifyAll(); |
| 2097 | } |
| 2098 | } |
| 2099 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2100 | private void handleNullReturnEvent(Message msg, String command) { |
| 2101 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2102 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2103 | if (ar.exception == null) { |
| 2104 | request.result = true; |
| 2105 | } else { |
| 2106 | request.result = false; |
| 2107 | if (ar.exception instanceof CommandException) { |
| 2108 | loge(command + ": CommandException: " + ar.exception); |
| 2109 | } else { |
| 2110 | loge(command + ": Unknown exception"); |
| 2111 | } |
| 2112 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2113 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2114 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2115 | } |
| 2116 | |
| 2117 | /** |
| 2118 | * Posts the specified command to be executed on the main thread, |
| 2119 | * waits for the request to complete, and returns the result. |
| 2120 | * @see #sendRequestAsync |
| 2121 | */ |
| 2122 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2123 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2124 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2125 | } |
| 2126 | |
| 2127 | /** |
| 2128 | * Posts the specified command to be executed on the main thread, |
| 2129 | * waits for the request to complete, and returns the result. |
| 2130 | * @see #sendRequestAsync |
| 2131 | */ |
| 2132 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2133 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2134 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | /** |
| 2138 | * Posts the specified command to be executed on the main thread, |
| 2139 | * waits for the request to complete, and returns the result. |
| 2140 | * @see #sendRequestAsync |
| 2141 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2142 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2143 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2144 | } |
| 2145 | |
| 2146 | /** |
| 2147 | * Posts the specified command to be executed on the main thread, |
| 2148 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2149 | * if not timeout or null otherwise. |
| 2150 | * @see #sendRequestAsync |
| 2151 | */ |
| 2152 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2153 | long timeoutInMs) { |
| 2154 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2155 | } |
| 2156 | |
| 2157 | /** |
| 2158 | * Posts the specified command to be executed on the main thread, |
| 2159 | * waits for the request to complete, and returns the result. |
| 2160 | * @see #sendRequestAsync |
| 2161 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2162 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2163 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2164 | } |
| 2165 | |
| 2166 | /** |
| 2167 | * Posts the specified command to be executed on the main thread, |
| 2168 | * waits for the request to complete, and returns the result. |
| 2169 | * @see #sendRequestAsync |
| 2170 | */ |
| 2171 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2172 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2173 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2174 | } |
| 2175 | |
| 2176 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2177 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2178 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2179 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2180 | * @see #sendRequestAsync |
| 2181 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2182 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2183 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2184 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2185 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2186 | } |
| 2187 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2188 | MainThreadRequest request = null; |
| 2189 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2190 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2191 | } else if (phone != null) { |
| 2192 | request = new MainThreadRequest(argument, phone, workSource); |
| 2193 | } else { |
| 2194 | request = new MainThreadRequest(argument, subId, workSource); |
| 2195 | } |
| 2196 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2197 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2198 | msg.sendToTarget(); |
| 2199 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2200 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2201 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2202 | if (timeoutInMs >= 0) { |
| 2203 | // Wait for at least timeoutInMs before returning null request result |
| 2204 | long now = SystemClock.elapsedRealtime(); |
| 2205 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2206 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2207 | try { |
| 2208 | request.wait(deadline - now); |
| 2209 | } catch (InterruptedException e) { |
| 2210 | // Do nothing, go back and check if request is completed or timeout |
| 2211 | } finally { |
| 2212 | now = SystemClock.elapsedRealtime(); |
| 2213 | } |
| 2214 | } |
| 2215 | } else { |
| 2216 | // Wait for the request to complete |
| 2217 | while (request.result == null) { |
| 2218 | try { |
| 2219 | request.wait(); |
| 2220 | } catch (InterruptedException e) { |
| 2221 | // Do nothing, go back and wait until the request is complete |
| 2222 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2223 | } |
| 2224 | } |
| 2225 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2226 | if (request.result == null) { |
| 2227 | Log.wtf(LOG_TAG, |
| 2228 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2229 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2230 | return request.result; |
| 2231 | } |
| 2232 | |
| 2233 | /** |
| 2234 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2235 | * Posts the specified command to be executed on the main thread, and |
| 2236 | * returns immediately. |
| 2237 | * @see #sendRequest |
| 2238 | */ |
| 2239 | private void sendRequestAsync(int command) { |
| 2240 | mMainThreadHandler.sendEmptyMessage(command); |
| 2241 | } |
| 2242 | |
| 2243 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2244 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2245 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2246 | */ |
| 2247 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2248 | sendRequestAsync(command, argument, null, null); |
| 2249 | } |
| 2250 | |
| 2251 | /** |
| 2252 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2253 | * @see {@link #sendRequest(int,Object)} |
| 2254 | */ |
| 2255 | private void sendRequestAsync( |
| 2256 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2257 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2258 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2259 | msg.sendToTarget(); |
| 2260 | } |
| 2261 | |
| 2262 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2263 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2264 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2265 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2266 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2267 | synchronized (PhoneInterfaceManager.class) { |
| 2268 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2269 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2270 | } else { |
| 2271 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2272 | } |
| 2273 | return sInstance; |
| 2274 | } |
| 2275 | } |
| 2276 | |
| 2277 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2278 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2279 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2280 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2281 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2282 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2283 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2284 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2285 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2286 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2287 | mTelephonySharedPreferences = |
| 2288 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2289 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2290 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2291 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2292 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2293 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2294 | publish(); |
| 2295 | } |
| 2296 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2297 | private Phone getDefaultPhone() { |
| 2298 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2299 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2300 | } |
| 2301 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2302 | private void publish() { |
| 2303 | if (DBG) log("publish: " + this); |
| 2304 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2305 | TelephonyFrameworkInitializer |
| 2306 | .getTelephonyServiceManager() |
| 2307 | .getTelephonyServiceRegisterer() |
| 2308 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2309 | } |
| 2310 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2311 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2312 | if (request.phone != null) { |
| 2313 | return request.phone; |
| 2314 | } else { |
| 2315 | return getPhoneFromSubId(request.subId); |
| 2316 | } |
| 2317 | } |
| 2318 | |
| 2319 | private Phone getPhoneFromSubId(int subId) { |
| 2320 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2321 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2322 | } |
| 2323 | |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2324 | private UiccPort getUiccPortFromRequest(MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2325 | Phone phone = getPhoneFromRequest(request); |
| 2326 | return phone == null ? null : |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2327 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2328 | } |
| 2329 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2330 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2331 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2332 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2333 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2334 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2335 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2336 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2337 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2338 | } |
| 2339 | |
| 2340 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2341 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2342 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2343 | } |
| 2344 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2345 | private boolean isImsAvailableOnDevice() { |
| 2346 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2347 | if (pm == null) { |
| 2348 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2349 | // so do not throw error and allow. |
| 2350 | return true; |
| 2351 | } |
| 2352 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2353 | } |
| 2354 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2355 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2356 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2357 | } |
| 2358 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2359 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2360 | if (DBG) log("dial: " + number); |
| 2361 | // No permission check needed here: This is just a wrapper around the |
| 2362 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2363 | // the UI before it does anything. |
| 2364 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2365 | final long identity = Binder.clearCallingIdentity(); |
| 2366 | try { |
| 2367 | String url = createTelUrl(number); |
| 2368 | if (url == null) { |
| 2369 | return; |
| 2370 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2371 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2372 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2373 | PhoneConstants.State state = mCM.getState(subId); |
| 2374 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2375 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2376 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2377 | mApp.startActivity(intent); |
| 2378 | } |
| 2379 | } finally { |
| 2380 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2381 | } |
| 2382 | } |
| 2383 | |
| 2384 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2385 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2386 | } |
| 2387 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2388 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2389 | if (DBG) log("call: " + number); |
| 2390 | |
| 2391 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2392 | // need to do a permission check since we're calling startActivity() |
| 2393 | // from the context of the phone app. |
| 2394 | enforceCallPermission(); |
| 2395 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2396 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2397 | != AppOpsManager.MODE_ALLOWED) { |
| 2398 | return; |
| 2399 | } |
| 2400 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2401 | final long identity = Binder.clearCallingIdentity(); |
| 2402 | try { |
| 2403 | String url = createTelUrl(number); |
| 2404 | if (url == null) { |
| 2405 | return; |
| 2406 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2407 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2408 | boolean isValid = false; |
| 2409 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2410 | if (slist != null) { |
| 2411 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2412 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2413 | isValid = true; |
| 2414 | break; |
| 2415 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2416 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2417 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2418 | if (!isValid) { |
| 2419 | return; |
| 2420 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2421 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2422 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2423 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2424 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2425 | mApp.startActivity(intent); |
| 2426 | } finally { |
| 2427 | Binder.restoreCallingIdentity(identity); |
| 2428 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2429 | } |
| 2430 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2431 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2432 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2433 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2434 | } |
| 2435 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2436 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2437 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2438 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2439 | } |
| 2440 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2441 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2442 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2443 | |
| 2444 | final long identity = Binder.clearCallingIdentity(); |
| 2445 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2446 | Phone phone = getPhone(subId); |
| 2447 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2448 | checkSimPin.start(); |
| 2449 | return checkSimPin.unlockSim(null, pin); |
| 2450 | } finally { |
| 2451 | Binder.restoreCallingIdentity(identity); |
| 2452 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2453 | } |
| 2454 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2455 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2456 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2457 | |
| 2458 | final long identity = Binder.clearCallingIdentity(); |
| 2459 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2460 | Phone phone = getPhone(subId); |
| 2461 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2462 | checkSimPuk.start(); |
| 2463 | return checkSimPuk.unlockSim(puk, pin); |
| 2464 | } finally { |
| 2465 | Binder.restoreCallingIdentity(identity); |
| 2466 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2467 | } |
| 2468 | |
| 2469 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2470 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2471 | * a synchronous one. |
| 2472 | */ |
| 2473 | private static class UnlockSim extends Thread { |
| 2474 | |
| 2475 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2476 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2477 | |
| 2478 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2479 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2480 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2481 | |
| 2482 | // For replies from SimCard interface |
| 2483 | private Handler mHandler; |
| 2484 | |
| 2485 | // For async handler to identify request type |
| 2486 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2487 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2488 | UnlockSim(int phoneId, IccCard simCard) { |
| 2489 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2490 | mSimCard = simCard; |
| 2491 | } |
| 2492 | |
| 2493 | @Override |
| 2494 | public void run() { |
| 2495 | Looper.prepare(); |
| 2496 | synchronized (UnlockSim.this) { |
| 2497 | mHandler = new Handler() { |
| 2498 | @Override |
| 2499 | public void handleMessage(Message msg) { |
| 2500 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2501 | switch (msg.what) { |
| 2502 | case SUPPLY_PIN_COMPLETE: |
| 2503 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2504 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2505 | mRetryCount = msg.arg1; |
| 2506 | if (ar.exception != null) { |
| 2507 | if (ar.exception instanceof CommandException && |
| 2508 | ((CommandException)(ar.exception)).getCommandError() |
| 2509 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2510 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2511 | } //When UiccCardApp dispose,handle message and return exception |
| 2512 | else if (ar.exception instanceof CommandException && |
| 2513 | ((CommandException) (ar.exception)).getCommandError() |
| 2514 | == CommandException.Error.ABORTED) { |
| 2515 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2516 | } else { |
| 2517 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2518 | } |
| 2519 | } else { |
| 2520 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2521 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2522 | mDone = true; |
| 2523 | UnlockSim.this.notifyAll(); |
| 2524 | } |
| 2525 | break; |
| 2526 | } |
| 2527 | } |
| 2528 | }; |
| 2529 | UnlockSim.this.notifyAll(); |
| 2530 | } |
| 2531 | Looper.loop(); |
| 2532 | } |
| 2533 | |
| 2534 | /* |
| 2535 | * Use PIN or PUK to unlock SIM card |
| 2536 | * |
| 2537 | * If PUK is null, unlock SIM card with PIN |
| 2538 | * |
| 2539 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2540 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2541 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2542 | |
| 2543 | while (mHandler == null) { |
| 2544 | try { |
| 2545 | wait(); |
| 2546 | } catch (InterruptedException e) { |
| 2547 | Thread.currentThread().interrupt(); |
| 2548 | } |
| 2549 | } |
| 2550 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2551 | |
| 2552 | if (puk == null) { |
| 2553 | mSimCard.supplyPin(pin, callback); |
| 2554 | } else { |
| 2555 | mSimCard.supplyPuk(puk, pin, callback); |
| 2556 | } |
| 2557 | |
| 2558 | while (!mDone) { |
| 2559 | try { |
| 2560 | Log.d(LOG_TAG, "wait for done"); |
| 2561 | wait(); |
| 2562 | } catch (InterruptedException e) { |
| 2563 | // Restore the interrupted status |
| 2564 | Thread.currentThread().interrupt(); |
| 2565 | } |
| 2566 | } |
| 2567 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2568 | int[] resultArray = new int[2]; |
| 2569 | resultArray[0] = mResult; |
| 2570 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2571 | |
| 2572 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | bb77752 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2573 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2574 | } |
| 2575 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2576 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2577 | } |
| 2578 | } |
| 2579 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2580 | /** |
| 2581 | * This method has been removed due to privacy and stability concerns. |
| 2582 | */ |
| 2583 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2584 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2585 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2586 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2587 | } |
| 2588 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2589 | @Override |
| 2590 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2591 | mApp.getSystemService(AppOpsManager.class) |
| 2592 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2593 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2594 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2595 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2596 | // Callers targeting S have no business invoking this method. |
| 2597 | return; |
| 2598 | } |
| 2599 | |
| 2600 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2601 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2602 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2603 | .setCallingPackage(callingPackage) |
| 2604 | .setCallingFeatureId(null) |
| 2605 | .setCallingPid(Binder.getCallingPid()) |
| 2606 | .setCallingUid(Binder.getCallingUid()) |
| 2607 | .setMethod("updateServiceLocation") |
| 2608 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2609 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2610 | .build()); |
| 2611 | // Apps that lack location permission have no business calling this method; |
| 2612 | // however, because no permission was declared in the public API, denials must |
| 2613 | // all be "soft". |
| 2614 | switch (locationResult) { |
| 2615 | case DENIED_HARD: /* fall through */ |
| 2616 | case DENIED_SOFT: |
| 2617 | return; |
| 2618 | } |
| 2619 | |
| 2620 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2621 | final long identity = Binder.clearCallingIdentity(); |
| 2622 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2623 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2624 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2625 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2626 | } |
| 2627 | } finally { |
| 2628 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2629 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2630 | } |
| 2631 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2632 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2633 | @Override |
| 2634 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2635 | return isRadioOnWithFeature(callingPackage, null); |
| 2636 | } |
| 2637 | |
| 2638 | |
| 2639 | @Override |
| 2640 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2641 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2642 | callingFeatureId); |
| 2643 | } |
| 2644 | |
| 2645 | @Deprecated |
| 2646 | @Override |
| 2647 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2648 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2649 | } |
| 2650 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2651 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2652 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2653 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2654 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2655 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2656 | return false; |
| 2657 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2658 | |
| 2659 | final long identity = Binder.clearCallingIdentity(); |
| 2660 | try { |
| 2661 | return isRadioOnForSubscriber(subId); |
| 2662 | } finally { |
| 2663 | Binder.restoreCallingIdentity(identity); |
| 2664 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2665 | } |
| 2666 | |
| 2667 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2668 | final long identity = Binder.clearCallingIdentity(); |
| 2669 | try { |
| 2670 | final Phone phone = getPhone(subId); |
| 2671 | if (phone != null) { |
| 2672 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2673 | } else { |
| 2674 | return false; |
| 2675 | } |
| 2676 | } finally { |
| 2677 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2678 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2679 | } |
| 2680 | |
| 2681 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2682 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2683 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2684 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2685 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2686 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2687 | |
| 2688 | final long identity = Binder.clearCallingIdentity(); |
| 2689 | try { |
| 2690 | final Phone phone = getPhone(subId); |
| 2691 | if (phone != null) { |
| 2692 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2693 | } |
| 2694 | } finally { |
| 2695 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2696 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2697 | } |
| 2698 | |
| 2699 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2700 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2701 | } |
| 2702 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2703 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2704 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2705 | |
| 2706 | final long identity = Binder.clearCallingIdentity(); |
| 2707 | try { |
| 2708 | final Phone phone = getPhone(subId); |
| 2709 | if (phone == null) { |
| 2710 | return false; |
| 2711 | } |
| 2712 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2713 | toggleRadioOnOffForSubscriber(subId); |
| 2714 | } |
| 2715 | return true; |
| 2716 | } finally { |
| 2717 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2718 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2719 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2720 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2721 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2722 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2723 | /* |
| 2724 | * If any of the Radios are available, it will need to be |
| 2725 | * shutdown. So return true if any Radio is available. |
| 2726 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2727 | final long identity = Binder.clearCallingIdentity(); |
| 2728 | try { |
| 2729 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2730 | Phone phone = PhoneFactory.getPhone(i); |
| 2731 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2732 | } |
| 2733 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2734 | return false; |
| 2735 | } finally { |
| 2736 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2737 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2738 | } |
| 2739 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2740 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2741 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2742 | enforceModifyPermission(); |
| 2743 | |
| 2744 | final long identity = Binder.clearCallingIdentity(); |
| 2745 | try { |
| 2746 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2747 | logv("Shutting down Phone " + i); |
| 2748 | shutdownRadioUsingPhoneId(i); |
| 2749 | } |
| 2750 | } finally { |
| 2751 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2752 | } |
| 2753 | } |
| 2754 | |
| 2755 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2756 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2757 | if (phone != null && phone.isRadioAvailable()) { |
| 2758 | phone.shutdownRadio(); |
| 2759 | } |
| 2760 | } |
| 2761 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2762 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2763 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2764 | |
| 2765 | final long identity = Binder.clearCallingIdentity(); |
| 2766 | try { |
| 2767 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2768 | if (defaultPhone != null) { |
| 2769 | defaultPhone.setRadioPower(turnOn); |
| 2770 | return true; |
| 2771 | } else { |
| 2772 | loge("There's no default phone."); |
| 2773 | return false; |
| 2774 | } |
| 2775 | } finally { |
| 2776 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2777 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2778 | } |
| 2779 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2780 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2781 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2782 | |
| 2783 | final long identity = Binder.clearCallingIdentity(); |
| 2784 | try { |
| 2785 | final Phone phone = getPhone(subId); |
| 2786 | if (phone != null) { |
| 2787 | phone.setRadioPower(turnOn); |
| 2788 | return true; |
| 2789 | } else { |
| 2790 | return false; |
| 2791 | } |
| 2792 | } finally { |
| 2793 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2794 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2795 | } |
| 2796 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2797 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2798 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2799 | public boolean enableDataConnectivity() { |
| 2800 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2801 | |
| 2802 | final long identity = Binder.clearCallingIdentity(); |
| 2803 | try { |
| 2804 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2805 | final Phone phone = getPhone(subId); |
| 2806 | if (phone != null) { |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 2807 | if (phone.isUsingNewDataStack()) { |
| 2808 | phone.getDataSettingsManager().setDataEnabled( |
| 2809 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
| 2810 | } else { |
| 2811 | phone.getDataEnabledSettings().setDataEnabled( |
| 2812 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
| 2813 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2814 | return true; |
| 2815 | } else { |
| 2816 | return false; |
| 2817 | } |
| 2818 | } finally { |
| 2819 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2820 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2821 | } |
| 2822 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2823 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2824 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2825 | public boolean disableDataConnectivity() { |
| 2826 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2827 | |
| 2828 | final long identity = Binder.clearCallingIdentity(); |
| 2829 | try { |
| 2830 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2831 | final Phone phone = getPhone(subId); |
| 2832 | if (phone != null) { |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 2833 | if (phone.isUsingNewDataStack()) { |
| 2834 | phone.getDataSettingsManager().setDataEnabled( |
| 2835 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
| 2836 | } else { |
| 2837 | phone.getDataEnabledSettings().setDataEnabled( |
| 2838 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
| 2839 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2840 | return true; |
| 2841 | } else { |
| 2842 | return false; |
| 2843 | } |
| 2844 | } finally { |
| 2845 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2846 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2847 | } |
| 2848 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2849 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2850 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2851 | final long identity = Binder.clearCallingIdentity(); |
| 2852 | try { |
| 2853 | final Phone phone = getPhone(subId); |
| 2854 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2855 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2856 | } else { |
| 2857 | return false; |
| 2858 | } |
| 2859 | } finally { |
| 2860 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2861 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2862 | } |
| 2863 | |
| 2864 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2865 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2866 | } |
| 2867 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2868 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2869 | enforceCallPermission(); |
| 2870 | |
| 2871 | final long identity = Binder.clearCallingIdentity(); |
| 2872 | try { |
| 2873 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2874 | return; |
| 2875 | } |
| 2876 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2877 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2878 | } finally { |
| 2879 | Binder.restoreCallingIdentity(identity); |
| 2880 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2881 | }; |
| 2882 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2883 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2884 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2885 | |
| 2886 | final long identity = Binder.clearCallingIdentity(); |
| 2887 | try { |
| 2888 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2889 | return false; |
| 2890 | } |
| 2891 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2892 | } finally { |
| 2893 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2894 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2895 | } |
| 2896 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2897 | /** |
| 2898 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 2899 | * tag on getCallState Binder call. |
| 2900 | */ |
| 2901 | @Deprecated |
| 2902 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2903 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2904 | if (CompatChanges.isChangeEnabled( |
| 2905 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2906 | Binder.getCallingUid())) { |
| 2907 | // Do not allow this API to be called on API version 31+, it should only be |
| 2908 | // called on old apps using this Binder call directly. |
| 2909 | throw new SecurityException("This method can only be used for applications " |
| 2910 | + "targeting API version 30 or less."); |
| 2911 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2912 | final long identity = Binder.clearCallingIdentity(); |
| 2913 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2914 | Phone phone = getPhone(getDefaultSubscription()); |
| 2915 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2916 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2917 | } finally { |
| 2918 | Binder.restoreCallingIdentity(identity); |
| 2919 | } |
| 2920 | } |
| 2921 | |
| 2922 | @Override |
| 2923 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 2924 | if (CompatChanges.isChangeEnabled( |
| 2925 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2926 | Binder.getCallingUid())) { |
| 2927 | // Check READ_PHONE_STATE for API version 31+ |
| 2928 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2929 | featureId, "getCallStateForSubscription")) { |
| 2930 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 2931 | + "targeting API level 31+."); |
| 2932 | } |
| 2933 | } |
| 2934 | final long identity = Binder.clearCallingIdentity(); |
| 2935 | try { |
| 2936 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2937 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2938 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2939 | } finally { |
| 2940 | Binder.restoreCallingIdentity(identity); |
| 2941 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2942 | } |
| 2943 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2944 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2945 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2946 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2947 | } |
| 2948 | |
| 2949 | @Override |
| 2950 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2951 | final long identity = Binder.clearCallingIdentity(); |
| 2952 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2953 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2954 | if (phone != null) { |
Jack Yu | 4accbd9 | 2021-11-29 11:36:17 -0800 | [diff] [blame] | 2955 | if (phone.isUsingNewDataStack()) { |
| 2956 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
| 2957 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2958 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2959 | } else { |
| 2960 | return PhoneConstantConversions.convertDataState( |
| 2961 | PhoneConstants.DataState.DISCONNECTED); |
| 2962 | } |
| 2963 | } finally { |
| 2964 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2965 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2966 | } |
| 2967 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2968 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2969 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2970 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2971 | } |
| 2972 | |
| 2973 | @Override |
| 2974 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2975 | final long identity = Binder.clearCallingIdentity(); |
| 2976 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2977 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2978 | if (phone != null) { |
| 2979 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2980 | } else { |
| 2981 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2982 | } |
| 2983 | } finally { |
| 2984 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2985 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2986 | } |
| 2987 | |
| 2988 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2989 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2990 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2991 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2992 | |
| 2993 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2994 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2995 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2996 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2997 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2998 | .setCallingPid(Binder.getCallingPid()) |
| 2999 | .setCallingUid(Binder.getCallingUid()) |
| 3000 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3001 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3002 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3003 | .build()); |
| 3004 | switch (locationResult) { |
| 3005 | case DENIED_HARD: |
| 3006 | throw new SecurityException("Not allowed to access cell location"); |
| 3007 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3008 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3009 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3010 | } |
| 3011 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3012 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3013 | final long identity = Binder.clearCallingIdentity(); |
| 3014 | try { |
| 3015 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3016 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3017 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3018 | } finally { |
| 3019 | Binder.restoreCallingIdentity(identity); |
| 3020 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3021 | } |
| 3022 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3023 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3024 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3025 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3026 | // registered cell info, so return a NULL country instead. |
| 3027 | final long identity = Binder.clearCallingIdentity(); |
| 3028 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3029 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3030 | // Get default phone in this case. |
| 3031 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3032 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3033 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3034 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3035 | if (phone == null) return ""; |
| 3036 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3037 | if (sst == null) return ""; |
| 3038 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3039 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3040 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3041 | } finally { |
| 3042 | Binder.restoreCallingIdentity(identity); |
| 3043 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3044 | } |
| 3045 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3046 | /** |
| 3047 | * This method was removed due to potential issues caused by performing partial |
| 3048 | * updates of service state, and lack of a credible use case. |
| 3049 | * |
| 3050 | * This has the ability to break the telephony implementation by disabling notification of |
| 3051 | * changes in device connectivity. DO NOT USE THIS! |
| 3052 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3053 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3054 | public void enableLocationUpdates() { |
| 3055 | mApp.enforceCallingOrSelfPermission( |
| 3056 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3057 | } |
| 3058 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3059 | /** |
| 3060 | * This method was removed due to potential issues caused by performing partial |
| 3061 | * updates of service state, and lack of a credible use case. |
| 3062 | * |
| 3063 | * This has the ability to break the telephony implementation by disabling notification of |
| 3064 | * changes in device connectivity. DO NOT USE THIS! |
| 3065 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3066 | @Override |
| 3067 | public void disableLocationUpdates() { |
| 3068 | mApp.enforceCallingOrSelfPermission( |
| 3069 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3070 | } |
| 3071 | |
| 3072 | @Override |
| 3073 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3074 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3075 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3076 | try { |
| 3077 | mApp.getSystemService(AppOpsManager.class) |
| 3078 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3079 | } catch (SecurityException e) { |
| 3080 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3081 | throw e; |
| 3082 | } |
| 3083 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3084 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3085 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3086 | throw new SecurityException( |
| 3087 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3088 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3089 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3090 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3091 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3092 | return null; |
| 3093 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3094 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3095 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3096 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3097 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3098 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3099 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3100 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3101 | for (CellInfo ci : info) { |
| 3102 | if (ci instanceof CellInfoGsm) { |
| 3103 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3104 | } else if (ci instanceof CellInfoWcdma) { |
| 3105 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3106 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3107 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3108 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3109 | } |
| 3110 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3111 | private List<CellInfo> getCachedCellInfo() { |
| 3112 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3113 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3114 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3115 | if (info != null) cellInfos.addAll(info); |
| 3116 | } |
| 3117 | return cellInfos; |
| 3118 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3119 | |
| 3120 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3121 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3122 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3123 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3124 | |
| 3125 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3126 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3127 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3128 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3129 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3130 | .setCallingPid(Binder.getCallingPid()) |
| 3131 | .setCallingUid(Binder.getCallingUid()) |
| 3132 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3133 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3134 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3135 | .build()); |
| 3136 | switch (locationResult) { |
| 3137 | case DENIED_HARD: |
| 3138 | throw new SecurityException("Not allowed to access cell info"); |
| 3139 | case DENIED_SOFT: |
| 3140 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3141 | } |
| 3142 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3143 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3144 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3145 | return getCachedCellInfo(); |
| 3146 | } |
| 3147 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3148 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3149 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3150 | final long identity = Binder.clearCallingIdentity(); |
| 3151 | try { |
| 3152 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3153 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3154 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3155 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3156 | if (info != null) cellInfos.addAll(info); |
| 3157 | } |
| 3158 | return cellInfos; |
| 3159 | } finally { |
| 3160 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3161 | } |
| 3162 | } |
| 3163 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3164 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3165 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3166 | String callingFeatureId) { |
| 3167 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3168 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3169 | } |
| 3170 | |
| 3171 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3172 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3173 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3174 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3175 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3176 | } |
| 3177 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3178 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3179 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3180 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3181 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3182 | |
| 3183 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3184 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3185 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3186 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3187 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3188 | .setCallingPid(Binder.getCallingPid()) |
| 3189 | .setCallingUid(Binder.getCallingUid()) |
| 3190 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3191 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3192 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3193 | .build()); |
| 3194 | switch (locationResult) { |
| 3195 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3196 | if (TelephonyPermissions |
| 3197 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3198 | // Safetynet logging for b/154934934 |
| 3199 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3200 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3201 | throw new SecurityException("Not allowed to access cell info"); |
| 3202 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3203 | if (TelephonyPermissions |
| 3204 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3205 | // Safetynet logging for b/154934934 |
| 3206 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3207 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3208 | try { |
| 3209 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3210 | } catch (RemoteException re) { |
| 3211 | // Drop without consequences |
| 3212 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3213 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3214 | } |
| 3215 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3216 | |
| 3217 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3218 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3219 | |
| 3220 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3221 | } |
| 3222 | |
| 3223 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3224 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3225 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3226 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3227 | |
| 3228 | final long identity = Binder.clearCallingIdentity(); |
| 3229 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3230 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3231 | } finally { |
| 3232 | Binder.restoreCallingIdentity(identity); |
| 3233 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3234 | } |
| 3235 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3236 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3237 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3238 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3239 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3240 | return null; |
| 3241 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3242 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3243 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3244 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3245 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3246 | return null; |
| 3247 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3248 | |
| 3249 | final long identity = Binder.clearCallingIdentity(); |
| 3250 | try { |
| 3251 | return phone.getImei(); |
| 3252 | } finally { |
| 3253 | Binder.restoreCallingIdentity(identity); |
| 3254 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3255 | } |
| 3256 | |
| 3257 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3258 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3259 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3260 | String tac = null; |
| 3261 | if (phone != null) { |
| 3262 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3263 | try { |
| 3264 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3265 | } catch (IndexOutOfBoundsException e) { |
| 3266 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3267 | return null; |
| 3268 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3269 | } |
| 3270 | return tac; |
| 3271 | } |
| 3272 | |
| 3273 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3274 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3275 | try { |
| 3276 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3277 | } catch (SecurityException se) { |
| 3278 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3279 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3280 | + Binder.getCallingUid()); |
| 3281 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3282 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3283 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3284 | return null; |
| 3285 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3286 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3287 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3288 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3289 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3290 | return null; |
| 3291 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3292 | |
| 3293 | final long identity = Binder.clearCallingIdentity(); |
| 3294 | try { |
| 3295 | return phone.getMeid(); |
| 3296 | } finally { |
| 3297 | Binder.restoreCallingIdentity(identity); |
| 3298 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3299 | } |
| 3300 | |
| 3301 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3302 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3303 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3304 | String manufacturerCode = null; |
| 3305 | if (phone != null) { |
| 3306 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3307 | try { |
| 3308 | manufacturerCode = |
| 3309 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3310 | } catch (IndexOutOfBoundsException e) { |
| 3311 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3312 | return null; |
| 3313 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3314 | } |
| 3315 | return manufacturerCode; |
| 3316 | } |
| 3317 | |
| 3318 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3319 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3320 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3321 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3322 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3323 | return null; |
| 3324 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3325 | int subId = phone.getSubId(); |
| 3326 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3327 | mApp, subId, callingPackage, callingFeatureId, |
| 3328 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3329 | return null; |
| 3330 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3331 | |
| 3332 | final long identity = Binder.clearCallingIdentity(); |
| 3333 | try { |
| 3334 | return phone.getDeviceSvn(); |
| 3335 | } finally { |
| 3336 | Binder.restoreCallingIdentity(identity); |
| 3337 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3338 | } |
| 3339 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3340 | @Override |
| 3341 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3342 | final long identity = Binder.clearCallingIdentity(); |
| 3343 | try { |
| 3344 | final Phone phone = getPhone(subId); |
| 3345 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3346 | } finally { |
| 3347 | Binder.restoreCallingIdentity(identity); |
| 3348 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3349 | } |
| 3350 | |
| 3351 | @Override |
| 3352 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3353 | final long identity = Binder.clearCallingIdentity(); |
| 3354 | try { |
| 3355 | final Phone phone = getPhone(subId); |
| 3356 | return phone == null ? null : phone.getCarrierName(); |
| 3357 | } finally { |
| 3358 | Binder.restoreCallingIdentity(identity); |
| 3359 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3360 | } |
| 3361 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3362 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3363 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3364 | final long identity = Binder.clearCallingIdentity(); |
| 3365 | try { |
| 3366 | final Phone phone = getPhone(subId); |
| 3367 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3368 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3369 | } finally { |
| 3370 | Binder.restoreCallingIdentity(identity); |
| 3371 | } |
| 3372 | } |
| 3373 | |
| 3374 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3375 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3376 | final long identity = Binder.clearCallingIdentity(); |
| 3377 | try { |
| 3378 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3379 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3380 | } finally { |
| 3381 | Binder.restoreCallingIdentity(identity); |
| 3382 | } |
| 3383 | } |
| 3384 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3385 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3386 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3387 | if (!isSubscriptionMccMnc) { |
| 3388 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3389 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3390 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3391 | if (phone == null) { |
| 3392 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3393 | } |
| 3394 | final long identity = Binder.clearCallingIdentity(); |
| 3395 | try { |
| 3396 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3397 | } finally { |
| 3398 | Binder.restoreCallingIdentity(identity); |
| 3399 | } |
| 3400 | } |
| 3401 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3402 | // |
| 3403 | // Internal helper methods. |
| 3404 | // |
| 3405 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3406 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3407 | * Make sure the caller is the calling package itself |
| 3408 | * |
| 3409 | * @throws SecurityException if the caller is not the calling package |
| 3410 | */ |
| 3411 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3412 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3413 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3414 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3415 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3416 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3417 | } catch (PackageManager.NameNotFoundException e) { |
| 3418 | // packageUid is -1 |
| 3419 | } |
| 3420 | if (packageUid != callingUid) { |
| 3421 | throw new SecurityException(message + ": Package " + callingPackage |
| 3422 | + " does not belong to " + callingUid); |
| 3423 | } |
| 3424 | } |
| 3425 | |
| 3426 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3427 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3428 | * |
| 3429 | * @throws SecurityException if the caller does not have the required permission |
| 3430 | */ |
| 3431 | private void enforceModifyPermission() { |
| 3432 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3433 | } |
| 3434 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3435 | private void enforceActiveEmergencySessionPermission() { |
| 3436 | mApp.enforceCallingOrSelfPermission( |
| 3437 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3438 | } |
| 3439 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3440 | /** |
| 3441 | * Make sure the caller has the CALL_PHONE permission. |
| 3442 | * |
| 3443 | * @throws SecurityException if the caller does not have the required permission |
| 3444 | */ |
| 3445 | private void enforceCallPermission() { |
| 3446 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3447 | } |
| 3448 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3449 | private void enforceSettingsPermission() { |
| 3450 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3451 | } |
| 3452 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3453 | private void enforceRebootPermission() { |
| 3454 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3455 | } |
| 3456 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3457 | private String createTelUrl(String number) { |
| 3458 | if (TextUtils.isEmpty(number)) { |
| 3459 | return null; |
| 3460 | } |
| 3461 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3462 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3463 | } |
| 3464 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3465 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3466 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3467 | } |
| 3468 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3469 | private static void logv(String msg) { |
| 3470 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3471 | } |
| 3472 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3473 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3474 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3475 | } |
| 3476 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3477 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3478 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3479 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3480 | } |
| 3481 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3482 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3483 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3484 | final long identity = Binder.clearCallingIdentity(); |
| 3485 | try { |
| 3486 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3487 | if (phone == null) { |
| 3488 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3489 | } else { |
| 3490 | return phone.getPhoneType(); |
| 3491 | } |
| 3492 | } finally { |
| 3493 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3494 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3495 | } |
| 3496 | |
| 3497 | /** |
| 3498 | * Returns the CDMA ERI icon index to display |
| 3499 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3500 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3501 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3502 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3503 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3504 | } |
| 3505 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3506 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3507 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3508 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3509 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3510 | mApp, subId, callingPackage, callingFeatureId, |
| 3511 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3512 | return -1; |
| 3513 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3514 | |
| 3515 | final long identity = Binder.clearCallingIdentity(); |
| 3516 | try { |
| 3517 | final Phone phone = getPhone(subId); |
| 3518 | if (phone != null) { |
| 3519 | return phone.getCdmaEriIconIndex(); |
| 3520 | } else { |
| 3521 | return -1; |
| 3522 | } |
| 3523 | } finally { |
| 3524 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3525 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3526 | } |
| 3527 | |
| 3528 | /** |
| 3529 | * Returns the CDMA ERI icon mode, |
| 3530 | * 0 - ON |
| 3531 | * 1 - FLASHING |
| 3532 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3533 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3534 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3535 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3536 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3537 | } |
| 3538 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3539 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3540 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3541 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3542 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3543 | mApp, subId, callingPackage, callingFeatureId, |
| 3544 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3545 | return -1; |
| 3546 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3547 | |
| 3548 | final long identity = Binder.clearCallingIdentity(); |
| 3549 | try { |
| 3550 | final Phone phone = getPhone(subId); |
| 3551 | if (phone != null) { |
| 3552 | return phone.getCdmaEriIconMode(); |
| 3553 | } else { |
| 3554 | return -1; |
| 3555 | } |
| 3556 | } finally { |
| 3557 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3558 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3559 | } |
| 3560 | |
| 3561 | /** |
| 3562 | * Returns the CDMA ERI text, |
| 3563 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3564 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3565 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3566 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3567 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3568 | } |
| 3569 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3570 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3571 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3572 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3573 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3574 | mApp, subId, callingPackage, callingFeatureId, |
| 3575 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3576 | return null; |
| 3577 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3578 | |
| 3579 | final long identity = Binder.clearCallingIdentity(); |
| 3580 | try { |
| 3581 | final Phone phone = getPhone(subId); |
| 3582 | if (phone != null) { |
| 3583 | return phone.getCdmaEriText(); |
| 3584 | } else { |
| 3585 | return null; |
| 3586 | } |
| 3587 | } finally { |
| 3588 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3589 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3590 | } |
| 3591 | |
| 3592 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3593 | * Returns the CDMA MDN. |
| 3594 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3595 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3596 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3597 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3598 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3599 | |
| 3600 | final long identity = Binder.clearCallingIdentity(); |
| 3601 | try { |
| 3602 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3603 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3604 | return phone.getLine1Number(); |
| 3605 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3606 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3607 | return null; |
| 3608 | } |
| 3609 | } finally { |
| 3610 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3611 | } |
| 3612 | } |
| 3613 | |
| 3614 | /** |
| 3615 | * Returns the CDMA MIN. |
| 3616 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3617 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3618 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3619 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3620 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3621 | |
| 3622 | final long identity = Binder.clearCallingIdentity(); |
| 3623 | try { |
| 3624 | final Phone phone = getPhone(subId); |
| 3625 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3626 | return phone.getCdmaMin(); |
| 3627 | } else { |
| 3628 | return null; |
| 3629 | } |
| 3630 | } finally { |
| 3631 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3632 | } |
| 3633 | } |
| 3634 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3635 | @Override |
| 3636 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3637 | INumberVerificationCallback callback, String callingPackage) { |
| 3638 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3639 | != PERMISSION_GRANTED) { |
| 3640 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3641 | } |
| 3642 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3643 | |
| 3644 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3645 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3646 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3647 | + "calling package: " + callingPackage |
| 3648 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3649 | } |
| 3650 | |
| 3651 | if (range == null) { |
| 3652 | throw new NullPointerException("Range must be non-null"); |
| 3653 | } |
| 3654 | |
| 3655 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3656 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3657 | |
| 3658 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3659 | } |
| 3660 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3661 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3662 | * Returns true if CDMA provisioning needs to run. |
| 3663 | */ |
| 3664 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3665 | final long identity = Binder.clearCallingIdentity(); |
| 3666 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3667 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3668 | } finally { |
| 3669 | Binder.restoreCallingIdentity(identity); |
| 3670 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3671 | } |
| 3672 | |
| 3673 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3674 | * Sets the voice mail number of a given subId. |
| 3675 | */ |
| 3676 | @Override |
| 3677 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3678 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3679 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3680 | |
| 3681 | final long identity = Binder.clearCallingIdentity(); |
| 3682 | try { |
| 3683 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3684 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3685 | return success; |
| 3686 | } finally { |
| 3687 | Binder.restoreCallingIdentity(identity); |
| 3688 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3689 | } |
| 3690 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3691 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3692 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3693 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3694 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3695 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3696 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3697 | throw new SecurityException("caller must be system dialer"); |
| 3698 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3699 | |
| 3700 | final long identity = Binder.clearCallingIdentity(); |
| 3701 | try { |
| 3702 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3703 | if (phoneAccountHandle == null) { |
| 3704 | return null; |
| 3705 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3706 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3707 | } finally { |
| 3708 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3709 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3710 | } |
| 3711 | |
| 3712 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3713 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3714 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3715 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3716 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3717 | mApp, subId, callingPackage, callingFeatureId, |
| 3718 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3719 | return null; |
| 3720 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3721 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3722 | final long identity = Binder.clearCallingIdentity(); |
| 3723 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3724 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3725 | } finally { |
| 3726 | Binder.restoreCallingIdentity(identity); |
| 3727 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3728 | } |
| 3729 | |
| 3730 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3731 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3732 | VisualVoicemailSmsFilterSettings settings) { |
| 3733 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3734 | |
| 3735 | final long identity = Binder.clearCallingIdentity(); |
| 3736 | try { |
| 3737 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3738 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3739 | } finally { |
| 3740 | Binder.restoreCallingIdentity(identity); |
| 3741 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3742 | } |
| 3743 | |
| 3744 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3745 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3746 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3747 | |
| 3748 | final long identity = Binder.clearCallingIdentity(); |
| 3749 | try { |
| 3750 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3751 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3752 | } finally { |
| 3753 | Binder.restoreCallingIdentity(identity); |
| 3754 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3755 | } |
| 3756 | |
| 3757 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3758 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3759 | String callingPackage, int subId) { |
| 3760 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3761 | |
| 3762 | final long identity = Binder.clearCallingIdentity(); |
| 3763 | try { |
| 3764 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3765 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3766 | } finally { |
| 3767 | Binder.restoreCallingIdentity(identity); |
| 3768 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3769 | } |
| 3770 | |
| 3771 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3772 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3773 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3774 | |
| 3775 | final long identity = Binder.clearCallingIdentity(); |
| 3776 | try { |
| 3777 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3778 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3779 | } finally { |
| 3780 | Binder.restoreCallingIdentity(identity); |
| 3781 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3782 | } |
| 3783 | |
| 3784 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3785 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3786 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3787 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3788 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3789 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3790 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3791 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3792 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3793 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3794 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3795 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3796 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3797 | * Sets the voice activation state of a given subId. |
| 3798 | */ |
| 3799 | @Override |
| 3800 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3801 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3802 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3803 | |
| 3804 | final long identity = Binder.clearCallingIdentity(); |
| 3805 | try { |
| 3806 | final Phone phone = getPhone(subId); |
| 3807 | if (phone != null) { |
| 3808 | phone.setVoiceActivationState(activationState); |
| 3809 | } else { |
| 3810 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3811 | } |
| 3812 | } finally { |
| 3813 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3814 | } |
| 3815 | } |
| 3816 | |
| 3817 | /** |
| 3818 | * Sets the data activation state of a given subId. |
| 3819 | */ |
| 3820 | @Override |
| 3821 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3822 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3823 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3824 | |
| 3825 | final long identity = Binder.clearCallingIdentity(); |
| 3826 | try { |
| 3827 | final Phone phone = getPhone(subId); |
| 3828 | if (phone != null) { |
| 3829 | phone.setDataActivationState(activationState); |
| 3830 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3831 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3832 | } |
| 3833 | } finally { |
| 3834 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3835 | } |
| 3836 | } |
| 3837 | |
| 3838 | /** |
| 3839 | * Returns the voice activation state of a given subId. |
| 3840 | */ |
| 3841 | @Override |
| 3842 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3843 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3844 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3845 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3846 | final long identity = Binder.clearCallingIdentity(); |
| 3847 | try { |
| 3848 | if (phone != null) { |
| 3849 | return phone.getVoiceActivationState(); |
| 3850 | } else { |
| 3851 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3852 | } |
| 3853 | } finally { |
| 3854 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3855 | } |
| 3856 | } |
| 3857 | |
| 3858 | /** |
| 3859 | * Returns the data activation state of a given subId. |
| 3860 | */ |
| 3861 | @Override |
| 3862 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3863 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3864 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3865 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3866 | final long identity = Binder.clearCallingIdentity(); |
| 3867 | try { |
| 3868 | if (phone != null) { |
| 3869 | return phone.getDataActivationState(); |
| 3870 | } else { |
| 3871 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3872 | } |
| 3873 | } finally { |
| 3874 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3875 | } |
| 3876 | } |
| 3877 | |
| 3878 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3879 | * Returns the unread count of voicemails for a subId |
| 3880 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3881 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3882 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3883 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3884 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3885 | mApp, subId, callingPackage, callingFeatureId, |
| 3886 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3887 | return 0; |
| 3888 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3889 | final long identity = Binder.clearCallingIdentity(); |
| 3890 | try { |
| 3891 | final Phone phone = getPhone(subId); |
| 3892 | if (phone != null) { |
| 3893 | return phone.getVoiceMessageCount(); |
| 3894 | } else { |
| 3895 | return 0; |
| 3896 | } |
| 3897 | } finally { |
| 3898 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3899 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3900 | } |
| 3901 | |
| 3902 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3903 | * returns true, if the device is in a state where both voice and data |
| 3904 | * are supported simultaneously. This can change based on location or network condition. |
| 3905 | */ |
| 3906 | @Override |
| 3907 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3908 | final long identity = Binder.clearCallingIdentity(); |
| 3909 | try { |
| 3910 | final Phone phone = getPhone(subId); |
| 3911 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3912 | } finally { |
| 3913 | Binder.restoreCallingIdentity(identity); |
| 3914 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3915 | } |
| 3916 | |
| 3917 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3918 | * Send the dialer code if called from the current default dialer or the caller has |
| 3919 | * carrier privilege. |
| 3920 | * @param inputCode The dialer code to send |
| 3921 | */ |
| 3922 | @Override |
| 3923 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3924 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3925 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3926 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3927 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3928 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3929 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3930 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3931 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3932 | |
| 3933 | final long identity = Binder.clearCallingIdentity(); |
| 3934 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3935 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3936 | } finally { |
| 3937 | Binder.restoreCallingIdentity(identity); |
| 3938 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3939 | } |
| 3940 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3941 | @Override |
| 3942 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3943 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3944 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3945 | mApp, subId, "getNetworkSelectionMode"); |
| 3946 | final long identity = Binder.clearCallingIdentity(); |
| 3947 | try { |
| 3948 | if (!isActiveSubscription(subId)) { |
| 3949 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3950 | } |
| 3951 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3952 | } finally { |
| 3953 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3954 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3955 | } |
| 3956 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3957 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3958 | public boolean isInEmergencySmsMode() { |
| 3959 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3960 | final long identity = Binder.clearCallingIdentity(); |
| 3961 | try { |
| 3962 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3963 | if (phone.isInEmergencySmsMode()) { |
| 3964 | return true; |
| 3965 | } |
| 3966 | } |
| 3967 | } finally { |
| 3968 | Binder.restoreCallingIdentity(identity); |
| 3969 | } |
| 3970 | return false; |
| 3971 | } |
| 3972 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3973 | /** |
| 3974 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3975 | * @param subId The subscription to use to check the configuration. |
| 3976 | * @param c The callback that will be used to send the result. |
| 3977 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3978 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3979 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3980 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3981 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3982 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3983 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3984 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3985 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3986 | "IMS not available on device."); |
| 3987 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3988 | final long token = Binder.clearCallingIdentity(); |
| 3989 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 3990 | int slotId = getSlotIndexOrException(subId); |
| 3991 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 3992 | ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3993 | } catch (ImsException e) { |
| 3994 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3995 | } finally { |
| 3996 | Binder.restoreCallingIdentity(token); |
| 3997 | } |
| 3998 | } |
| 3999 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4000 | /** |
| 4001 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4002 | * @param subId The subscription to use to check the configuration. |
| 4003 | * @param c The callback that will be used to send the result. |
| 4004 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4005 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4006 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4007 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4008 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4009 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4010 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4011 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4012 | final long token = Binder.clearCallingIdentity(); |
| 4013 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4014 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 4015 | .removeRegistrationCallbackForSubscription(c, subId); |
| 4016 | } catch (ImsException e) { |
| 4017 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4018 | + "is inactive, ignoring unregister."); |
| 4019 | // If the subscription is no longer active, just return, since the callback |
| 4020 | // will already have been removed internally. |
| 4021 | } finally { |
| 4022 | Binder.restoreCallingIdentity(token); |
| 4023 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4024 | } |
| 4025 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4026 | /** |
| 4027 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4028 | */ |
| 4029 | @Override |
| 4030 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4031 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4032 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4033 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4034 | "IMS not available on device."); |
| 4035 | } |
| 4036 | final long token = Binder.clearCallingIdentity(); |
| 4037 | try { |
| 4038 | Phone phone = getPhone(subId); |
| 4039 | if (phone == null) { |
| 4040 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4041 | + subId + "'"); |
| 4042 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4043 | } |
| 4044 | phone.getImsRegistrationState(regState -> { |
| 4045 | try { |
| 4046 | consumer.accept((regState == null) |
| 4047 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4048 | } catch (RemoteException e) { |
| 4049 | // Ignore if the remote process is no longer available to call back. |
| 4050 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4051 | } |
| 4052 | }); |
| 4053 | } finally { |
| 4054 | Binder.restoreCallingIdentity(token); |
| 4055 | } |
| 4056 | } |
| 4057 | |
| 4058 | /** |
| 4059 | * Get the transport type for the IMS service registration state. |
| 4060 | */ |
| 4061 | @Override |
| 4062 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4063 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4064 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4065 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4066 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4067 | "IMS not available on device."); |
| 4068 | } |
| 4069 | final long token = Binder.clearCallingIdentity(); |
| 4070 | try { |
| 4071 | Phone phone = getPhone(subId); |
| 4072 | if (phone == null) { |
| 4073 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4074 | + subId + "'"); |
| 4075 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4076 | } |
| 4077 | phone.getImsRegistrationTech(regTech -> { |
| 4078 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4079 | int regTechConverted = (regTech == null) |
| 4080 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4081 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4082 | regTechConverted); |
| 4083 | try { |
| 4084 | consumer.accept(regTechConverted); |
| 4085 | } catch (RemoteException e) { |
| 4086 | // Ignore if the remote process is no longer available to call back. |
| 4087 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4088 | } |
| 4089 | }); |
| 4090 | } finally { |
| 4091 | Binder.restoreCallingIdentity(token); |
| 4092 | } |
| 4093 | } |
| 4094 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4095 | /** |
| 4096 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4097 | * @param subId The subscription to use to check the configuration. |
| 4098 | * @param c The callback that will be used to send the result. |
| 4099 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4100 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4101 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4102 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4103 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4104 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4105 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4106 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4107 | "IMS not available on device."); |
| 4108 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4109 | final long token = Binder.clearCallingIdentity(); |
| 4110 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4111 | int slotId = getSlotIndexOrException(subId); |
| 4112 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4113 | ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4114 | } catch (ImsException e) { |
| 4115 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4116 | } finally { |
| 4117 | Binder.restoreCallingIdentity(token); |
| 4118 | } |
| 4119 | } |
| 4120 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4121 | /** |
| 4122 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4123 | * @param subId The subscription to use to check the configuration. |
| 4124 | * @param c The callback that will be used to send the result. |
| 4125 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4126 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4127 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4128 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4129 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4130 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4131 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4132 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4133 | |
| 4134 | final long token = Binder.clearCallingIdentity(); |
| 4135 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4136 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4137 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4138 | } catch (ImsException e) { |
| 4139 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4140 | + "is inactive, ignoring unregister."); |
| 4141 | // If the subscription is no longer active, just return, since the callback |
| 4142 | // will already have been removed internally. |
| 4143 | } finally { |
| 4144 | Binder.restoreCallingIdentity(token); |
| 4145 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4146 | } |
| 4147 | |
| 4148 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4149 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4150 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4151 | final long token = Binder.clearCallingIdentity(); |
| 4152 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4153 | int slotId = getSlotIndexOrException(subId); |
| 4154 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4155 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4156 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4157 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4158 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4159 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4160 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4161 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4162 | } finally { |
| 4163 | Binder.restoreCallingIdentity(token); |
| 4164 | } |
| 4165 | } |
| 4166 | |
| 4167 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4168 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4169 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4170 | final long token = Binder.clearCallingIdentity(); |
| 4171 | try { |
| 4172 | Phone phone = getPhone(subId); |
| 4173 | if (phone == null) return false; |
| 4174 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4175 | } catch (com.android.ims.ImsException e) { |
| 4176 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4177 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4178 | } finally { |
| 4179 | Binder.restoreCallingIdentity(token); |
| 4180 | } |
| 4181 | } |
| 4182 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4183 | /** |
| 4184 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4185 | * subscription. |
| 4186 | * @param subId The subscription to use to check the configuration. |
| 4187 | * @param callback The callback that will be used to send the result. |
| 4188 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4189 | * @param transportType The transport type of the MmTelFeature capability. |
| 4190 | */ |
| 4191 | @Override |
| 4192 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4193 | int transportType) { |
| 4194 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 4195 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4196 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4197 | "IMS not available on device."); |
| 4198 | } |
| 4199 | final long token = Binder.clearCallingIdentity(); |
| 4200 | try { |
| 4201 | int slotId = getSlotIndex(subId); |
| 4202 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4203 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4204 | + subId + "'"); |
| 4205 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4206 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4207 | verifyImsMmTelConfiguredOrThrow(slotId); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4208 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4209 | transportType, aBoolean -> { |
| 4210 | try { |
| 4211 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4212 | } catch (RemoteException e) { |
| 4213 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4214 | + "running. Ignore"); |
| 4215 | } |
| 4216 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4217 | } catch (ImsException e) { |
| 4218 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4219 | } finally { |
| 4220 | Binder.restoreCallingIdentity(token); |
| 4221 | } |
| 4222 | } |
| 4223 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4224 | /** |
| 4225 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4226 | * @param subId The subscription to use to check the configuration. |
| 4227 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4228 | @Override |
| 4229 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4230 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4231 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4232 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4233 | final long token = Binder.clearCallingIdentity(); |
| 4234 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4235 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4236 | // 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] | 4237 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4238 | } catch (ImsException e) { |
| 4239 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4240 | } finally { |
| 4241 | Binder.restoreCallingIdentity(token); |
| 4242 | } |
| 4243 | } |
| 4244 | |
| 4245 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4246 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4247 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4248 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4249 | final long identity = Binder.clearCallingIdentity(); |
| 4250 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4251 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4252 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4253 | // 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] | 4254 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4255 | } catch (ImsException e) { |
| 4256 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4257 | } finally { |
| 4258 | Binder.restoreCallingIdentity(identity); |
| 4259 | } |
| 4260 | } |
| 4261 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4262 | /** |
| 4263 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4264 | * @param subId The subscription to use to check the configuration. |
| 4265 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4266 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4267 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4268 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4269 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4270 | final long identity = Binder.clearCallingIdentity(); |
| 4271 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4272 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4273 | // 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] | 4274 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4275 | } catch (ImsException e) { |
| 4276 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4277 | } finally { |
| 4278 | Binder.restoreCallingIdentity(identity); |
| 4279 | } |
| 4280 | } |
| 4281 | |
| 4282 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4283 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4284 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4285 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4286 | final long identity = Binder.clearCallingIdentity(); |
| 4287 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4288 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4289 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4290 | // 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] | 4291 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4292 | } catch (ImsException e) { |
| 4293 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4294 | } finally { |
| 4295 | Binder.restoreCallingIdentity(identity); |
| 4296 | } |
| 4297 | } |
| 4298 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4299 | /** |
| 4300 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4301 | * @param subId The subscription to use to check the configuration. |
| 4302 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4303 | @Override |
| 4304 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4305 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4306 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4307 | final long identity = Binder.clearCallingIdentity(); |
| 4308 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4309 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4310 | // 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] | 4311 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4312 | } catch (ImsException e) { |
| 4313 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4314 | } finally { |
| 4315 | Binder.restoreCallingIdentity(identity); |
| 4316 | } |
| 4317 | } |
| 4318 | |
| 4319 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4320 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4321 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4322 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4323 | final long identity = Binder.clearCallingIdentity(); |
| 4324 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4325 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4326 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4327 | // 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] | 4328 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4329 | } catch (ImsException e) { |
| 4330 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4331 | } finally { |
| 4332 | Binder.restoreCallingIdentity(identity); |
| 4333 | } |
| 4334 | } |
| 4335 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4336 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4337 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4338 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4339 | * @param subId The subscription to use to check the configuration. |
| 4340 | */ |
| 4341 | @Override |
| 4342 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4343 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4344 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4345 | final long identity = Binder.clearCallingIdentity(); |
| 4346 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4347 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4348 | // 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] | 4349 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4350 | } catch (ImsException e) { |
| 4351 | throw new ServiceSpecificException(e.getCode()); |
| 4352 | } finally { |
| 4353 | Binder.restoreCallingIdentity(identity); |
| 4354 | } |
| 4355 | } |
| 4356 | |
| 4357 | /** |
| 4358 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4359 | * Requires MODIFY_PHONE_STATE permission. |
| 4360 | * @param subId The subscription to use to check the configuration. |
| 4361 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4362 | * false otherwise |
| 4363 | */ |
| 4364 | @Override |
| 4365 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4366 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4367 | "setCrossSimCallingEnabled"); |
| 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).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4374 | } catch (ImsException e) { |
| 4375 | throw new ServiceSpecificException(e.getCode()); |
| 4376 | } finally { |
| 4377 | Binder.restoreCallingIdentity(identity); |
| 4378 | } |
| 4379 | } |
| 4380 | |
| 4381 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4382 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4383 | * @param subId The subscription to use to check the configuration. |
| 4384 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4385 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4386 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4387 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4388 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4389 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 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).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4395 | } catch (ImsException e) { |
| 4396 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4397 | } finally { |
| 4398 | Binder.restoreCallingIdentity(identity); |
| 4399 | } |
| 4400 | } |
| 4401 | |
| 4402 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4403 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4404 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4405 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4406 | final long identity = Binder.clearCallingIdentity(); |
| 4407 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4408 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4409 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4410 | // 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] | 4411 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4412 | } catch (ImsException e) { |
| 4413 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4414 | } finally { |
| 4415 | Binder.restoreCallingIdentity(identity); |
| 4416 | } |
| 4417 | } |
| 4418 | |
| 4419 | @Override |
| 4420 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4421 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4422 | "setVoWiFiNonPersistent"); |
| 4423 | final long identity = Binder.clearCallingIdentity(); |
| 4424 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4425 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4426 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4427 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4428 | } catch (ImsException e) { |
| 4429 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4430 | } finally { |
| 4431 | Binder.restoreCallingIdentity(identity); |
| 4432 | } |
| 4433 | } |
| 4434 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4435 | /** |
| 4436 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4437 | * @param subId The subscription to use to check the configuration. |
| 4438 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4439 | @Override |
| 4440 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4441 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4442 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4443 | final long identity = Binder.clearCallingIdentity(); |
| 4444 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4445 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4446 | // 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] | 4447 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4448 | } catch (ImsException e) { |
| 4449 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4450 | } finally { |
| 4451 | Binder.restoreCallingIdentity(identity); |
| 4452 | } |
| 4453 | } |
| 4454 | |
| 4455 | @Override |
| 4456 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4457 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4458 | "setVoWiFiModeSetting"); |
| 4459 | final long identity = Binder.clearCallingIdentity(); |
| 4460 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4461 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4462 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4463 | // 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] | 4464 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4465 | } catch (ImsException e) { |
| 4466 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4467 | } finally { |
| 4468 | Binder.restoreCallingIdentity(identity); |
| 4469 | } |
| 4470 | } |
| 4471 | |
| 4472 | @Override |
| 4473 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4474 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4475 | final long identity = Binder.clearCallingIdentity(); |
| 4476 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4477 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4478 | // 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] | 4479 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4480 | } catch (ImsException e) { |
| 4481 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4482 | } finally { |
| 4483 | Binder.restoreCallingIdentity(identity); |
| 4484 | } |
| 4485 | } |
| 4486 | |
| 4487 | @Override |
| 4488 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4489 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4490 | "setVoWiFiRoamingModeSetting"); |
| 4491 | final long identity = Binder.clearCallingIdentity(); |
| 4492 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4493 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4494 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4495 | // 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] | 4496 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4497 | } catch (ImsException e) { |
| 4498 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4499 | } finally { |
| 4500 | Binder.restoreCallingIdentity(identity); |
| 4501 | } |
| 4502 | } |
| 4503 | |
| 4504 | @Override |
| 4505 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4506 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4507 | "setRttCapabilityEnabled"); |
| 4508 | final long identity = Binder.clearCallingIdentity(); |
| 4509 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4510 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4511 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4512 | // 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] | 4513 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4514 | } catch (ImsException e) { |
| 4515 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4516 | } finally { |
| 4517 | Binder.restoreCallingIdentity(identity); |
| 4518 | } |
| 4519 | } |
| 4520 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4521 | /** |
| 4522 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4523 | * @param subId The subscription to use to check the configuration. |
| 4524 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4525 | @Override |
| 4526 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4527 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4528 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4529 | final long identity = Binder.clearCallingIdentity(); |
| 4530 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4531 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4532 | // 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] | 4533 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4534 | } catch (ImsException e) { |
| 4535 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4536 | } finally { |
| 4537 | Binder.restoreCallingIdentity(identity); |
| 4538 | } |
| 4539 | } |
| 4540 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4541 | @Override |
| 4542 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4543 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4544 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4545 | final long identity = Binder.clearCallingIdentity(); |
| 4546 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4547 | if (!isImsAvailableOnDevice()) { |
| 4548 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4549 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4550 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4551 | int slotId = getSlotIndexOrException(subId); |
| 4552 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4553 | ImsManager.getInstance(mApp, slotId) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4554 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4555 | } catch (ImsException e) { |
| 4556 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4557 | } finally { |
| 4558 | Binder.restoreCallingIdentity(identity); |
| 4559 | } |
| 4560 | } |
| 4561 | |
| 4562 | @Override |
| 4563 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4564 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4565 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4566 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4567 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4568 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4569 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4570 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4571 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4572 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4573 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4574 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4575 | + "is inactive, ignoring unregister."); |
| 4576 | // If the subscription is no longer active, just return, since the callback will already |
| 4577 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4578 | } finally { |
| 4579 | Binder.restoreCallingIdentity(identity); |
| 4580 | } |
| 4581 | } |
| 4582 | |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4583 | @Override |
| 4584 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 4585 | IFeatureProvisioningCallback callback) { |
| 4586 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4587 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 4588 | |
| 4589 | final long identity = Binder.clearCallingIdentity(); |
| 4590 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4591 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4592 | } |
| 4593 | |
| 4594 | ImsProvisioningController.getInstance() |
| 4595 | .addFeatureProvisioningChangedCallback(subId, callback); |
| 4596 | |
| 4597 | Binder.restoreCallingIdentity(identity); |
| 4598 | } |
| 4599 | |
| 4600 | @Override |
| 4601 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 4602 | IFeatureProvisioningCallback callback) { |
| 4603 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4604 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 4605 | |
| 4606 | final long identity = Binder.clearCallingIdentity(); |
| 4607 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4608 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4609 | } |
| 4610 | |
| 4611 | ImsProvisioningController.getInstance() |
| 4612 | .removeFeatureProvisioningChangedCallback(subId, callback); |
| 4613 | |
| 4614 | Binder.restoreCallingIdentity(identity); |
| 4615 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4616 | |
| 4617 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4618 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4619 | message); |
| 4620 | } |
| 4621 | |
| 4622 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4623 | boolean isMmtelCapability) { |
| 4624 | Phone phone = getPhone(subId); |
| 4625 | if (phone == null) { |
| 4626 | loge("phone instance null for subid " + subId); |
| 4627 | return false; |
| 4628 | } |
| 4629 | if (isMmtelCapability) { |
| 4630 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4631 | return false; |
| 4632 | } |
| 4633 | } else { |
| 4634 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4635 | return false; |
| 4636 | } |
| 4637 | } |
| 4638 | return true; |
| 4639 | } |
| 4640 | |
| 4641 | @Override |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4642 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4643 | boolean isProvisioned) { |
| 4644 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4645 | |
| 4646 | final long identity = Binder.clearCallingIdentity(); |
| 4647 | try { |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4648 | ImsProvisioningController.getInstance() |
| 4649 | .setRcsProvisioningStatusForCapability(subId, capability, tech, isProvisioned); |
| 4650 | return; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4651 | } finally { |
| 4652 | Binder.restoreCallingIdentity(identity); |
| 4653 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4654 | } |
| 4655 | |
| 4656 | |
| 4657 | @Override |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4658 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4659 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4660 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 4661 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4662 | final long identity = Binder.clearCallingIdentity(); |
| 4663 | try { |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4664 | return ImsProvisioningController.getInstance() |
| 4665 | .getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4666 | } finally { |
| 4667 | Binder.restoreCallingIdentity(identity); |
| 4668 | } |
| 4669 | } |
| 4670 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4671 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4672 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4673 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4674 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4675 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4676 | final long identity = Binder.clearCallingIdentity(); |
| 4677 | try { |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4678 | ImsProvisioningController.getInstance() |
| 4679 | .setImsProvisioningStatusForCapability(subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4680 | } finally { |
| 4681 | Binder.restoreCallingIdentity(identity); |
| 4682 | } |
| 4683 | } |
| 4684 | |
| 4685 | @Override |
| 4686 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4687 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4688 | mApp, subId, "getProvisioningStatusForCapability"); |
| 4689 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4690 | final long identity = Binder.clearCallingIdentity(); |
| 4691 | try { |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4692 | return ImsProvisioningController.getInstance() |
| 4693 | .getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4694 | |
| 4695 | } finally { |
| 4696 | Binder.restoreCallingIdentity(identity); |
| 4697 | } |
| 4698 | } |
| 4699 | |
| 4700 | @Override |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4701 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4702 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4703 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 4704 | |
| 4705 | final long identity = Binder.clearCallingIdentity(); |
| 4706 | try { |
| 4707 | return ImsProvisioningController.getInstance() |
| 4708 | .isImsProvisioningRequiredForCapability(subId, capability, tech); |
| 4709 | } finally { |
| 4710 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4711 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4712 | } |
| 4713 | |
| 4714 | @Override |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4715 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4716 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4717 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4718 | |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4719 | final long identity = Binder.clearCallingIdentity(); |
| 4720 | try { |
| 4721 | return ImsProvisioningController.getInstance() |
| 4722 | .isRcsProvisioningRequiredForCapability(subId, capability, tech); |
| 4723 | } finally { |
| 4724 | Binder.restoreCallingIdentity(identity); |
| 4725 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4726 | } |
| 4727 | |
| 4728 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4729 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4730 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4731 | } |
| 4732 | |
| 4733 | /** |
| 4734 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4735 | * carrier associated with the subscription id. |
| 4736 | */ |
| 4737 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4738 | int capability) { |
| 4739 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4740 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4741 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4742 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4743 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4744 | false); |
| 4745 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4746 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4747 | |
| 4748 | // First check to make sure that the capability requires provisioning. |
| 4749 | switch (capability) { |
| 4750 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4751 | // intentional fallthrough |
| 4752 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4753 | if (requireVoiceVtProvisioning) { |
| 4754 | // Voice and Video requires provisioning |
| 4755 | return true; |
| 4756 | } |
| 4757 | break; |
| 4758 | } |
| 4759 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4760 | if (requireUtProvisioning) { |
| 4761 | // UT requires provisioning |
| 4762 | return true; |
| 4763 | } |
| 4764 | break; |
| 4765 | } |
| 4766 | } |
| 4767 | return false; |
| 4768 | } |
| 4769 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4770 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4771 | int capability) { |
| 4772 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4773 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4774 | |
| 4775 | boolean requireRcsProvisioning = c.getBoolean( |
| 4776 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4777 | |
| 4778 | // First check to make sure that the capability requires provisioning. |
| 4779 | switch (capability) { |
| 4780 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4781 | // intentional fallthrough |
| 4782 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4783 | if (requireRcsProvisioning) { |
| 4784 | // OPTION or PRESENCE requires provisioning |
| 4785 | return true; |
| 4786 | } |
| 4787 | break; |
| 4788 | } |
| 4789 | } |
| 4790 | return false; |
| 4791 | } |
| 4792 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4793 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4794 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4795 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4796 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4797 | } |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4798 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4799 | mApp, subId, "getImsProvisioningInt"); |
| 4800 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4801 | final long identity = Binder.clearCallingIdentity(); |
| 4802 | try { |
| 4803 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4804 | int slotId = getSlotIndex(subId); |
| 4805 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4806 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4807 | + subId + "' for key:" + key); |
| 4808 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4809 | } |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4810 | |
| 4811 | int retVal = ImsProvisioningController.getInstance().getProvisioningValue(subId, key); |
| 4812 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 4813 | return retVal; |
| 4814 | } |
| 4815 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4816 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4817 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4818 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4819 | + subId + "' for key:" + key); |
| 4820 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4821 | } finally { |
| 4822 | Binder.restoreCallingIdentity(identity); |
| 4823 | } |
| 4824 | } |
| 4825 | |
| 4826 | @Override |
| 4827 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4828 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4829 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4830 | } |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4831 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4832 | mApp, subId, "getImsProvisioningString"); |
| 4833 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4834 | final long identity = Binder.clearCallingIdentity(); |
| 4835 | try { |
| 4836 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4837 | int slotId = getSlotIndex(subId); |
| 4838 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4839 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4840 | + subId + "' for key:" + key); |
| 4841 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4842 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4843 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4844 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4845 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4846 | + subId + "' for key:" + key); |
| 4847 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4848 | } finally { |
| 4849 | Binder.restoreCallingIdentity(identity); |
| 4850 | } |
| 4851 | } |
| 4852 | |
| 4853 | @Override |
| 4854 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4855 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4856 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4857 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4858 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4859 | "setImsProvisioningInt"); |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4860 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4861 | final long identity = Binder.clearCallingIdentity(); |
| 4862 | try { |
| 4863 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4864 | int slotId = getSlotIndex(subId); |
| 4865 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4866 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4867 | + subId + "' for key:" + key); |
| 4868 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4869 | } |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4870 | |
| 4871 | int retVal = ImsProvisioningController.getInstance() |
| 4872 | .setProvisioningValue(subId, key, value); |
| 4873 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 4874 | return retVal; |
| 4875 | } |
| 4876 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4877 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4878 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4879 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4880 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4881 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4882 | } finally { |
| 4883 | Binder.restoreCallingIdentity(identity); |
| 4884 | } |
| 4885 | } |
| 4886 | |
| 4887 | @Override |
| 4888 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4889 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4890 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4891 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4892 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4893 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4894 | final long identity = Binder.clearCallingIdentity(); |
| 4895 | try { |
| 4896 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4897 | int slotId = getSlotIndex(subId); |
| 4898 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4899 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4900 | + subId + "' for key:" + key); |
| 4901 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4902 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4903 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4904 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4905 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4906 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4907 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4908 | } finally { |
| 4909 | Binder.restoreCallingIdentity(identity); |
| 4910 | } |
| 4911 | } |
| 4912 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4913 | /** |
| 4914 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 4915 | * for the given slot ID or no ImsResolver instance has been created. |
| 4916 | * @param slotId The slot ID that the IMS service is created for. |
| 4917 | * @throws ImsException If there is no ImsService configured for this slot. |
| 4918 | */ |
| 4919 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 4920 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 4921 | ImsFeature.FEATURE_MMTEL)) { |
| 4922 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 4923 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4924 | } |
| 4925 | } |
| 4926 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4927 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4928 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4929 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4930 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4931 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4932 | } |
| 4933 | return slotId; |
| 4934 | } |
| 4935 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4936 | private int getSlotIndex(int subId) { |
| 4937 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4938 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4939 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4940 | } |
| 4941 | return slotId; |
| 4942 | } |
| 4943 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4944 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4945 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4946 | */ |
| 4947 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4948 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4949 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 4950 | try { |
| 4951 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4952 | } catch (SecurityException se) { |
| 4953 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 4954 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 4955 | + Binder.getCallingUid()); |
| 4956 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4957 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4958 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4959 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4960 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4961 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4962 | mApp, subId, callingPackage, callingFeatureId, |
| 4963 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4964 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4965 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4966 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4967 | final long identity = Binder.clearCallingIdentity(); |
| 4968 | try { |
| 4969 | final Phone phone = getPhone(subId); |
| 4970 | if (phone != null) { |
| 4971 | return phone.getServiceState().getDataNetworkType(); |
| 4972 | } else { |
| 4973 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4974 | } |
| 4975 | } finally { |
| 4976 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4977 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4978 | } |
| 4979 | |
| 4980 | /** |
| 4981 | * Returns the data network type |
| 4982 | */ |
| 4983 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4984 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 4985 | return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(), |
| 4986 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4987 | } |
| 4988 | |
| 4989 | /** |
| 4990 | * Returns the data network type for a subId |
| 4991 | */ |
| 4992 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4993 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4994 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 4995 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 4996 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 4997 | mApp, functionName)) { |
| 4998 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4999 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5000 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5001 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5002 | } |
| 5003 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5004 | final long identity = Binder.clearCallingIdentity(); |
| 5005 | try { |
| 5006 | final Phone phone = getPhone(subId); |
| 5007 | if (phone != null) { |
| 5008 | return phone.getServiceState().getDataNetworkType(); |
| 5009 | } else { |
| 5010 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5011 | } |
| 5012 | } finally { |
| 5013 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5014 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5015 | } |
| 5016 | |
| 5017 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5018 | * Returns the Voice network type for a subId |
| 5019 | */ |
| 5020 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5021 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5022 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5023 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5024 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5025 | mApp, functionName)) { |
| 5026 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5027 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5028 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5029 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5030 | } |
| 5031 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5032 | final long identity = Binder.clearCallingIdentity(); |
| 5033 | try { |
| 5034 | final Phone phone = getPhone(subId); |
| 5035 | if (phone != null) { |
| 5036 | return phone.getServiceState().getVoiceNetworkType(); |
| 5037 | } else { |
| 5038 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5039 | } |
| 5040 | } finally { |
| 5041 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5042 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5043 | } |
| 5044 | |
| 5045 | /** |
| 5046 | * @return true if a ICC card is present |
| 5047 | */ |
| 5048 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5049 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5050 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 5051 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5052 | } |
| 5053 | |
| 5054 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5055 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5056 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5057 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5058 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5059 | final long identity = Binder.clearCallingIdentity(); |
| 5060 | try { |
| 5061 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5062 | if (phone != null) { |
| 5063 | return phone.getIccCard().hasIccCard(); |
| 5064 | } else { |
| 5065 | return false; |
| 5066 | } |
| 5067 | } finally { |
| 5068 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5069 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5070 | } |
| 5071 | |
| 5072 | /** |
| 5073 | * Return if the current radio is LTE on CDMA. This |
| 5074 | * is a tri-state return value as for a period of time |
| 5075 | * the mode may be unknown. |
| 5076 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5077 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5078 | * @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] | 5079 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5080 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5081 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5082 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5083 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5084 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5085 | } |
| 5086 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5087 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5088 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5089 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5090 | try { |
| 5091 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5092 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5093 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5094 | } |
| 5095 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5096 | final long identity = Binder.clearCallingIdentity(); |
| 5097 | try { |
| 5098 | final Phone phone = getPhone(subId); |
| 5099 | if (phone == null) { |
| 5100 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5101 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5102 | return TelephonyProperties.lte_on_cdma_device() |
| 5103 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5104 | } |
| 5105 | } finally { |
| 5106 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5107 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5108 | } |
| 5109 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5110 | /** |
| 5111 | * {@hide} |
| 5112 | * Returns Default subId, 0 in the case of single standby. |
| 5113 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5114 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5115 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5116 | } |
| 5117 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5118 | private int getSlotForDefaultSubscription() { |
| 5119 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 5120 | } |
| 5121 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5122 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5123 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5124 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5125 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5126 | private boolean isActiveSubscription(int subId) { |
| 5127 | return mSubscriptionController.isActiveSubId(subId); |
| 5128 | } |
| 5129 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5130 | /** |
| 5131 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5132 | */ |
| 5133 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5134 | final long identity = Binder.clearCallingIdentity(); |
| 5135 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5136 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5137 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5138 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5139 | } finally { |
| 5140 | Binder.restoreCallingIdentity(identity); |
| 5141 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5142 | } |
| 5143 | |
| 5144 | /** |
| 5145 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5146 | */ |
| 5147 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5148 | final long identity = Binder.clearCallingIdentity(); |
| 5149 | try { |
| 5150 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5151 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5152 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5153 | } finally { |
| 5154 | Binder.restoreCallingIdentity(identity); |
| 5155 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5156 | } |
| 5157 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5158 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5159 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5160 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5161 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5162 | |
Muralidhar Reddy | c4c6a69 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5163 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5164 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5165 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5166 | if (phoneId == -1) { |
Muralidhar Reddy | c4c6a69 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5167 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
| 5168 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5169 | } |
| 5170 | return PhoneFactory.getPhone(phoneId); |
| 5171 | } |
| 5172 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5173 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5174 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5175 | @NonNull IccLogicalChannelRequest request) { |
| 5176 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5177 | /*message=*/ "iccOpenLogicalChannel"); |
| 5178 | |
| 5179 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5180 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5181 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5182 | |
| 5183 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5184 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5185 | |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5186 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5187 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5188 | Phone phone; |
| 5189 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5190 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5191 | mApp, request.subId, message); |
| 5192 | phone = getPhoneFromSubId(request.subId); |
| 5193 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5194 | enforceModifyPermission(); |
| 5195 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5196 | } else { |
| 5197 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5198 | } |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5199 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5200 | } |
| 5201 | |
| 5202 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5203 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5204 | final long identity = Binder.clearCallingIdentity(); |
| 5205 | try { |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5206 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5207 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5208 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5209 | .getContext().getPackageManager()); |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5210 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5211 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5212 | loge("The calling package is not allowed to access ISD-R."); |
| 5213 | throw new SecurityException( |
| 5214 | "The calling package is not allowed to access ISD-R."); |
| 5215 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5216 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5217 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5218 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5219 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5220 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5221 | return response; |
| 5222 | } finally { |
| 5223 | Binder.restoreCallingIdentity(identity); |
| 5224 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5225 | } |
| 5226 | |
| 5227 | @Override |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5228 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5229 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5230 | /*message=*/"iccCloseLogicalChannel"); |
| 5231 | |
| 5232 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5233 | |
| 5234 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5235 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5236 | |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5237 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5238 | IccLogicalChannelRequest request) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5239 | final long identity = Binder.clearCallingIdentity(); |
| 5240 | try { |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5241 | if (request.channel < 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5242 | return false; |
| 5243 | } |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5244 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5245 | null /* workSource */); |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5246 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5247 | return success; |
| 5248 | } finally { |
| 5249 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5250 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5251 | } |
| 5252 | |
| 5253 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5254 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5255 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5256 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5257 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5258 | if (DBG) { |
| 5259 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5260 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5261 | + p3 + " data=" + data); |
| 5262 | } |
| 5263 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5264 | command, p1, p2, p3, data); |
| 5265 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5266 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5267 | @Override |
Muralidhar Reddy | c4c6a69 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5268 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
| 5269 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5270 | enforceModifyPermission(); |
| 5271 | if (DBG) { |
Muralidhar Reddy | c4c6a69 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5272 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5273 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5274 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5275 | } |
| 5276 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | c4c6a69 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5277 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5278 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5279 | } |
| 5280 | |
| 5281 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5282 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5283 | final long identity = Binder.clearCallingIdentity(); |
| 5284 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5285 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5286 | return ""; |
| 5287 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5288 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5289 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5290 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5291 | null /* workSource */); |
| 5292 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5293 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5294 | // Append the returned status code to the end of the response payload. |
| 5295 | String s = Integer.toHexString( |
| 5296 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5297 | if (response.payload != null) { |
| 5298 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5299 | } |
| 5300 | return s; |
| 5301 | } finally { |
| 5302 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5303 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5304 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5305 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5306 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5307 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5308 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5309 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5310 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5311 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5312 | if (DBG) { |
| 5313 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5314 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5315 | } |
| 5316 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5317 | cla, command, p1, p2, p3, data); |
| 5318 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5319 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5320 | @Override |
Muralidhar Reddy | c4c6a69 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5321 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
| 5322 | 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] | 5323 | enforceModifyPermission(); |
| 5324 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5325 | if (DBG) { |
Muralidhar Reddy | c4c6a69 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5326 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5327 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5328 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5329 | } |
| 5330 | |
| 5331 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | c4c6a69 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5332 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5333 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5334 | } |
| 5335 | |
| 5336 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5337 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5338 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5339 | final long identity = Binder.clearCallingIdentity(); |
| 5340 | try { |
| 5341 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5342 | && TextUtils.equals(ISDR_AID, data)) { |
| 5343 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5344 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5345 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5346 | if (bestComponent == null |
| 5347 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5348 | loge("The calling package is not allowed to select ISD-R."); |
| 5349 | throw new SecurityException( |
| 5350 | "The calling package is not allowed to select ISD-R."); |
| 5351 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5352 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5353 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5354 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5355 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5356 | null /* workSource */); |
| 5357 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5358 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5359 | // Append the returned status code to the end of the response payload. |
| 5360 | String s = Integer.toHexString( |
| 5361 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5362 | if (response.payload != null) { |
| 5363 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5364 | } |
| 5365 | return s; |
| 5366 | } finally { |
| 5367 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5368 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5369 | } |
| 5370 | |
| 5371 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5372 | 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] | 5373 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5374 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5375 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5376 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5377 | final long identity = Binder.clearCallingIdentity(); |
| 5378 | try { |
| 5379 | if (DBG) { |
| 5380 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5381 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5382 | } |
| 5383 | |
| 5384 | IccIoResult response = |
| 5385 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5386 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5387 | subId); |
| 5388 | |
| 5389 | if (DBG) { |
| 5390 | log("Exchange SIM_IO [R]" + response); |
| 5391 | } |
| 5392 | |
| 5393 | byte[] result = null; |
| 5394 | int length = 2; |
| 5395 | if (response.payload != null) { |
| 5396 | length = 2 + response.payload.length; |
| 5397 | result = new byte[length]; |
| 5398 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5399 | } else { |
| 5400 | result = new byte[length]; |
| 5401 | } |
| 5402 | |
| 5403 | result[length - 1] = (byte) response.sw2; |
| 5404 | result[length - 2] = (byte) response.sw1; |
| 5405 | return result; |
| 5406 | } finally { |
| 5407 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5408 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5409 | } |
| 5410 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5411 | /** |
| 5412 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5413 | * on a particular subscription |
| 5414 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5415 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5416 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5417 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5418 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5419 | return null; |
| 5420 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5421 | |
| 5422 | final long identity = Binder.clearCallingIdentity(); |
| 5423 | try { |
| 5424 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5425 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5426 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5427 | return null; |
| 5428 | } |
| 5429 | Object response = sendRequest( |
| 5430 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5431 | if (response instanceof String[]) { |
| 5432 | return (String[]) response; |
| 5433 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5434 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5435 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5436 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5437 | } finally { |
| 5438 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5439 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5440 | } |
| 5441 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5442 | /** |
| 5443 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5444 | * subscription. |
| 5445 | * |
| 5446 | * @param subId the id of the subscription. |
| 5447 | * @param appType the uicc app type, must be USIM or SIM. |
| 5448 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5449 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5450 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5451 | * @return number of fplmns that is successfully written to the SIM. |
| 5452 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5453 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5454 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5455 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5456 | mApp, subId, "setForbiddenPlmns"); |
| 5457 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5458 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5459 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5460 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5461 | } |
| 5462 | if (fplmns == null) { |
| 5463 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5464 | } |
| 5465 | for (String fplmn : fplmns) { |
| 5466 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5467 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5468 | } |
| 5469 | } |
| 5470 | final long identity = Binder.clearCallingIdentity(); |
| 5471 | try { |
| 5472 | Object response = sendRequest( |
| 5473 | CMD_SET_FORBIDDEN_PLMNS, |
| 5474 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5475 | subId); |
| 5476 | return (int) response; |
| 5477 | } finally { |
| 5478 | Binder.restoreCallingIdentity(identity); |
| 5479 | } |
| 5480 | } |
| 5481 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5482 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5483 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5484 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5485 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5486 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5487 | final long identity = Binder.clearCallingIdentity(); |
| 5488 | try { |
| 5489 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5490 | if (response.payload == null) { |
| 5491 | return ""; |
| 5492 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5493 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5494 | // Append the returned status code to the end of the response payload. |
| 5495 | String s = Integer.toHexString( |
| 5496 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5497 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5498 | return s; |
| 5499 | } finally { |
| 5500 | Binder.restoreCallingIdentity(identity); |
| 5501 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5502 | } |
| 5503 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5504 | /** |
| 5505 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5506 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5507 | * |
| 5508 | * @param itemID the ID of the item to read |
| 5509 | * @return the NV item as a String, or null on error. |
| 5510 | */ |
| 5511 | @Override |
| 5512 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5513 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5514 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5515 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5516 | |
| 5517 | final long identity = Binder.clearCallingIdentity(); |
| 5518 | try { |
| 5519 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5520 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5521 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5522 | return value; |
| 5523 | } finally { |
| 5524 | Binder.restoreCallingIdentity(identity); |
| 5525 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5526 | } |
| 5527 | |
| 5528 | /** |
| 5529 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5530 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5531 | * |
| 5532 | * @param itemID the ID of the item to read |
| 5533 | * @param itemValue the value to write, as a String |
| 5534 | * @return true on success; false on any failure |
| 5535 | */ |
| 5536 | @Override |
| 5537 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5538 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5539 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5540 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5541 | |
| 5542 | final long identity = Binder.clearCallingIdentity(); |
| 5543 | try { |
| 5544 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5545 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5546 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5547 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5548 | return success; |
| 5549 | } finally { |
| 5550 | Binder.restoreCallingIdentity(identity); |
| 5551 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5552 | } |
| 5553 | |
| 5554 | /** |
| 5555 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5556 | * Used for device configuration by some CDMA operators. |
| 5557 | * |
| 5558 | * @param preferredRoamingList byte array containing the new PRL |
| 5559 | * @return true on success; false on any failure |
| 5560 | */ |
| 5561 | @Override |
| 5562 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5563 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5564 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5565 | |
| 5566 | final long identity = Binder.clearCallingIdentity(); |
| 5567 | try { |
| 5568 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5569 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5570 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5571 | return success; |
| 5572 | } finally { |
| 5573 | Binder.restoreCallingIdentity(identity); |
| 5574 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5575 | } |
| 5576 | |
| 5577 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5578 | * 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] | 5579 | * Used for device configuration by some CDMA operators. |
| 5580 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5581 | * @param slotIndex - device slot. |
| 5582 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5583 | * @return true on success; false on any failure |
| 5584 | */ |
| 5585 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5586 | public boolean resetModemConfig(int slotIndex) { |
| 5587 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5588 | if (phone != null) { |
| 5589 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5590 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5591 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5592 | final long identity = Binder.clearCallingIdentity(); |
| 5593 | try { |
| 5594 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5595 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5596 | return success; |
| 5597 | } finally { |
| 5598 | Binder.restoreCallingIdentity(identity); |
| 5599 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5600 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5601 | return false; |
| 5602 | } |
| 5603 | |
| 5604 | /** |
| 5605 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5606 | * |
| 5607 | * @param slotIndex - device slot. |
| 5608 | * |
| 5609 | * @return true on success; false on any failure |
| 5610 | */ |
| 5611 | @Override |
| 5612 | public boolean rebootModem(int slotIndex) { |
| 5613 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5614 | if (phone != null) { |
| 5615 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5616 | mApp, phone.getSubId(), "rebootModem"); |
| 5617 | |
| 5618 | final long identity = Binder.clearCallingIdentity(); |
| 5619 | try { |
| 5620 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5621 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5622 | return success; |
| 5623 | } finally { |
| 5624 | Binder.restoreCallingIdentity(identity); |
| 5625 | } |
| 5626 | } |
| 5627 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5628 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5629 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5630 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5631 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5632 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5633 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5634 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5635 | return new String[0]; |
| 5636 | } |
| 5637 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5638 | final long identity = Binder.clearCallingIdentity(); |
| 5639 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5640 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5641 | } finally { |
| 5642 | Binder.restoreCallingIdentity(identity); |
| 5643 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5644 | } |
| 5645 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5646 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5647 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5648 | * {@link #disableIms(int)}. |
| 5649 | * @param slotIndex device slot. |
| 5650 | */ |
| 5651 | public void resetIms(int slotIndex) { |
| 5652 | enforceModifyPermission(); |
| 5653 | |
| 5654 | final long identity = Binder.clearCallingIdentity(); |
| 5655 | try { |
| 5656 | if (mImsResolver == null) { |
| 5657 | // may happen if the does not support IMS. |
| 5658 | return; |
| 5659 | } |
| 5660 | mImsResolver.disableIms(slotIndex); |
| 5661 | mImsResolver.enableIms(slotIndex); |
| 5662 | } finally { |
| 5663 | Binder.restoreCallingIdentity(identity); |
| 5664 | } |
| 5665 | } |
| 5666 | |
| 5667 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5668 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5669 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5670 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5671 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5672 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5673 | |
| 5674 | final long identity = Binder.clearCallingIdentity(); |
| 5675 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5676 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5677 | // may happen if the device does not support IMS. |
| 5678 | return; |
| 5679 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5680 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5681 | } finally { |
| 5682 | Binder.restoreCallingIdentity(identity); |
| 5683 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5684 | } |
| 5685 | |
| 5686 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5687 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5688 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5689 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5690 | public void disableIms(int slotId) { |
| 5691 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5692 | |
| 5693 | final long identity = Binder.clearCallingIdentity(); |
| 5694 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5695 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5696 | // may happen if the device does not support IMS. |
| 5697 | return; |
| 5698 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5699 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5700 | } finally { |
| 5701 | Binder.restoreCallingIdentity(identity); |
| 5702 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5703 | } |
| 5704 | |
| 5705 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5706 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5707 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5708 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5709 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5710 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5711 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5712 | |
| 5713 | final long identity = Binder.clearCallingIdentity(); |
| 5714 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5715 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5716 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5717 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5718 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5719 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5720 | } finally { |
| 5721 | Binder.restoreCallingIdentity(identity); |
| 5722 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5723 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5724 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5725 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5726 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5727 | @Override |
| 5728 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5729 | enforceModifyPermission(); |
| 5730 | |
| 5731 | final long identity = Binder.clearCallingIdentity(); |
| 5732 | try { |
| 5733 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5734 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5735 | } finally { |
| 5736 | Binder.restoreCallingIdentity(identity); |
| 5737 | } |
| 5738 | } |
| 5739 | |
| 5740 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5741 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5742 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5743 | */ |
| 5744 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5745 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5746 | |
| 5747 | final long identity = Binder.clearCallingIdentity(); |
| 5748 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5749 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5750 | // may happen if the device does not support IMS. |
| 5751 | return null; |
| 5752 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5753 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5754 | } finally { |
| 5755 | Binder.restoreCallingIdentity(identity); |
| 5756 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5757 | } |
| 5758 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5759 | /** |
| 5760 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5761 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5762 | */ |
| 5763 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5764 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5765 | |
| 5766 | final long identity = Binder.clearCallingIdentity(); |
| 5767 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5768 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5769 | // may happen if the device does not support IMS. |
| 5770 | return null; |
| 5771 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5772 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5773 | } finally { |
| 5774 | Binder.restoreCallingIdentity(identity); |
| 5775 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5776 | } |
| 5777 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5778 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5779 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5780 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5781 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5782 | * @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] | 5783 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5784 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5785 | * @param packageName The name of the package that the current configuration will be replaced |
| 5786 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5787 | * @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] | 5788 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5789 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5790 | int[] featureTypes, String packageName) { |
| 5791 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5792 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5793 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5794 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5795 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5796 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5797 | final long identity = Binder.clearCallingIdentity(); |
| 5798 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5799 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5800 | // may happen if the device does not support IMS. |
| 5801 | return false; |
| 5802 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5803 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5804 | for (int featureType : featureTypes) { |
| 5805 | featureConfig.put(featureType, packageName); |
| 5806 | } |
| 5807 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5808 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5809 | } finally { |
| 5810 | Binder.restoreCallingIdentity(identity); |
| 5811 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5812 | } |
| 5813 | |
| 5814 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5815 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5816 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5817 | * |
| 5818 | * This should only be used for testing. |
| 5819 | * |
| 5820 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5821 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5822 | */ |
| 5823 | @Override |
| 5824 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5825 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5826 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5827 | "clearCarrierImsServiceOverride"); |
| 5828 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5829 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5830 | "clearCarrierImsServiceOverride"); |
| 5831 | |
| 5832 | final long identity = Binder.clearCallingIdentity(); |
| 5833 | try { |
| 5834 | if (mImsResolver == null) { |
| 5835 | // may happen if the device does not support IMS. |
| 5836 | return false; |
| 5837 | } |
| 5838 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5839 | } finally { |
| 5840 | Binder.restoreCallingIdentity(identity); |
| 5841 | } |
| 5842 | } |
| 5843 | |
| 5844 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5845 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5846 | * |
| 5847 | * @param slotId The slot that the ImsService is associated with. |
| 5848 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5849 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5850 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5851 | * @return the package name of the ImsService configuration. |
| 5852 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5853 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5854 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5855 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5856 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5857 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5858 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5859 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5860 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5861 | final long identity = Binder.clearCallingIdentity(); |
| 5862 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5863 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5864 | // may happen if the device does not support IMS. |
| 5865 | return ""; |
| 5866 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5867 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5868 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5869 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5870 | } finally { |
| 5871 | Binder.restoreCallingIdentity(identity); |
| 5872 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5873 | } |
| 5874 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5875 | /** |
| 5876 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5877 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5878 | * @param callback A callback with an integer containing the |
| 5879 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5880 | */ |
| 5881 | @Override |
| 5882 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5883 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5884 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5885 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5886 | "IMS not available on device."); |
| 5887 | } |
| 5888 | final long token = Binder.clearCallingIdentity(); |
| 5889 | try { |
| 5890 | int slotId = getSlotIndex(subId); |
| 5891 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5892 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5893 | + subId + "'"); |
| 5894 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5895 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5896 | verifyImsMmTelConfiguredOrThrow(slotId); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5897 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5898 | try { |
| 5899 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5900 | } catch (RemoteException e) { |
| 5901 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5902 | + "Ignore"); |
| 5903 | } |
| 5904 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5905 | } catch (ImsException e) { |
| 5906 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5907 | } finally { |
| 5908 | Binder.restoreCallingIdentity(token); |
| 5909 | } |
| 5910 | } |
| 5911 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5912 | /** |
| 5913 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5914 | */ |
| 5915 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5916 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5917 | |
| 5918 | final long identity = Binder.clearCallingIdentity(); |
| 5919 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5920 | // NOTE: Before S, this method only set the default phone. |
| 5921 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5922 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5923 | phone.setImsRegistrationState(registered); |
| 5924 | } |
| 5925 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5926 | } finally { |
| 5927 | Binder.restoreCallingIdentity(identity); |
| 5928 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5929 | } |
| 5930 | |
| 5931 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5932 | * Set the network selection mode to automatic. |
| 5933 | * |
| 5934 | */ |
| 5935 | @Override |
| 5936 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5937 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5938 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5939 | |
| 5940 | final long identity = Binder.clearCallingIdentity(); |
| 5941 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5942 | if (!isActiveSubscription(subId)) { |
| 5943 | return; |
| 5944 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5945 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 5946 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 5947 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5948 | } finally { |
| 5949 | Binder.restoreCallingIdentity(identity); |
| 5950 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5951 | } |
| 5952 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5953 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5954 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5955 | * |
| 5956 | * @param subId the id of the subscription. |
| 5957 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5958 | * the operator to attach to. |
| 5959 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5960 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5961 | * normal network selection next time. |
| 5962 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5963 | */ |
| 5964 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5965 | public boolean setNetworkSelectionModeManual( |
| 5966 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5967 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5968 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5969 | |
| 5970 | if (!isActiveSubscription(subId)) { |
| 5971 | return false; |
| 5972 | } |
| 5973 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5974 | final long identity = Binder.clearCallingIdentity(); |
| 5975 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5976 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5977 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5978 | if (DBG) { |
| 5979 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5980 | + " operator: " + operatorInfo); |
| 5981 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5982 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5983 | } finally { |
| 5984 | Binder.restoreCallingIdentity(identity); |
| 5985 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5986 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5987 | /** |
| 5988 | * Get the manual network selection |
| 5989 | * |
| 5990 | * @param subId the id of the subscription. |
| 5991 | * |
| 5992 | * @return the previously saved user selected PLMN |
| 5993 | */ |
| 5994 | @Override |
| 5995 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5996 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5997 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5998 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5999 | |
| 6000 | final long identity = Binder.clearCallingIdentity(); |
| 6001 | try { |
| 6002 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6003 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6004 | } |
| 6005 | |
| 6006 | final Phone phone = getPhone(subId); |
| 6007 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6008 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6009 | } |
| 6010 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6011 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6012 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6013 | } finally { |
| 6014 | Binder.restoreCallingIdentity(identity); |
| 6015 | } |
| 6016 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6017 | |
| 6018 | /** |
| 6019 | * Scans for available networks. |
| 6020 | */ |
| 6021 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6022 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6023 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6024 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6025 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6026 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6027 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6028 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6029 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6030 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6031 | .setCallingPid(Binder.getCallingPid()) |
| 6032 | .setCallingUid(Binder.getCallingUid()) |
| 6033 | .setMethod("getCellNetworkScanResults") |
| 6034 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6035 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6036 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6037 | .build()); |
| 6038 | switch (locationResult) { |
| 6039 | case DENIED_HARD: |
| 6040 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6041 | case DENIED_SOFT: |
| 6042 | return null; |
| 6043 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6044 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6045 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6046 | try { |
| 6047 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6048 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6049 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6050 | } finally { |
| 6051 | Binder.restoreCallingIdentity(identity); |
| 6052 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6053 | } |
| 6054 | |
| 6055 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6056 | * Get the call forwarding info, given the call forwarding reason. |
| 6057 | */ |
| 6058 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6059 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6060 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6061 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6062 | long identity = Binder.clearCallingIdentity(); |
| 6063 | try { |
| 6064 | if (DBG) { |
| 6065 | log("getCallForwarding: subId " + subId |
| 6066 | + " callForwardingReason" + callForwardingReason); |
| 6067 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6068 | |
| 6069 | Phone phone = getPhone(subId); |
| 6070 | if (phone == null) { |
| 6071 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6072 | callback.onError( |
| 6073 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6074 | } catch (RemoteException e) { |
| 6075 | // ignore |
| 6076 | } |
| 6077 | return; |
| 6078 | } |
| 6079 | |
| 6080 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6081 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6082 | @Override |
| 6083 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6084 | try { |
| 6085 | callback.onCallForwardingInfoAvailable(info); |
| 6086 | } catch (RemoteException e) { |
| 6087 | // ignore |
| 6088 | } |
| 6089 | } |
| 6090 | |
| 6091 | @Override |
| 6092 | public void onError(int error) { |
| 6093 | try { |
| 6094 | callback.onError(error); |
| 6095 | } catch (RemoteException e) { |
| 6096 | // ignore |
| 6097 | } |
| 6098 | } |
| 6099 | }); |
| 6100 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6101 | } finally { |
| 6102 | Binder.restoreCallingIdentity(identity); |
| 6103 | } |
| 6104 | } |
| 6105 | |
| 6106 | /** |
| 6107 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6108 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6109 | */ |
| 6110 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6111 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6112 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6113 | enforceModifyPermission(); |
| 6114 | long identity = Binder.clearCallingIdentity(); |
| 6115 | try { |
| 6116 | if (DBG) { |
| 6117 | log("setCallForwarding: subId " + subId |
| 6118 | + " callForwardingInfo" + callForwardingInfo); |
| 6119 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6120 | |
| 6121 | Phone phone = getPhone(subId); |
| 6122 | if (phone == null) { |
| 6123 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6124 | callback.accept( |
| 6125 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6126 | } catch (RemoteException e) { |
| 6127 | // ignore |
| 6128 | } |
| 6129 | return; |
| 6130 | } |
| 6131 | |
| 6132 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6133 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6134 | |
| 6135 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6136 | } finally { |
| 6137 | Binder.restoreCallingIdentity(identity); |
| 6138 | } |
| 6139 | } |
| 6140 | |
| 6141 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6142 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6143 | */ |
| 6144 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6145 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6146 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6147 | long identity = Binder.clearCallingIdentity(); |
| 6148 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6149 | Phone phone = getPhone(subId); |
| 6150 | if (phone == null) { |
| 6151 | try { |
| 6152 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6153 | } catch (RemoteException e) { |
| 6154 | // ignore |
| 6155 | } |
| 6156 | return; |
| 6157 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6158 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6159 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6160 | boolean requireUssd = c.getBoolean( |
| 6161 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6162 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6163 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6164 | if (requireUssd) { |
| 6165 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6166 | getSubscriptionCarrierId(subId)); |
| 6167 | String newUssdCommand = ""; |
| 6168 | try { |
| 6169 | newUssdCommand = carrierXmlParser.getFeature( |
| 6170 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6171 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6172 | } catch (NullPointerException e) { |
| 6173 | loge("Failed to generate USSD number" + e); |
| 6174 | } |
| 6175 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6176 | mMainThreadHandler, callback, carrierXmlParser, |
| 6177 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6178 | final String ussdCommand = newUssdCommand; |
| 6179 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6180 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6181 | }); |
| 6182 | } else { |
| 6183 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6184 | callback::accept); |
| 6185 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6186 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6187 | } finally { |
| 6188 | Binder.restoreCallingIdentity(identity); |
| 6189 | } |
| 6190 | } |
| 6191 | |
| 6192 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6193 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6194 | */ |
| 6195 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6196 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6197 | enforceModifyPermission(); |
| 6198 | long identity = Binder.clearCallingIdentity(); |
| 6199 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6200 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6201 | |
| 6202 | Phone phone = getPhone(subId); |
| 6203 | if (phone == null) { |
| 6204 | try { |
| 6205 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6206 | } catch (RemoteException e) { |
| 6207 | // ignore |
| 6208 | } |
| 6209 | return; |
| 6210 | } |
| 6211 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6212 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6213 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6214 | boolean requireUssd = c.getBoolean( |
| 6215 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6216 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6217 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6218 | if (requireUssd) { |
| 6219 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6220 | getSubscriptionCarrierId(subId)); |
| 6221 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6222 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6223 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6224 | String newUssdCommand = ""; |
| 6225 | try { |
| 6226 | newUssdCommand = carrierXmlParser.getFeature( |
| 6227 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6228 | .makeCommand(ssAction, null); |
| 6229 | } catch (NullPointerException e) { |
| 6230 | loge("Failed to generate USSD number" + e); |
| 6231 | } |
| 6232 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6233 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6234 | final String ussdCommand = newUssdCommand; |
| 6235 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6236 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6237 | }); |
| 6238 | } else { |
| 6239 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6240 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6241 | |
| 6242 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6243 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6244 | } finally { |
| 6245 | Binder.restoreCallingIdentity(identity); |
| 6246 | } |
| 6247 | } |
| 6248 | |
| 6249 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6250 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6251 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6252 | * @param subId id of the subscription |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6253 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6254 | * location related information which will be sent if the caller already possess |
| 6255 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6256 | * @param request contains the radio access networks with bands/channels to scan |
| 6257 | * @param messenger callback messenger for scan results or errors |
| 6258 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6259 | * @return the id of the requested scan which can be used to stop the scan. |
| 6260 | */ |
| 6261 | @Override |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6262 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6263 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6264 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6265 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6266 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6267 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6268 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6269 | if (!renounceFineLocationAccess) { |
| 6270 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
| 6271 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6272 | .setCallingPackage(callingPackage) |
| 6273 | .setCallingFeatureId(callingFeatureId) |
| 6274 | .setCallingPid(Binder.getCallingPid()) |
| 6275 | .setCallingUid(Binder.getCallingUid()) |
| 6276 | .setMethod("requestNetworkScan") |
| 6277 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6278 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6279 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6280 | .build()); |
| 6281 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6282 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6283 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6284 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6285 | if (e != null) { |
| 6286 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6287 | throw e; |
| 6288 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6289 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6290 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6291 | } |
| 6292 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6293 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6294 | int callingUid = Binder.getCallingUid(); |
| 6295 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6296 | final long identity = Binder.clearCallingIdentity(); |
| 6297 | try { |
| 6298 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6299 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6300 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6301 | } finally { |
| 6302 | Binder.restoreCallingIdentity(identity); |
| 6303 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6304 | } |
| 6305 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6306 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6307 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6308 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6309 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6310 | boolean hasNetworkScanPermission = |
| 6311 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6312 | == PERMISSION_GRANTED; |
| 6313 | |
| 6314 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6315 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6316 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6317 | } |
| 6318 | |
| 6319 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6320 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6321 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6322 | return new SecurityException("Specific channels must not be" |
| 6323 | + " scanned without location access."); |
| 6324 | } |
| 6325 | } |
| 6326 | } |
| 6327 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6328 | return null; |
| 6329 | } |
| 6330 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6331 | /** |
| 6332 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6333 | * |
| 6334 | * @param subId id of the subscription |
| 6335 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6336 | */ |
| 6337 | @Override |
| 6338 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6339 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6340 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6341 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6342 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6343 | final long identity = Binder.clearCallingIdentity(); |
| 6344 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6345 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6346 | } finally { |
| 6347 | Binder.restoreCallingIdentity(identity); |
| 6348 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6349 | } |
| 6350 | |
| 6351 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6352 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6353 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6354 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6355 | */ |
| 6356 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6357 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6358 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6359 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6360 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6361 | |
| 6362 | final long identity = Binder.clearCallingIdentity(); |
| 6363 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6364 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6365 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6366 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6367 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6368 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6369 | } finally { |
| 6370 | Binder.restoreCallingIdentity(identity); |
| 6371 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6372 | } |
| 6373 | |
| 6374 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6375 | * Get the allowed network types for certain reason. |
| 6376 | * |
| 6377 | * @param subId the id of the subscription. |
| 6378 | * @param reason the reason the allowed network type change is taking place |
| 6379 | * @return the allowed network types. |
| 6380 | */ |
| 6381 | @Override |
| 6382 | public long getAllowedNetworkTypesForReason(int subId, |
| 6383 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6384 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6385 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6386 | final long identity = Binder.clearCallingIdentity(); |
| 6387 | try { |
| 6388 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6389 | } finally { |
| 6390 | Binder.restoreCallingIdentity(identity); |
| 6391 | } |
| 6392 | } |
| 6393 | |
| 6394 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6395 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6396 | * @param subId subscription id of the sim card |
| 6397 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6398 | * This can be passed following states |
| 6399 | * <ol> |
| 6400 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6401 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6402 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6403 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6404 | * </ol> |
| 6405 | * @return operation result. |
| 6406 | */ |
| 6407 | @Override |
| 6408 | public int setNrDualConnectivityState(int subId, |
| 6409 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6410 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6411 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6412 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6413 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6414 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6415 | } |
| 6416 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6417 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6418 | final long identity = Binder.clearCallingIdentity(); |
| 6419 | try { |
| 6420 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6421 | nrDualConnectivityState, subId, |
| 6422 | workSource); |
| 6423 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6424 | return result; |
| 6425 | } finally { |
| 6426 | Binder.restoreCallingIdentity(identity); |
| 6427 | } |
| 6428 | } |
| 6429 | |
| 6430 | /** |
| 6431 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6432 | * @return true if dual connectivity is enabled else false |
| 6433 | */ |
| 6434 | @Override |
| 6435 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6436 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6437 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6438 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6439 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6440 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6441 | return false; |
| 6442 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6443 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6444 | final long identity = Binder.clearCallingIdentity(); |
| 6445 | try { |
| 6446 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6447 | null, subId, workSource); |
| 6448 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6449 | return isEnabled; |
| 6450 | } finally { |
| 6451 | Binder.restoreCallingIdentity(identity); |
| 6452 | } |
| 6453 | } |
| 6454 | |
| 6455 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6456 | * Set the allowed network types of the device and |
| 6457 | * provide the reason triggering the allowed network change. |
| 6458 | * |
| 6459 | * @param subId the id of the subscription. |
| 6460 | * @param reason the reason the allowed network type change is taking place |
| 6461 | * @param allowedNetworkTypes the allowed network types. |
| 6462 | * @return true on success; false on any failure. |
| 6463 | */ |
| 6464 | @Override |
| 6465 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6466 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6467 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6468 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6469 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6470 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6471 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6472 | return false; |
| 6473 | } |
| 6474 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6475 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6476 | return false; |
| 6477 | } |
| 6478 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6479 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6480 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6481 | |
| 6482 | |
| 6483 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6484 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6485 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6486 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6487 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6488 | final long identity = Binder.clearCallingIdentity(); |
| 6489 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6490 | Boolean success = (Boolean) sendRequest( |
| 6491 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6492 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6493 | |
| 6494 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6495 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6496 | } finally { |
| 6497 | Binder.restoreCallingIdentity(identity); |
| 6498 | } |
| 6499 | } |
| 6500 | |
| 6501 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6502 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6503 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6504 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6505 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6506 | * @hide |
| 6507 | */ |
| 6508 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6509 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6510 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6511 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6512 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6513 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6514 | if (phone != null) { |
| 6515 | return phone.hasMatchedTetherApnSetting(); |
| 6516 | } else { |
| 6517 | return false; |
| 6518 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6519 | } finally { |
| 6520 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6521 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6522 | } |
| 6523 | |
| 6524 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6525 | * Get the user enabled state of Mobile Data. |
| 6526 | * |
| 6527 | * TODO: remove and use isUserDataEnabled. |
| 6528 | * This can't be removed now because some vendor codes |
| 6529 | * calls through ITelephony directly while they should |
| 6530 | * use TelephonyManager. |
| 6531 | * |
| 6532 | * @return true on enabled |
| 6533 | */ |
| 6534 | @Override |
| 6535 | public boolean getDataEnabled(int subId) { |
| 6536 | return isUserDataEnabled(subId); |
| 6537 | } |
| 6538 | |
| 6539 | /** |
| 6540 | * Get whether mobile data is enabled per user setting. |
| 6541 | * |
| 6542 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6543 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6544 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6545 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6546 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6547 | * |
| 6548 | * @return {@code true} if data is enabled else {@code false} |
| 6549 | */ |
| 6550 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6551 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6552 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6553 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6554 | try { |
| 6555 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6556 | functionName); |
| 6557 | } catch (Exception e) { |
| 6558 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6559 | } |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6560 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6561 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6562 | mApp, subId, functionName); |
| 6563 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6564 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6565 | |
| 6566 | final long identity = Binder.clearCallingIdentity(); |
| 6567 | try { |
| 6568 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6569 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6570 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6571 | if (phone != null) { |
| 6572 | boolean retVal = phone.isUserDataEnabled(); |
| 6573 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6574 | return retVal; |
| 6575 | } else { |
| 6576 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6577 | return false; |
| 6578 | } |
| 6579 | } finally { |
| 6580 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6581 | } |
| 6582 | } |
| 6583 | |
| 6584 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6585 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6586 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6587 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6588 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6589 | * @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] | 6590 | */ |
| 6591 | @Override |
| 6592 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6593 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6594 | try { |
| 6595 | try { |
| 6596 | mApp.enforceCallingOrSelfPermission( |
| 6597 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6598 | functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6599 | } catch (Exception e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6600 | try { |
| 6601 | mApp.enforceCallingOrSelfPermission( |
| 6602 | android.Manifest.permission.READ_PHONE_STATE, |
| 6603 | functionName); |
| 6604 | } catch (Exception e2) { |
| 6605 | mApp.enforceCallingOrSelfPermission( |
| 6606 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6607 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6608 | } |
| 6609 | } catch (Exception e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6610 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6611 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6612 | |
| 6613 | final long identity = Binder.clearCallingIdentity(); |
| 6614 | try { |
| 6615 | int phoneId = mSubscriptionController.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6616 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6617 | if (phone != null) { |
Jack Yu | 3fb3a6b | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6618 | boolean retVal; |
| 6619 | if (phone.isUsingNewDataStack()) { |
Sarah Chin | 8619e16 | 2022-03-09 13:57:52 -0800 | [diff] [blame] | 6620 | retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 3fb3a6b | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6621 | } else { |
| 6622 | retVal = phone.getDataEnabledSettings().isDataEnabled(); |
| 6623 | } |
| 6624 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6625 | return retVal; |
| 6626 | } else { |
| 6627 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6628 | return false; |
| 6629 | } |
| 6630 | } finally { |
| 6631 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6632 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6633 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6634 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6635 | /** |
| 6636 | * Check if data is enabled for a specific reason |
| 6637 | * @param subId Subscription index |
| 6638 | * @param reason the reason the data enable change is taking place |
| 6639 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6640 | */ |
| 6641 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6642 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6643 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6644 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6645 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6646 | try { |
| 6647 | mApp.enforceCallingOrSelfPermission( |
| 6648 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6649 | functionName); |
| 6650 | } catch (Exception e) { |
| 6651 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6652 | functionName); |
| 6653 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6654 | } catch (Exception e) { |
Sooraj Sasindran | 72a2276 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6655 | try { |
| 6656 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6657 | functionName); |
Sooraj Sasindran | 72a2276 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6658 | } catch (Exception e2) { |
| 6659 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6660 | mApp, subId, functionName); |
Sooraj Sasindran | 72a2276 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6661 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6662 | } |
| 6663 | |
| 6664 | |
| 6665 | final long identity = Binder.clearCallingIdentity(); |
| 6666 | try { |
| 6667 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6668 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6669 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6670 | + " reason=" + reason); |
| 6671 | } |
| 6672 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6673 | if (phone != null) { |
| 6674 | boolean retVal; |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 6675 | if (phone.isUsingNewDataStack()) { |
| 6676 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6677 | } else { |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 6678 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6679 | retVal = phone.isUserDataEnabled(); |
| 6680 | } else { |
| 6681 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
| 6682 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6683 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6684 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6685 | return retVal; |
| 6686 | } else { |
| 6687 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6688 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6689 | + subId + " retVal=false"); |
| 6690 | } |
| 6691 | return false; |
| 6692 | } |
| 6693 | } finally { |
| 6694 | Binder.restoreCallingIdentity(identity); |
| 6695 | } |
| 6696 | } |
| 6697 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6698 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6699 | Phone phone) { |
Sarah Chin | 3394efe | 2021-04-09 10:37:15 -0700 | [diff] [blame] | 6700 | if (uid == Process.PHONE_UID) { |
| 6701 | // Skip the check if it's the phone UID (system UID removed in b/184713596) |
| 6702 | // TODO (b/184954344): Check for system/phone UID at call site instead of here |
Hall Liu | 54a2a0c | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6703 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6704 | } |
| 6705 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6706 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6707 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6708 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6709 | || subController == null) return privilegeFromSim; |
| 6710 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6711 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6712 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6713 | |
| 6714 | final long identity = Binder.clearCallingIdentity(); |
| 6715 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6716 | int subId = phone.getSubId(); |
| 6717 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6718 | // A test override is in place for the privileges for this subId, so don't try to |
| 6719 | // read the subscription privileges. |
| 6720 | return privilegeFromSim; |
| 6721 | } |
| 6722 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6723 | SubscriptionManager subManager = (SubscriptionManager) |
| 6724 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6725 | for (String pkg : packages) { |
| 6726 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6727 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6728 | } |
| 6729 | } |
| 6730 | return privilegeFromSim; |
| 6731 | } finally { |
| 6732 | Binder.restoreCallingIdentity(identity); |
| 6733 | } |
| 6734 | } |
| 6735 | |
| 6736 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6737 | String pkgName) { |
| 6738 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6739 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6740 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6741 | || subController == null) return privilegeFromSim; |
| 6742 | |
| 6743 | final long identity = Binder.clearCallingIdentity(); |
| 6744 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6745 | int subId = phone.getSubId(); |
| 6746 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6747 | // A test override is in place for the privileges for this subId, so don't try to |
| 6748 | // read the subscription privileges. |
| 6749 | return privilegeFromSim; |
| 6750 | } |
| 6751 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6752 | SubscriptionManager subManager = (SubscriptionManager) |
| 6753 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6754 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6755 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6756 | } finally { |
| 6757 | Binder.restoreCallingIdentity(identity); |
| 6758 | } |
| 6759 | } |
| 6760 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6761 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6762 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6763 | // No permission needed; this only lets the caller inspect their own status. |
| 6764 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6765 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6766 | |
| 6767 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6768 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6769 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6770 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 6771 | } |
| 6772 | |
| 6773 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 6774 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6775 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6776 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6777 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6778 | } |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6779 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6780 | if (cpt == null) { |
| 6781 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6782 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6783 | } |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6784 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6785 | } |
| 6786 | |
| 6787 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6788 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6789 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6790 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6791 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6792 | } |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6793 | Phone phone = getPhone(subId); |
| 6794 | if (phone == null) { |
| 6795 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 6796 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6797 | } |
| 6798 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6799 | if (cpt == null) { |
| 6800 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6801 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6802 | } |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6803 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6804 | } |
| 6805 | |
| 6806 | @Override |
| 6807 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6808 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
| 6809 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6810 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6811 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6812 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6813 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 6814 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6815 | if (phone == null) { |
| 6816 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6817 | } |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6818 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6819 | if (cpt == null) { |
| 6820 | continue; |
| 6821 | } |
| 6822 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6823 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6824 | break; |
| 6825 | } |
| 6826 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6827 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6828 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6829 | |
| 6830 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6831 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6832 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Hunter Knepshield | b0eb479 | 2021-12-14 18:49:15 -0800 | [diff] [blame^] | 6833 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6834 | if (phone == null) { |
| 6835 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6836 | } |
Hunter Knepshield | b0eb479 | 2021-12-14 18:49:15 -0800 | [diff] [blame^] | 6837 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6838 | if (cpt == null) { |
| 6839 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6840 | } |
Hunter Knepshield | b0eb479 | 2021-12-14 18:49:15 -0800 | [diff] [blame^] | 6841 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6842 | } |
| 6843 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6844 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6845 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6846 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6847 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6848 | if (phone == null) { |
| 6849 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6850 | } |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6851 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6852 | if (cpt == null) { |
| 6853 | return Collections.emptyList(); |
| 6854 | } |
| 6855 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6856 | } |
| 6857 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6858 | @Override |
| 6859 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6860 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6861 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6862 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6863 | try { |
| 6864 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6865 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6866 | } |
| 6867 | } finally { |
| 6868 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6869 | } |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6870 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6871 | } |
| 6872 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6873 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6874 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6875 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 6876 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6877 | return null; |
| 6878 | } |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6879 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6880 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6881 | return null; |
| 6882 | } |
| 6883 | return iccId; |
| 6884 | } |
| 6885 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6886 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6887 | public void setCallComposerStatus(int subId, int status) { |
| 6888 | enforceModifyPermission(); |
| 6889 | |
| 6890 | final long identity = Binder.clearCallingIdentity(); |
| 6891 | try { |
| 6892 | Phone phone = getPhone(subId); |
| 6893 | if (phone != null) { |
| 6894 | Phone defaultPhone = phone.getImsPhone(); |
| 6895 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6896 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6897 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6898 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6899 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6900 | } |
| 6901 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6902 | } catch (ImsException e) { |
| 6903 | throw new ServiceSpecificException(e.getCode()); |
| 6904 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6905 | Binder.restoreCallingIdentity(identity); |
| 6906 | } |
| 6907 | } |
| 6908 | |
| 6909 | @Override |
| 6910 | public int getCallComposerStatus(int subId) { |
| 6911 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6912 | |
| 6913 | final long identity = Binder.clearCallingIdentity(); |
| 6914 | try { |
| 6915 | Phone phone = getPhone(subId); |
| 6916 | if (phone != null) { |
| 6917 | Phone defaultPhone = phone.getImsPhone(); |
| 6918 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6919 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6920 | return imsPhone.getCallComposerStatus(); |
| 6921 | } |
| 6922 | } |
| 6923 | } finally { |
| 6924 | Binder.restoreCallingIdentity(identity); |
| 6925 | } |
| 6926 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6927 | } |
| 6928 | |
| 6929 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6930 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6931 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6932 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6933 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6934 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6935 | final long identity = Binder.clearCallingIdentity(); |
| 6936 | try { |
| 6937 | final String iccId = getIccId(subId); |
| 6938 | final Phone phone = getPhone(subId); |
| 6939 | if (phone == null) { |
| 6940 | return false; |
| 6941 | } |
| 6942 | final String subscriberId = phone.getSubscriberId(); |
| 6943 | |
| 6944 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6945 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6946 | + subscriberId + " to " + number); |
| 6947 | } |
| 6948 | |
| 6949 | if (TextUtils.isEmpty(iccId)) { |
| 6950 | return false; |
| 6951 | } |
| 6952 | |
| 6953 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6954 | |
| 6955 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6956 | if (alphaTag == null) { |
| 6957 | editor.remove(alphaTagPrefKey); |
| 6958 | } else { |
| 6959 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6960 | } |
| 6961 | |
| 6962 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6963 | // track all merged IMSIs based on line number |
| 6964 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6965 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6966 | if (number == null) { |
| 6967 | editor.remove(numberPrefKey); |
| 6968 | editor.remove(subscriberPrefKey); |
| 6969 | } else { |
| 6970 | editor.putString(numberPrefKey, number); |
| 6971 | editor.putString(subscriberPrefKey, subscriberId); |
| 6972 | } |
| 6973 | |
| 6974 | editor.commit(); |
| 6975 | return true; |
| 6976 | } finally { |
| 6977 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6978 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6979 | } |
| 6980 | |
| 6981 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6982 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6983 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6984 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6985 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6986 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6987 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6988 | return null; |
| 6989 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6990 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6991 | final long identity = Binder.clearCallingIdentity(); |
| 6992 | try { |
| 6993 | String iccId = getIccId(subId); |
| 6994 | if (iccId != null) { |
| 6995 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6996 | if (DBG_MERGE) { |
| 6997 | log("getLine1NumberForDisplay returning " |
| 6998 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6999 | } |
| 7000 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7001 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7002 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7003 | return null; |
| 7004 | } finally { |
| 7005 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7006 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7007 | } |
| 7008 | |
| 7009 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7010 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7011 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7012 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7013 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7014 | return null; |
| 7015 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7016 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7017 | final long identity = Binder.clearCallingIdentity(); |
| 7018 | try { |
| 7019 | String iccId = getIccId(subId); |
| 7020 | if (iccId != null) { |
| 7021 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7022 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7023 | } |
| 7024 | return null; |
| 7025 | } finally { |
| 7026 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7027 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7028 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7029 | |
| 7030 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7031 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7032 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7033 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7034 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7035 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7036 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7037 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7038 | return null; |
| 7039 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7040 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7041 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7042 | // the process, where TelephonyManager was instantiated. |
| 7043 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7044 | final long identity = Binder.clearCallingIdentity(); |
| 7045 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7046 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7047 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7048 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7049 | |
| 7050 | // Figure out what subscribers are currently active |
| 7051 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7052 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7053 | // Only consider subs which match the current subId |
| 7054 | // This logic can be simplified. See b/131189269 for progress. |
| 7055 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7056 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7057 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7058 | |
| 7059 | // First pass, find a number override for an active subscriber |
| 7060 | String mergeNumber = null; |
| 7061 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7062 | for (String key : prefs.keySet()) { |
| 7063 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7064 | final String subscriberId = (String) prefs.get(key); |
| 7065 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7066 | final String iccId = key.substring( |
| 7067 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7068 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7069 | mergeNumber = (String) prefs.get(numberKey); |
| 7070 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7071 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7072 | + " for active subscriber " + subscriberId); |
| 7073 | } |
| 7074 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7075 | break; |
| 7076 | } |
| 7077 | } |
| 7078 | } |
| 7079 | } |
| 7080 | |
| 7081 | // Shortcut when no active merged subscribers |
| 7082 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7083 | return null; |
| 7084 | } |
| 7085 | |
| 7086 | // Second pass, find all subscribers under that line override |
| 7087 | final ArraySet<String> result = new ArraySet<>(); |
| 7088 | for (String key : prefs.keySet()) { |
| 7089 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7090 | final String number = (String) prefs.get(key); |
| 7091 | if (mergeNumber.equals(number)) { |
| 7092 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7093 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7094 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7095 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7096 | result.add(subscriberId); |
| 7097 | } |
| 7098 | } |
| 7099 | } |
| 7100 | } |
| 7101 | |
| 7102 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7103 | Arrays.sort(resultArray); |
| 7104 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7105 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7106 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7107 | } |
| 7108 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7109 | } finally { |
| 7110 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7111 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7112 | } |
| 7113 | |
| 7114 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7115 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7116 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7117 | |
| 7118 | final long identity = Binder.clearCallingIdentity(); |
| 7119 | try { |
| 7120 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7121 | TelephonyManager.class); |
| 7122 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7123 | if (subscriberId == null) { |
| 7124 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7125 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7126 | + subId); |
| 7127 | } |
| 7128 | return null; |
| 7129 | } |
| 7130 | |
| 7131 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 7132 | .getSubscriptionInfo(subId); |
| 7133 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 7134 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7135 | if (groupUuid == null) { |
| 7136 | return new String[]{subscriberId}; |
| 7137 | } |
| 7138 | |
| 7139 | // Get all subscriberIds from the group. |
| 7140 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 7141 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7142 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7143 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7144 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7145 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7146 | if (subscriberId != null) { |
| 7147 | mergedSubscriberIds.add(subscriberId); |
| 7148 | } |
| 7149 | } |
| 7150 | |
| 7151 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7152 | } finally { |
| 7153 | Binder.restoreCallingIdentity(identity); |
| 7154 | |
| 7155 | } |
| 7156 | } |
| 7157 | |
| 7158 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7159 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7160 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7161 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7162 | |
| 7163 | final long identity = Binder.clearCallingIdentity(); |
| 7164 | try { |
| 7165 | final Phone phone = getPhone(subId); |
| 7166 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7167 | } finally { |
| 7168 | Binder.restoreCallingIdentity(identity); |
| 7169 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7170 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7171 | |
| 7172 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7173 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7174 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7175 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7176 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7177 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7178 | |
| 7179 | final long identity = Binder.clearCallingIdentity(); |
| 7180 | try { |
| 7181 | final Phone phone = getPhone(subId); |
| 7182 | if (phone == null) { |
| 7183 | return false; |
| 7184 | } |
| 7185 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7186 | cdmaNonRoamingList); |
| 7187 | } finally { |
| 7188 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7189 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7190 | } |
| 7191 | |
| 7192 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7193 | @Deprecated |
| 7194 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7195 | enforceModifyPermission(); |
| 7196 | |
| 7197 | int returnValue = 0; |
| 7198 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7199 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7200 | if(result.exception == null) { |
| 7201 | if (result.result != null) { |
| 7202 | byte[] responseData = (byte[])(result.result); |
| 7203 | if(responseData.length > oemResp.length) { |
| 7204 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7205 | responseData.length + "bytes. Buffer Size is " + |
| 7206 | oemResp.length + "bytes."); |
| 7207 | } |
| 7208 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7209 | returnValue = responseData.length; |
| 7210 | } |
| 7211 | } else { |
| 7212 | CommandException ex = (CommandException) result.exception; |
| 7213 | returnValue = ex.getCommandError().ordinal(); |
| 7214 | if(returnValue > 0) returnValue *= -1; |
| 7215 | } |
| 7216 | } catch (RuntimeException e) { |
| 7217 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7218 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7219 | if(returnValue > 0) returnValue *= -1; |
| 7220 | } |
| 7221 | |
| 7222 | return returnValue; |
| 7223 | } |
| 7224 | |
| 7225 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7226 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7227 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7228 | try { |
| 7229 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7230 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7231 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7232 | } catch (SecurityException e) { |
| 7233 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7234 | throw e; |
| 7235 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7236 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7237 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7238 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7239 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7240 | final long identity = Binder.clearCallingIdentity(); |
| 7241 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7242 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7243 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7244 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7245 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7246 | } finally { |
| 7247 | Binder.restoreCallingIdentity(identity); |
| 7248 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7249 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7250 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7251 | |
| 7252 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7253 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7254 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7255 | try { |
| 7256 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7257 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7258 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7259 | } |
| 7260 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7261 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7262 | } |
| 7263 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7264 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7265 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7266 | throw new SecurityException("App must be the dialer role holder to" |
| 7267 | + " upload a call composer pic"); |
| 7268 | } |
| 7269 | |
| 7270 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7271 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7272 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7273 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7274 | boolean readUntilEnd = false; |
| 7275 | int totalBytesRead = 0; |
| 7276 | byte[] buffer = new byte[16 * 1024]; |
| 7277 | while (true) { |
| 7278 | int numRead; |
| 7279 | try { |
| 7280 | numRead = input.read(buffer); |
| 7281 | } catch (IOException e) { |
| 7282 | try { |
| 7283 | fd.checkError(); |
| 7284 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7285 | null); |
| 7286 | } catch (IOException e1) { |
| 7287 | // This means that the other side closed explicitly with an error. If this |
| 7288 | // happens, log and ignore. |
| 7289 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7290 | } |
| 7291 | break; |
| 7292 | } |
| 7293 | if (numRead == -1) { |
| 7294 | readUntilEnd = true; |
| 7295 | break; |
| 7296 | } |
| 7297 | totalBytesRead += numRead; |
| 7298 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7299 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7300 | try { |
| 7301 | input.close(); |
| 7302 | } catch (IOException e) { |
| 7303 | // ignore |
| 7304 | } |
| 7305 | break; |
| 7306 | } |
| 7307 | output.write(buffer, 0, numRead); |
| 7308 | } |
| 7309 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7310 | // close is above, where the picture size is too big. |
| 7311 | |
| 7312 | try { |
| 7313 | fd.checkError(); |
| 7314 | } catch (IOException e) { |
| 7315 | loge("Remote end for call composer closed with an error: " + e); |
| 7316 | return; |
| 7317 | } |
| 7318 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7319 | if (!readUntilEnd) { |
| 7320 | loge("Did not finish reading entire image; aborting"); |
| 7321 | return; |
| 7322 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7323 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7324 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7325 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7326 | new CallComposerPictureTransfer.Factory() {}, |
| 7327 | imageData, |
| 7328 | (result) -> { |
| 7329 | if (result.first != null) { |
| 7330 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7331 | Bundle outputResult = new Bundle(); |
| 7332 | outputResult.putParcelable( |
| 7333 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7334 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7335 | outputResult); |
| 7336 | } else { |
| 7337 | callback.send(result.second, null); |
| 7338 | } |
| 7339 | } |
| 7340 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7341 | }); |
| 7342 | } |
| 7343 | |
| 7344 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7345 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7346 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7347 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7348 | |
| 7349 | final long identity = Binder.clearCallingIdentity(); |
| 7350 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7351 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7352 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7353 | } finally { |
| 7354 | Binder.restoreCallingIdentity(identity); |
| 7355 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7356 | } |
| 7357 | |
| 7358 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7359 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7360 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7361 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7362 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7363 | return false; |
| 7364 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7365 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7366 | final long identity = Binder.clearCallingIdentity(); |
| 7367 | try { |
| 7368 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7369 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7370 | // In the long run, we may instead need to check if there exists a connection service |
| 7371 | // which can support video calling. |
| 7372 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7373 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7374 | return imsManager.isVtEnabledByPlatform() |
| 7375 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7376 | && imsManager.isVtEnabledByUser(); |
| 7377 | } finally { |
| 7378 | Binder.restoreCallingIdentity(identity); |
| 7379 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7380 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7381 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7382 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7383 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7384 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7385 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7386 | mApp, subId, callingPackage, callingFeatureId, |
| 7387 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7388 | return false; |
| 7389 | } |
| 7390 | |
| 7391 | final long identity = Binder.clearCallingIdentity(); |
| 7392 | try { |
| 7393 | CarrierConfigManager configManager = |
| 7394 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7395 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7396 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7397 | } finally { |
| 7398 | Binder.restoreCallingIdentity(identity); |
| 7399 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7400 | } |
| 7401 | |
| 7402 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7403 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7404 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7405 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7406 | return false; |
| 7407 | } |
| 7408 | |
| 7409 | final long identity = Binder.clearCallingIdentity(); |
| 7410 | try { |
| 7411 | CarrierConfigManager configManager = |
| 7412 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7413 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7414 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7415 | } finally { |
| 7416 | Binder.restoreCallingIdentity(identity); |
| 7417 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7418 | } |
| 7419 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7420 | @Override |
| 7421 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7422 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7423 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7424 | } |
| 7425 | |
| 7426 | @Override |
| 7427 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7428 | final long identity = Binder.clearCallingIdentity(); |
| 7429 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7430 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7431 | } finally { |
| 7432 | Binder.restoreCallingIdentity(identity); |
| 7433 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7434 | } |
| 7435 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7436 | /** |
| 7437 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7438 | * support for the feature and device firmware support. |
| 7439 | * |
| 7440 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7441 | */ |
| 7442 | @Override |
| 7443 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7444 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7445 | final Phone phone = getPhone(subscriptionId); |
| 7446 | if (phone == null) { |
| 7447 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7448 | return false; |
| 7449 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7450 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7451 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7452 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7453 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7454 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7455 | return isCarrierSupported && isDeviceSupported; |
| 7456 | } finally { |
| 7457 | Binder.restoreCallingIdentity(identity); |
| 7458 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7459 | } |
| 7460 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7461 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7462 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7463 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7464 | * 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] | 7465 | */ |
| 7466 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7467 | final long identity = Binder.clearCallingIdentity(); |
| 7468 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7469 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7470 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7471 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7472 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7473 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7474 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7475 | } finally { |
| 7476 | Binder.restoreCallingIdentity(identity); |
| 7477 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7478 | } |
| 7479 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7480 | @Deprecated |
| 7481 | @Override |
| 7482 | public String getDeviceId(String callingPackage) { |
| 7483 | return getDeviceIdWithFeature(callingPackage, null); |
| 7484 | } |
| 7485 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7486 | /** |
| 7487 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7488 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7489 | * |
| 7490 | * <p>Requires Permission: |
| 7491 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7492 | */ |
| 7493 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7494 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7495 | try { |
| 7496 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7497 | } catch (SecurityException se) { |
| 7498 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7499 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7500 | + Binder.getCallingUid()); |
| 7501 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7502 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7503 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7504 | return null; |
| 7505 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7506 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7507 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7508 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7509 | return null; |
| 7510 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7511 | |
| 7512 | final long identity = Binder.clearCallingIdentity(); |
| 7513 | try { |
| 7514 | return phone.getDeviceId(); |
| 7515 | } finally { |
| 7516 | Binder.restoreCallingIdentity(identity); |
| 7517 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7518 | } |
| 7519 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7520 | /** |
| 7521 | * {@hide} |
| 7522 | * Returns the IMS Registration Status on a particular subid |
| 7523 | * |
| 7524 | * @param subId |
| 7525 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7526 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7527 | Phone phone = getPhone(subId); |
| 7528 | if (phone != null) { |
| 7529 | return phone.isImsRegistered(); |
| 7530 | } else { |
| 7531 | return false; |
| 7532 | } |
| 7533 | } |
| 7534 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7535 | @Override |
| 7536 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7537 | final long identity = Binder.clearCallingIdentity(); |
| 7538 | try { |
| 7539 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7540 | } finally { |
| 7541 | Binder.restoreCallingIdentity(identity); |
| 7542 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7543 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7544 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7545 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7546 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7547 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7548 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7549 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7550 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7551 | } |
| 7552 | final long identity = Binder.clearCallingIdentity(); |
| 7553 | try { |
| 7554 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7555 | } finally { |
| 7556 | Binder.restoreCallingIdentity(identity); |
| 7557 | } |
| 7558 | } |
| 7559 | |
| 7560 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7561 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7562 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7563 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7564 | mApp, |
| 7565 | subscriptionId, |
| 7566 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7567 | final long identity = Binder.clearCallingIdentity(); |
| 7568 | try { |
| 7569 | Phone phone = getPhone(subscriptionId); |
| 7570 | if (phone == null) { |
| 7571 | return null; |
| 7572 | } |
| 7573 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7574 | } finally { |
| 7575 | Binder.restoreCallingIdentity(identity); |
| 7576 | } |
| 7577 | } |
| 7578 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7579 | /** |
| 7580 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7581 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7582 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7583 | final long identity = Binder.clearCallingIdentity(); |
| 7584 | try { |
| 7585 | Phone phone = getPhone(subId); |
| 7586 | if (phone != null) { |
| 7587 | return phone.isWifiCallingEnabled(); |
| 7588 | } else { |
| 7589 | return false; |
| 7590 | } |
| 7591 | } finally { |
| 7592 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7593 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7594 | } |
| 7595 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7596 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7597 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7598 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7599 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7600 | final long identity = Binder.clearCallingIdentity(); |
| 7601 | try { |
| 7602 | Phone phone = getPhone(subId); |
| 7603 | if (phone != null) { |
| 7604 | return phone.isVideoEnabled(); |
| 7605 | } else { |
| 7606 | return false; |
| 7607 | } |
| 7608 | } finally { |
| 7609 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7610 | } |
| 7611 | } |
| 7612 | |
| 7613 | /** |
| 7614 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7615 | * defined in {@link ImsRegistrationImplBase}. |
| 7616 | */ |
| 7617 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7618 | final long identity = Binder.clearCallingIdentity(); |
| 7619 | try { |
| 7620 | Phone phone = getPhone(subId); |
| 7621 | if (phone != null) { |
| 7622 | return phone.getImsRegistrationTech(); |
| 7623 | } else { |
| 7624 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7625 | } |
| 7626 | } finally { |
| 7627 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7628 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7629 | } |
| 7630 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7631 | @Override |
| 7632 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7633 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7634 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7635 | return; |
| 7636 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7637 | Phone defaultPhone = getDefaultPhone(); |
| 7638 | if (defaultPhone != null) { |
| 7639 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7640 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7641 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7642 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7643 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7644 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7645 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7646 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7647 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7648 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7649 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7650 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7651 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7652 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7653 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7654 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7655 | // There has been issues when Sms raw table somehow stores orphan |
| 7656 | // fragments. They lead to garbled message when new fragments come |
| 7657 | // in and combined with those stale ones. In case this happens again, |
| 7658 | // user can reset all network settings which will clean up this table. |
| 7659 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7660 | // Clean up IMS settings as well here. |
| 7661 | int slotId = getSlotIndex(subId); |
| 7662 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7663 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7664 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7665 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7666 | if (defaultPhone == null) { |
| 7667 | return; |
| 7668 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7669 | // Erase modem config if erase modem on network setting is enabled. |
| 7670 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7671 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7672 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7673 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7674 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7675 | |
| 7676 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7677 | } finally { |
| 7678 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7679 | } |
| 7680 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7681 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7682 | @VisibleForTesting |
| 7683 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7684 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7685 | return; |
| 7686 | } |
| 7687 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7688 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7689 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7690 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7691 | "user=" + defaultNetworkType); |
| 7692 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7693 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7694 | defaultNetworkType, null); |
| 7695 | } |
| 7696 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7697 | private void cleanUpSmsRawTable(Context context) { |
| 7698 | ContentResolver resolver = context.getContentResolver(); |
| 7699 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7700 | resolver.delete(uri, null, null); |
| 7701 | } |
| 7702 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7703 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7704 | public String getSimLocaleForSubscriber(int subId) { |
| 7705 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7706 | final Phone phone = getPhone(subId); |
| 7707 | if (phone == null) { |
| 7708 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7709 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7710 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7711 | final long identity = Binder.clearCallingIdentity(); |
| 7712 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7713 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7714 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7715 | if (info == null) { |
| 7716 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7717 | return null; |
| 7718 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7719 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7720 | // preferences (EF-PL and EF-LI)... |
| 7721 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7722 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7723 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7724 | if (localeFromDefaultSim != null) { |
| 7725 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7726 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7727 | + localeFromDefaultSim); |
| 7728 | return localeFromDefaultSim.toLanguageTag(); |
| 7729 | } else { |
| 7730 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7731 | } |
| 7732 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7733 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7734 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7735 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7736 | // the SIM and carrier preferences does not include a country we add the country |
| 7737 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7738 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7739 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7740 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7741 | return mccLocale.toLanguageTag(); |
| 7742 | } |
| 7743 | |
| 7744 | if (DBG) log("No locale found - returning null"); |
| 7745 | return null; |
| 7746 | } finally { |
| 7747 | Binder.restoreCallingIdentity(identity); |
| 7748 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7749 | } |
| 7750 | |
| 7751 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7752 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7753 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7754 | } |
| 7755 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7756 | /** |
| 7757 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7758 | */ |
| 7759 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7760 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7761 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7762 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7763 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7764 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7765 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7766 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7767 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7768 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7769 | * representing the state of the modem. |
| 7770 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7771 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7772 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7773 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7774 | */ |
| 7775 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7776 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7777 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7778 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7779 | |
| 7780 | final long identity = Binder.clearCallingIdentity(); |
| 7781 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7782 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7783 | } finally { |
| 7784 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7785 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7786 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7787 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7788 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7789 | // less than total activity duration. |
| 7790 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7791 | if (info == null) { |
| 7792 | return false; |
| 7793 | } |
| 7794 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7795 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7796 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7797 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7798 | return (info.isValid() |
| 7799 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7800 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7801 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7802 | && (totalTxTimeMs <= activityDurationMs)); |
| 7803 | } |
| 7804 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7805 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7806 | * Returns the service state information on specified subscription. |
| 7807 | */ |
| 7808 | @Override |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7809 | public ServiceState getServiceStateForSubscriber(int subId, |
| 7810 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 7811 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7812 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7813 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7814 | return null; |
| 7815 | } |
| 7816 | |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7817 | boolean hasFinePermission = false; |
| 7818 | boolean hasCoarsePermission = false; |
| 7819 | if (!renounceFineLocationAccess) { |
| 7820 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7821 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7822 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7823 | .setCallingPackage(callingPackage) |
| 7824 | .setCallingFeatureId(callingFeatureId) |
| 7825 | .setCallingPid(Binder.getCallingPid()) |
| 7826 | .setCallingUid(Binder.getCallingUid()) |
| 7827 | .setMethod("getServiceStateForSubscriber") |
| 7828 | .setLogAsInfo(true) |
| 7829 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7830 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7831 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7832 | .build()); |
| 7833 | hasFinePermission = |
| 7834 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7835 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7836 | |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7837 | if (!renounceCoarseLocationAccess) { |
| 7838 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7839 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7840 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7841 | .setCallingPackage(callingPackage) |
| 7842 | .setCallingFeatureId(callingFeatureId) |
| 7843 | .setCallingPid(Binder.getCallingPid()) |
| 7844 | .setCallingUid(Binder.getCallingUid()) |
| 7845 | .setMethod("getServiceStateForSubscriber") |
| 7846 | .setLogAsInfo(true) |
| 7847 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7848 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7849 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7850 | .build()); |
| 7851 | hasCoarsePermission = |
| 7852 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7853 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7854 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7855 | final Phone phone = getPhone(subId); |
| 7856 | if (phone == null) { |
| 7857 | return null; |
| 7858 | } |
| 7859 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7860 | final long identity = Binder.clearCallingIdentity(); |
| 7861 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7862 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7863 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7864 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7865 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7866 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7867 | Rlog.d(LOG_TAG, |
| 7868 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7869 | return null; |
| 7870 | } |
| 7871 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7872 | ServiceState ss = phone.getServiceState(); |
| 7873 | |
| 7874 | // Scrub out the location info in ServiceState depending on what level of access |
| 7875 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7876 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7877 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7878 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7879 | } finally { |
| 7880 | Binder.restoreCallingIdentity(identity); |
| 7881 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7882 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7883 | |
| 7884 | /** |
| 7885 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7886 | * |
| 7887 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7888 | * voicemail ringtone. |
| 7889 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7890 | * PhoneAccount. |
| 7891 | */ |
| 7892 | @Override |
| 7893 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7894 | final long identity = Binder.clearCallingIdentity(); |
| 7895 | try { |
| 7896 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7897 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7898 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7899 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7900 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7901 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7902 | } finally { |
| 7903 | Binder.restoreCallingIdentity(identity); |
| 7904 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7905 | } |
| 7906 | |
| 7907 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7908 | * Sets the per-account voicemail ringtone. |
| 7909 | * |
| 7910 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7911 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7912 | * |
| 7913 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7914 | * voicemail ringtone. |
| 7915 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7916 | * PhoneAccount. |
| 7917 | */ |
| 7918 | @Override |
| 7919 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7920 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7921 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7922 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7923 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7924 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7925 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7926 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7927 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7928 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7929 | |
| 7930 | final long identity = Binder.clearCallingIdentity(); |
| 7931 | try { |
| 7932 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7933 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7934 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7935 | } |
| 7936 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7937 | } finally { |
| 7938 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7939 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7940 | } |
| 7941 | |
| 7942 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7943 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7944 | * |
| 7945 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7946 | * voicemail vibration setting. |
| 7947 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7948 | */ |
| 7949 | @Override |
| 7950 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7951 | final long identity = Binder.clearCallingIdentity(); |
| 7952 | try { |
| 7953 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7954 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7955 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7956 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7957 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7958 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7959 | } finally { |
| 7960 | Binder.restoreCallingIdentity(identity); |
| 7961 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7962 | } |
| 7963 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7964 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7965 | * Sets the per-account voicemail vibration. |
| 7966 | * |
| 7967 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7968 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7969 | * |
| 7970 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7971 | * voicemail vibration setting. |
| 7972 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7973 | * specific PhoneAccount. |
| 7974 | */ |
| 7975 | @Override |
| 7976 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7977 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7978 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7979 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7980 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7981 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7982 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7983 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7984 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7985 | } |
| 7986 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7987 | final long identity = Binder.clearCallingIdentity(); |
| 7988 | try { |
| 7989 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7990 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7991 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7992 | } |
| 7993 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7994 | } finally { |
| 7995 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7996 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7997 | } |
| 7998 | |
| 7999 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8000 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8001 | * |
| 8002 | * @throws SecurityException if the caller does not have the required permission |
| 8003 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8004 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8005 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8006 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8007 | } |
| 8008 | |
| 8009 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8010 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8011 | * permission. |
| 8012 | * |
| 8013 | * @throws SecurityException if the caller does not have the required permission |
| 8014 | */ |
| 8015 | private void enforceSendSmsPermission() { |
| 8016 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8017 | } |
| 8018 | |
| 8019 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8020 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8021 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8022 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8023 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8024 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8025 | final long identity = Binder.clearCallingIdentity(); |
| 8026 | try { |
| 8027 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8028 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8029 | if (componentName == null) { |
| 8030 | throw new SecurityException( |
| 8031 | "Caller not current active visual voicemail package[null]"); |
| 8032 | } |
| 8033 | String vvmPackage = componentName.getPackageName(); |
| 8034 | if (!callingPackage.equals(vvmPackage)) { |
| 8035 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 8036 | + vvmPackage + "]"); |
| 8037 | } |
| 8038 | } finally { |
| 8039 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8040 | } |
| 8041 | } |
| 8042 | |
| 8043 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8044 | * Return the application ID for the app type. |
| 8045 | * |
| 8046 | * @param subId the subscription ID that this request applies to. |
| 8047 | * @param appType the uicc app type. |
| 8048 | * @return Application ID for specificied app type, or null if no uicc. |
| 8049 | */ |
| 8050 | @Override |
| 8051 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8052 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8053 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8054 | |
| 8055 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8056 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8057 | if (phone == null) { |
| 8058 | return null; |
| 8059 | } |
| 8060 | String aid = null; |
| 8061 | try { |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8062 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8063 | .getApplicationByType(appType).getAid(); |
| 8064 | } catch (Exception e) { |
| 8065 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8066 | } |
| 8067 | return aid; |
| 8068 | } finally { |
| 8069 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8070 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8071 | } |
| 8072 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8073 | /** |
| 8074 | * Return the Electronic Serial Number. |
| 8075 | * |
| 8076 | * @param subId the subscription ID that this request applies to. |
| 8077 | * @return ESN or null if error. |
| 8078 | */ |
| 8079 | @Override |
| 8080 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8081 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8082 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8083 | |
| 8084 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8085 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8086 | if (phone == null) { |
| 8087 | return null; |
| 8088 | } |
| 8089 | String esn = null; |
| 8090 | try { |
| 8091 | esn = phone.getEsn(); |
| 8092 | } catch (Exception e) { |
| 8093 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8094 | } |
| 8095 | return esn; |
| 8096 | } finally { |
| 8097 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8098 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8099 | } |
| 8100 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8101 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8102 | * Return the Preferred Roaming List Version. |
| 8103 | * |
| 8104 | * @param subId the subscription ID that this request applies to. |
| 8105 | * @return PRLVersion or null if error. |
| 8106 | */ |
| 8107 | @Override |
| 8108 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8109 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8110 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8111 | |
| 8112 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8113 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8114 | if (phone == null) { |
| 8115 | return null; |
| 8116 | } |
| 8117 | String cdmaPrlVersion = null; |
| 8118 | try { |
| 8119 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8120 | } catch (Exception e) { |
| 8121 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8122 | } |
| 8123 | return cdmaPrlVersion; |
| 8124 | } finally { |
| 8125 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8126 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8127 | } |
| 8128 | |
| 8129 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8130 | * Get snapshot of Telephony histograms |
| 8131 | * @return List of Telephony histograms |
| 8132 | * @hide |
| 8133 | */ |
| 8134 | @Override |
| 8135 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8136 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8137 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8138 | |
| 8139 | final long identity = Binder.clearCallingIdentity(); |
| 8140 | try { |
| 8141 | return RIL.getTelephonyRILTimingHistograms(); |
| 8142 | } finally { |
| 8143 | Binder.restoreCallingIdentity(identity); |
| 8144 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8145 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8146 | |
| 8147 | /** |
| 8148 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8149 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8150 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8151 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8152 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8153 | * @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] | 8154 | */ |
| 8155 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8156 | @TelephonyManager.SetCarrierRestrictionResult |
| 8157 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8158 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8159 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8160 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8161 | if (carrierRestrictionRules == null) { |
| 8162 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8163 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8164 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8165 | final long identity = Binder.clearCallingIdentity(); |
| 8166 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8167 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8168 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8169 | } finally { |
| 8170 | Binder.restoreCallingIdentity(identity); |
| 8171 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8172 | } |
| 8173 | |
| 8174 | /** |
| 8175 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8176 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8177 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8178 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8179 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8180 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8181 | */ |
| 8182 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8183 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8184 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8185 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8186 | |
| 8187 | final long identity = Binder.clearCallingIdentity(); |
| 8188 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8189 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8190 | if (response instanceof CarrierRestrictionRules) { |
| 8191 | return (CarrierRestrictionRules) response; |
| 8192 | } |
| 8193 | // Response is an Exception of some kind, |
| 8194 | // which is signalled to the user as a NULL retval |
| 8195 | return null; |
| 8196 | } catch (Exception e) { |
| 8197 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8198 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8199 | } finally { |
| 8200 | Binder.restoreCallingIdentity(identity); |
| 8201 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8202 | } |
| 8203 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8204 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8205 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8206 | * @param subId the subscription ID that this action applies to. |
| 8207 | * @param enabled control enable or disable radio. |
| 8208 | * {@hide} |
| 8209 | */ |
| 8210 | @Override |
| 8211 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8212 | enforceModifyPermission(); |
| 8213 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8214 | |
| 8215 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8216 | if (phone == null) { |
| 8217 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8218 | return; |
| 8219 | } |
| 8220 | try { |
| 8221 | phone.carrierActionSetRadioEnabled(enabled); |
| 8222 | } catch (Exception e) { |
| 8223 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8224 | } finally { |
| 8225 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8226 | } |
| 8227 | } |
| 8228 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8229 | /** |
Sooraj Sasindran | bf5c79c | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8230 | * Enable or disable Voice over NR (VoNR) |
| 8231 | * @param subId the subscription ID that this action applies to. |
| 8232 | * @param enabled enable or disable VoNR. |
| 8233 | * @return operation result. |
| 8234 | */ |
| 8235 | @Override |
| 8236 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8237 | enforceModifyPermission(); |
| 8238 | final Phone phone = getPhone(subId); |
| 8239 | |
| 8240 | final long identity = Binder.clearCallingIdentity(); |
| 8241 | if (phone == null) { |
| 8242 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8243 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8244 | } |
| 8245 | |
| 8246 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8247 | try { |
| 8248 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8249 | workSource); |
| 8250 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8251 | |
| 8252 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8253 | if (DBG) { |
| 8254 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8255 | } |
| 8256 | SubscriptionManager.setSubscriptionProperty( |
| 8257 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8258 | (enabled ? "1" : "0")); |
| 8259 | } |
| 8260 | |
Sooraj Sasindran | bf5c79c | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8261 | return result; |
| 8262 | } finally { |
| 8263 | Binder.restoreCallingIdentity(identity); |
| 8264 | } |
| 8265 | } |
| 8266 | |
| 8267 | /** |
| 8268 | * Is voice over NR enabled |
| 8269 | * @return true if VoNR is enabled else false |
| 8270 | */ |
| 8271 | @Override |
| 8272 | public boolean isVoNrEnabled(int subId) { |
| 8273 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8274 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8275 | final long identity = Binder.clearCallingIdentity(); |
| 8276 | try { |
| 8277 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8278 | null, subId, workSource); |
| 8279 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8280 | return isEnabled; |
| 8281 | } finally { |
| 8282 | Binder.restoreCallingIdentity(identity); |
| 8283 | } |
| 8284 | } |
| 8285 | |
| 8286 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8287 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8288 | * network status based on which carrier apps could apply actions accordingly, |
| 8289 | * enable/disable default url handler for example. |
| 8290 | * |
| 8291 | * @param subId the subscription ID that this action applies to. |
| 8292 | * @param report control start/stop reporting the default network status. |
| 8293 | * {@hide} |
| 8294 | */ |
| 8295 | @Override |
| 8296 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8297 | enforceModifyPermission(); |
| 8298 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8299 | |
| 8300 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8301 | if (phone == null) { |
| 8302 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8303 | return; |
| 8304 | } |
| 8305 | try { |
| 8306 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8307 | } catch (Exception e) { |
| 8308 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8309 | } finally { |
| 8310 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8311 | } |
| 8312 | } |
| 8313 | |
| 8314 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8315 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8316 | * @param subId the subscription ID that this action applies to. |
| 8317 | * {@hide} |
| 8318 | */ |
| 8319 | @Override |
| 8320 | public void carrierActionResetAll(int subId) { |
| 8321 | enforceModifyPermission(); |
| 8322 | final Phone phone = getPhone(subId); |
| 8323 | if (phone == null) { |
| 8324 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8325 | return; |
| 8326 | } |
| 8327 | try { |
| 8328 | phone.carrierActionResetAll(); |
| 8329 | } catch (Exception e) { |
| 8330 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8331 | } |
| 8332 | } |
| 8333 | |
| 8334 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8335 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8336 | * bug report is being generated. |
| 8337 | */ |
| 8338 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8339 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8340 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8341 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8342 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8343 | + Binder.getCallingPid() |
| 8344 | + ", uid=" + Binder.getCallingUid() |
| 8345 | + "without permission " |
| 8346 | + android.Manifest.permission.DUMP); |
| 8347 | return; |
| 8348 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8349 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8350 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8351 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8352 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8353 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8354 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8355 | @NonNull String[] args) { |
| 8356 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8357 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8358 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8359 | } |
| 8360 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8361 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8362 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8363 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8364 | * @param reason the reason the data enable change is taking place |
| 8365 | * @param enabled True if enabling the data, otherwise disabling. |
| 8366 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8367 | */ |
| 8368 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8369 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8370 | boolean enabled) { |
| 8371 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8372 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8373 | try { |
| 8374 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8375 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8376 | } catch (SecurityException se) { |
| 8377 | enforceModifyPermission(); |
| 8378 | } |
| 8379 | } else { |
| 8380 | enforceModifyPermission(); |
| 8381 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8382 | |
| 8383 | final long identity = Binder.clearCallingIdentity(); |
| 8384 | try { |
| 8385 | Phone phone = getPhone(subId); |
| 8386 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8387 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8388 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8389 | } else { |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 8390 | if (phone.isUsingNewDataStack()) { |
| 8391 | phone.getDataSettingsManager().setDataEnabled(reason, enabled); |
| 8392 | } else { |
| 8393 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 8394 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8395 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8396 | } |
| 8397 | } finally { |
| 8398 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8399 | } |
| 8400 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8401 | |
| 8402 | /** |
| 8403 | * Get Client request stats |
| 8404 | * @return List of Client Request Stats |
| 8405 | * @hide |
| 8406 | */ |
| 8407 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8408 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8409 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8410 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8411 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8412 | return null; |
| 8413 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8414 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8415 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8416 | final long identity = Binder.clearCallingIdentity(); |
| 8417 | try { |
| 8418 | if (phone != null) { |
| 8419 | return phone.getClientRequestStats(); |
| 8420 | } |
| 8421 | |
| 8422 | return null; |
| 8423 | } finally { |
| 8424 | Binder.restoreCallingIdentity(identity); |
| 8425 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8426 | } |
| 8427 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8428 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8429 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8430 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8431 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8432 | |
| 8433 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8434 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8435 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8436 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8437 | * @param state State of SIM (power down, power up, pass through) |
| 8438 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8439 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8440 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8441 | * |
| 8442 | **/ |
| 8443 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8444 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8445 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8446 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8447 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8448 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8449 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8450 | final long identity = Binder.clearCallingIdentity(); |
| 8451 | try { |
| 8452 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8453 | phone.setSimPowerState(state, null, workSource); |
| 8454 | } |
| 8455 | } finally { |
| 8456 | Binder.restoreCallingIdentity(identity); |
| 8457 | } |
| 8458 | } |
| 8459 | |
| 8460 | /** |
| 8461 | * Set SIM card power state. |
| 8462 | * |
| 8463 | * @param slotIndex SIM slot id. |
| 8464 | * @param state State of SIM (power down, power up, pass through) |
| 8465 | * @param callback callback to trigger after success or failure |
| 8466 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8467 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8468 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8469 | * |
| 8470 | **/ |
| 8471 | @Override |
| 8472 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8473 | IIntegerConsumer callback) { |
| 8474 | enforceModifyPermission(); |
| 8475 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8476 | |
| 8477 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8478 | |
| 8479 | final long identity = Binder.clearCallingIdentity(); |
| 8480 | try { |
| 8481 | if (phone != null) { |
| 8482 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8483 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8484 | } |
| 8485 | } finally { |
| 8486 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8487 | } |
| 8488 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8489 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8490 | private boolean isUssdApiAllowed(int subId) { |
| 8491 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8492 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8493 | if (configManager == null) { |
| 8494 | return false; |
| 8495 | } |
| 8496 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8497 | if (pb == null) { |
| 8498 | return false; |
| 8499 | } |
| 8500 | return pb.getBoolean( |
| 8501 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8502 | } |
| 8503 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8504 | /** |
| 8505 | * Check if phone is in emergency callback mode |
| 8506 | * @return true if phone is in emergency callback mode |
| 8507 | * @param subId sub id |
| 8508 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8509 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8510 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8511 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8512 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8513 | |
| 8514 | final long identity = Binder.clearCallingIdentity(); |
| 8515 | try { |
| 8516 | if (phone != null) { |
| 8517 | return phone.isInEcm(); |
| 8518 | } else { |
| 8519 | return false; |
| 8520 | } |
| 8521 | } finally { |
| 8522 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8523 | } |
| 8524 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8525 | |
| 8526 | /** |
| 8527 | * Get the current signal strength information for the given subscription. |
| 8528 | * Because this information is not updated when the device is in a low power state |
| 8529 | * it should not be relied-upon to be current. |
| 8530 | * @param subId Subscription index |
| 8531 | * @return the most recent cached signal strength info from the modem |
| 8532 | */ |
| 8533 | @Override |
| 8534 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8535 | final long identity = Binder.clearCallingIdentity(); |
| 8536 | try { |
| 8537 | Phone p = getPhone(subId); |
| 8538 | if (p == null) { |
| 8539 | return null; |
| 8540 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8541 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8542 | return p.getSignalStrength(); |
| 8543 | } finally { |
| 8544 | Binder.restoreCallingIdentity(identity); |
| 8545 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8546 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8547 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8548 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8549 | * Get the current modem radio state for the given slot. |
| 8550 | * @param slotIndex slot index. |
| 8551 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8552 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8553 | * @return the current radio power state from the modem |
| 8554 | */ |
| 8555 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8556 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8557 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8558 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8559 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8560 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8561 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8562 | } |
| 8563 | |
| 8564 | final long identity = Binder.clearCallingIdentity(); |
| 8565 | try { |
| 8566 | return phone.getRadioPowerState(); |
| 8567 | } finally { |
| 8568 | Binder.restoreCallingIdentity(identity); |
| 8569 | } |
| 8570 | } |
| 8571 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8572 | } |
| 8573 | |
| 8574 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8575 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8576 | * |
| 8577 | * <p>Requires one of the following permissions: |
| 8578 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8579 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8580 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8581 | * privileges. |
| 8582 | * |
| 8583 | * @param subId subscription id |
| 8584 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8585 | * {@code false}. |
| 8586 | */ |
| 8587 | @Override |
| 8588 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8589 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8590 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8591 | try { |
| 8592 | mApp.enforceCallingOrSelfPermission( |
| 8593 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8594 | functionName); |
| 8595 | } catch (Exception e) { |
| 8596 | mApp.enforceCallingOrSelfPermission( |
| 8597 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 8598 | } |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8599 | } catch (Exception e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8600 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8601 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8602 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8603 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8604 | boolean isEnabled = false; |
| 8605 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8606 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8607 | Phone phone = getPhone(subId); |
| 8608 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8609 | } finally { |
| 8610 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8611 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8612 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8613 | } |
| 8614 | |
| 8615 | |
| 8616 | /** |
| 8617 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8618 | * |
| 8619 | * <p> Requires permission: |
| 8620 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8621 | * privileges. |
| 8622 | * |
| 8623 | * @param subId subscription id |
| 8624 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8625 | */ |
| 8626 | @Override |
| 8627 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8628 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8629 | mApp, subId, "setDataRoamingEnabled"); |
| 8630 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8631 | final long identity = Binder.clearCallingIdentity(); |
| 8632 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8633 | Phone phone = getPhone(subId); |
| 8634 | if (phone != null) { |
| 8635 | phone.setDataRoamingEnabled(isEnabled); |
| 8636 | } |
| 8637 | } finally { |
| 8638 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8639 | } |
| 8640 | } |
| 8641 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8642 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8643 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8644 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8645 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8646 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8647 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8648 | boolean isAllowed = true; |
| 8649 | final long identity = Binder.clearCallingIdentity(); |
| 8650 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8651 | Phone phone = getPhone(subId); |
| 8652 | if (phone != null) { |
| 8653 | isAllowed = phone.isCspPlmnEnabled(); |
| 8654 | } |
| 8655 | } finally { |
| 8656 | Binder.restoreCallingIdentity(identity); |
| 8657 | } |
| 8658 | return isAllowed; |
| 8659 | } |
| 8660 | |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8661 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 8662 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 8663 | if (profile == null) { |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8664 | return false; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8665 | } |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 8666 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 8667 | if (phone == null) { |
| 8668 | return false; |
| 8669 | } |
| 8670 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 8671 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 8672 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8673 | } |
| 8674 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8675 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8676 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | 29b7e8e | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8677 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8678 | mApp.getSystemService(AppOpsManager.class) |
| 8679 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8680 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8681 | boolean hasReadPermission = false; |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8682 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8683 | try { |
| 8684 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8685 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8686 | } catch (SecurityException e) { |
| 8687 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8688 | // has carrier privileges on an active UICC |
| 8689 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8690 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8691 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8692 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8693 | } |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8694 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8695 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8696 | Binder.getCallingUid())) { |
| 8697 | isIccIdAccessRestricted = true; |
| 8698 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8699 | final long identity = Binder.clearCallingIdentity(); |
| 8700 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8701 | UiccController uiccController = UiccController.getInstance(); |
| 8702 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8703 | if (hasReadPermission) { |
| 8704 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8705 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8706 | |
| 8707 | // Remove private info if the caller doesn't have access |
| 8708 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8709 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8710 | //setting the value after compatibility check |
| 8711 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8712 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8713 | // is available |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8714 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8715 | if (card == null) { |
| 8716 | // assume no access if the card is unavailable |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8717 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8718 | continue; |
| 8719 | } |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8720 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 8721 | if (portInfos.isEmpty()) { |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8722 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8723 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8724 | } |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8725 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 8726 | for (UiccPortInfo portInfo : portInfos) { |
| 8727 | UiccPort port = uiccController.getUiccPortForSlot( |
| 8728 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 8729 | if (port == null) { |
| 8730 | // assume no access if port is null |
| 8731 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8732 | continue; |
| 8733 | } |
| 8734 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 8735 | uiccPortInfos.add(portInfo); |
| 8736 | } else { |
| 8737 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8738 | } |
| 8739 | } |
| 8740 | filteredInfos.add(new UiccCardInfo( |
| 8741 | cardInfo.isEuicc(), |
| 8742 | cardInfo.getCardId(), |
| 8743 | null, |
| 8744 | cardInfo.getPhysicalSlotIndex(), |
| 8745 | cardInfo.isRemovable(), |
| 8746 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8747 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8748 | } |
| 8749 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8750 | } finally { |
| 8751 | Binder.restoreCallingIdentity(identity); |
| 8752 | } |
| 8753 | } |
| 8754 | |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8755 | /** |
| 8756 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 8757 | * generally private and require carrier privileges to view. |
| 8758 | * |
| 8759 | * @hide |
| 8760 | */ |
| 8761 | @NonNull |
| 8762 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 8763 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 8764 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 8765 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 8766 | } |
| 8767 | return new UiccCardInfo( |
| 8768 | cardInfo.isEuicc(), |
| 8769 | cardInfo.getCardId(), |
| 8770 | null, |
| 8771 | cardInfo.getPhysicalSlotIndex(), |
| 8772 | cardInfo.isRemovable(), |
| 8773 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8774 | portinfo |
| 8775 | ); |
| 8776 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8777 | |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8778 | /** |
| 8779 | * @hide |
| 8780 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 8781 | * These values are generally private and require carrier privileges to view. |
| 8782 | */ |
| 8783 | @NonNull |
| 8784 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 8785 | return new UiccPortInfo( |
| 8786 | UiccPortInfo.ICCID_REDACTED, |
| 8787 | portInfo.getPortIndex(), |
| 8788 | portInfo.getLogicalSlotIndex(), |
| 8789 | portInfo.isActive() |
| 8790 | ); |
| 8791 | } |
| 8792 | @Override |
| 8793 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | 29b7e8e | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8794 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8795 | mApp.getSystemService(AppOpsManager.class) |
| 8796 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8797 | |
| 8798 | boolean hasReadPermission = false; |
| 8799 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8800 | |
| 8801 | try { |
| 8802 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
| 8803 | hasReadPermission = true; |
| 8804 | } catch (SecurityException e) { |
| 8805 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8806 | // has carrier privileges on an active UICC |
| 8807 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8808 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8809 | hasReadPermission = true; |
| 8810 | } |
| 8811 | } |
| 8812 | |
| 8813 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8814 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8815 | Binder.getCallingUid())) { |
| 8816 | isLogicalSlotAccessRestricted = true; |
| 8817 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8818 | final long identity = Binder.clearCallingIdentity(); |
| 8819 | try { |
| 8820 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8821 | if (slots == null) { |
| 8822 | Rlog.i(LOG_TAG, "slots is null."); |
| 8823 | return null; |
| 8824 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8825 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8826 | for (int i = 0; i < slots.length; i++) { |
| 8827 | UiccSlot slot = slots[i]; |
| 8828 | if (slot == null) { |
| 8829 | continue; |
| 8830 | } |
| 8831 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8832 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8833 | UiccCard card = slot.getUiccCard(); |
| 8834 | if (card != null) { |
| 8835 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8836 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8837 | cardId = slot.getEid(); |
| 8838 | if (TextUtils.isEmpty(cardId)) { |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8839 | // If cardId is null, use iccId of default port as cardId. Check if has |
| 8840 | // read permission otherwise set to null.(card is null which means no |
| 8841 | // carrier permission) |
| 8842 | cardId = hasReadPermission ? slot.getIccId( |
| 8843 | TelephonyManager.DEFAULT_PORT_INDEX) : null; |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8844 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8845 | } |
| 8846 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8847 | if (cardId != null) { |
| 8848 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8849 | // if cardId is an EID, it's all digits so this is fine |
| 8850 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8851 | } |
| 8852 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8853 | int cardState = 0; |
| 8854 | switch (slot.getCardState()) { |
| 8855 | case CARDSTATE_ABSENT: |
| 8856 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8857 | break; |
| 8858 | case CARDSTATE_PRESENT: |
| 8859 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8860 | break; |
| 8861 | case CARDSTATE_ERROR: |
| 8862 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8863 | break; |
| 8864 | case CARDSTATE_RESTRICTED: |
| 8865 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8866 | break; |
| 8867 | default: |
| 8868 | break; |
| 8869 | |
| 8870 | } |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8871 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 8872 | int[] portIndexes = slot.getPortList(); |
| 8873 | for (int portIdx : portIndexes) { |
| 8874 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
| 8875 | callingPackage, hasReadPermission)); |
| 8876 | if (slot.isPortActive(portIdx)) { |
| 8877 | UiccPort port = slot.getUiccCard().getUiccPort(portIdx); |
| 8878 | portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(), |
| 8879 | port.getPhoneId(), true)); |
| 8880 | } else { |
| 8881 | portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false)); |
| 8882 | } |
| 8883 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8884 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8885 | slot.isEuicc(), |
| 8886 | cardId, |
| 8887 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8888 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8889 | slot.isRemovable(), portInfos); |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8890 | //setting the value after compatibility check |
| 8891 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8892 | } |
| 8893 | return infos; |
| 8894 | } finally { |
| 8895 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8896 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8897 | } |
| 8898 | |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8899 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 8900 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 8901 | boolean hasReadPermission) { |
| 8902 | String iccId = slot.getIccId(portIndex); |
| 8903 | if (hasReadPermission) { // if has read permission |
| 8904 | return iccId; |
| 8905 | } else { |
| 8906 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 8907 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 8908 | // if no read permission, checking carrier privilege access |
| 8909 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 8910 | return iccId; |
| 8911 | } |
| 8912 | } |
| 8913 | } |
| 8914 | // No read permission or carrier privilege access. |
| 8915 | return UiccPortInfo.ICCID_REDACTED; |
| 8916 | } |
| 8917 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8918 | @Override |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8919 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8920 | public boolean switchSlots(int[] physicalSlots) { |
| 8921 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8922 | |
| 8923 | final long identity = Binder.clearCallingIdentity(); |
| 8924 | try { |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8925 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 8926 | for (int i = 0; i < physicalSlots.length; i++) { |
| 8927 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 8928 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 8929 | physicalSlots[i], i)); |
| 8930 | } |
| 8931 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8932 | } finally { |
| 8933 | Binder.restoreCallingIdentity(identity); |
| 8934 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8935 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8936 | |
| 8937 | @Override |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8938 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 8939 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 8940 | enforceModifyPermission(); |
| 8941 | |
| 8942 | final long identity = Binder.clearCallingIdentity(); |
| 8943 | try { |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8944 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8945 | } finally { |
| 8946 | Binder.restoreCallingIdentity(identity); |
| 8947 | } |
| 8948 | } |
| 8949 | |
| 8950 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8951 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8952 | final long identity = Binder.clearCallingIdentity(); |
| 8953 | try { |
| 8954 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8955 | } finally { |
| 8956 | Binder.restoreCallingIdentity(identity); |
| 8957 | } |
| 8958 | } |
| 8959 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8960 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8961 | * A test API to reload the UICC profile. |
| 8962 | * |
| 8963 | * <p>Requires that the calling app has permission |
| 8964 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8965 | * @hide |
| 8966 | */ |
| 8967 | @Override |
| 8968 | public void refreshUiccProfile(int subId) { |
| 8969 | enforceModifyPermission(); |
| 8970 | |
| 8971 | final long identity = Binder.clearCallingIdentity(); |
| 8972 | try { |
| 8973 | Phone phone = getPhone(subId); |
| 8974 | if (phone == null) { |
| 8975 | return; |
| 8976 | } |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8977 | UiccPort uiccPort = phone.getUiccPort(); |
| 8978 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8979 | return; |
| 8980 | } |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8981 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8982 | if (uiccProfile == null) { |
| 8983 | return; |
| 8984 | } |
| 8985 | uiccProfile.refresh(); |
| 8986 | } finally { |
| 8987 | Binder.restoreCallingIdentity(identity); |
| 8988 | } |
| 8989 | } |
| 8990 | |
| 8991 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8992 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8993 | */ |
| 8994 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8995 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8996 | } |
| 8997 | |
| 8998 | /** |
| 8999 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9000 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9001 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9002 | */ |
| 9003 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9004 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9005 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9006 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9007 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9008 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9009 | return isDataRoamingEnabled; |
| 9010 | } |
| 9011 | |
| 9012 | /** |
| 9013 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9014 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9015 | */ |
| 9016 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9017 | List<Integer> list = TelephonyProperties.default_network(); |
| 9018 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 9019 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9020 | return list.get(phoneId); |
| 9021 | } |
| 9022 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9023 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9024 | |
| 9025 | @Override |
| 9026 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9027 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9028 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9029 | |
| 9030 | final long identity = Binder.clearCallingIdentity(); |
| 9031 | try { |
| 9032 | final Phone phone = getPhone(subId); |
| 9033 | if (phone == null) { |
| 9034 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9035 | return; |
| 9036 | } |
Rambo Wang | a743688 | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9037 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9038 | if (cpt != null) { |
| 9039 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9040 | } |
| 9041 | // 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] | 9042 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9043 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9044 | if (carrierPrivilegeRules == null) { |
| 9045 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9046 | } else { |
| 9047 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9048 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9049 | } finally { |
| 9050 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9051 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9052 | } |
| 9053 | |
| 9054 | @Override |
| 9055 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9056 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9057 | |
| 9058 | final long identity = Binder.clearCallingIdentity(); |
| 9059 | try { |
| 9060 | final Phone phone = getPhone(subId); |
| 9061 | if (phone == null) { |
| 9062 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9063 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9064 | } |
| 9065 | return phone.getCarrierIdListVersion(); |
| 9066 | } finally { |
| 9067 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9068 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9069 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9070 | |
| 9071 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9072 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9073 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9074 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9075 | mApp, subId, callingPackage, callingFeatureId, |
| 9076 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9077 | return -1; |
| 9078 | } |
| 9079 | |
| 9080 | final long identity = Binder.clearCallingIdentity(); |
| 9081 | try { |
| 9082 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9083 | } finally { |
| 9084 | Binder.restoreCallingIdentity(identity); |
| 9085 | } |
| 9086 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9087 | |
| 9088 | @Override |
| 9089 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9090 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9091 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9092 | mApp, subId, "getCdmaRoamingMode"); |
| 9093 | |
| 9094 | final long identity = Binder.clearCallingIdentity(); |
| 9095 | try { |
| 9096 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9097 | } finally { |
| 9098 | Binder.restoreCallingIdentity(identity); |
| 9099 | } |
| 9100 | } |
| 9101 | |
| 9102 | @Override |
| 9103 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9104 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9105 | mApp, subId, "setCdmaRoamingMode"); |
| 9106 | |
| 9107 | final long identity = Binder.clearCallingIdentity(); |
| 9108 | try { |
| 9109 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9110 | } finally { |
| 9111 | Binder.restoreCallingIdentity(identity); |
| 9112 | } |
| 9113 | } |
| 9114 | |
| 9115 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9116 | public int getCdmaSubscriptionMode(int subId) { |
| 9117 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9118 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9119 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9120 | |
| 9121 | final long identity = Binder.clearCallingIdentity(); |
| 9122 | try { |
| 9123 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9124 | } finally { |
| 9125 | Binder.restoreCallingIdentity(identity); |
| 9126 | } |
| 9127 | } |
| 9128 | |
| 9129 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9130 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9131 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9132 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9133 | |
| 9134 | final long identity = Binder.clearCallingIdentity(); |
| 9135 | try { |
| 9136 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9137 | } finally { |
| 9138 | Binder.restoreCallingIdentity(identity); |
| 9139 | } |
| 9140 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9141 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9142 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9143 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9144 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9145 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9146 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9147 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9148 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9149 | } |
| 9150 | final long identity = Binder.clearCallingIdentity(); |
| 9151 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9152 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9153 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9154 | if (phone.getEmergencyNumberTracker() != null |
| 9155 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9156 | emergencyNumberListInternal.put( |
| 9157 | phone.getSubId(), |
| 9158 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9159 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9160 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9161 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9162 | } finally { |
| 9163 | Binder.restoreCallingIdentity(identity); |
| 9164 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9165 | } |
| 9166 | |
| 9167 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9168 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9169 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9170 | if (!exactMatch) { |
| 9171 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9172 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9173 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9174 | } |
| 9175 | final long identity = Binder.clearCallingIdentity(); |
| 9176 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9177 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9178 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9179 | && phone.getEmergencyNumberTracker() |
| 9180 | .isEmergencyNumber(number, exactMatch)) { |
| 9181 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9182 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9183 | } |
| 9184 | return false; |
| 9185 | } finally { |
| 9186 | Binder.restoreCallingIdentity(identity); |
| 9187 | } |
| 9188 | } |
| 9189 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9190 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9191 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9192 | */ |
| 9193 | @Override |
| 9194 | public void startEmergencyCallbackMode() { |
| 9195 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9196 | "startEmergencyCallbackMode"); |
| 9197 | enforceModifyPermission(); |
| 9198 | final long identity = Binder.clearCallingIdentity(); |
| 9199 | try { |
| 9200 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9201 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9202 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9203 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9204 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9205 | gsmCdmaPhone.obtainMessage( |
| 9206 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9207 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9208 | } |
| 9209 | } |
| 9210 | } finally { |
| 9211 | Binder.restoreCallingIdentity(identity); |
| 9212 | } |
| 9213 | } |
| 9214 | |
| 9215 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9216 | * Update emergency number list for test mode. |
| 9217 | */ |
| 9218 | @Override |
| 9219 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9220 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9221 | "updateEmergencyNumberListTestMode"); |
| 9222 | |
| 9223 | final long identity = Binder.clearCallingIdentity(); |
| 9224 | try { |
| 9225 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9226 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9227 | if (tracker != null) { |
| 9228 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9229 | } |
| 9230 | } |
| 9231 | } finally { |
| 9232 | Binder.restoreCallingIdentity(identity); |
| 9233 | } |
| 9234 | } |
| 9235 | |
| 9236 | /** |
| 9237 | * Get the full emergency number list for test mode. |
| 9238 | */ |
| 9239 | @Override |
| 9240 | public List<String> getEmergencyNumberListTestMode() { |
| 9241 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9242 | "getEmergencyNumberListTestMode"); |
| 9243 | |
| 9244 | final long identity = Binder.clearCallingIdentity(); |
| 9245 | try { |
| 9246 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9247 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9248 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9249 | if (tracker != null) { |
| 9250 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9251 | emergencyNumbers.add(num.getNumber()); |
| 9252 | } |
| 9253 | } |
| 9254 | } |
| 9255 | return new ArrayList<>(emergencyNumbers); |
| 9256 | } finally { |
| 9257 | Binder.restoreCallingIdentity(identity); |
| 9258 | } |
| 9259 | } |
| 9260 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9261 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9262 | public int getEmergencyNumberDbVersion(int subId) { |
| 9263 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9264 | |
| 9265 | final long identity = Binder.clearCallingIdentity(); |
| 9266 | try { |
| 9267 | final Phone phone = getPhone(subId); |
| 9268 | if (phone == null) { |
| 9269 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9270 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9271 | } |
| 9272 | return phone.getEmergencyNumberDbVersion(); |
| 9273 | } finally { |
| 9274 | Binder.restoreCallingIdentity(identity); |
| 9275 | } |
| 9276 | } |
| 9277 | |
| 9278 | @Override |
| 9279 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9280 | enforceModifyPermission(); |
| 9281 | |
| 9282 | final long identity = Binder.clearCallingIdentity(); |
| 9283 | try { |
| 9284 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9285 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9286 | if (tracker != null) { |
| 9287 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9288 | } |
| 9289 | } |
| 9290 | } finally { |
| 9291 | Binder.restoreCallingIdentity(identity); |
| 9292 | } |
| 9293 | } |
| 9294 | |
| 9295 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9296 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9297 | enforceActiveEmergencySessionPermission(); |
| 9298 | |
| 9299 | final long identity = Binder.clearCallingIdentity(); |
| 9300 | try { |
| 9301 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9302 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9303 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9304 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9305 | } |
| 9306 | } |
| 9307 | } finally { |
| 9308 | Binder.restoreCallingIdentity(identity); |
| 9309 | } |
| 9310 | } |
| 9311 | |
| 9312 | @Override |
| 9313 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9314 | enforceActiveEmergencySessionPermission(); |
| 9315 | |
| 9316 | final long identity = Binder.clearCallingIdentity(); |
| 9317 | try { |
| 9318 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9319 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9320 | if (tracker != null) { |
| 9321 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9322 | } |
| 9323 | } |
| 9324 | } finally { |
| 9325 | Binder.restoreCallingIdentity(identity); |
| 9326 | } |
| 9327 | } |
| 9328 | |
| 9329 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9330 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9331 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9332 | Phone phone = getPhone(subId); |
| 9333 | if (phone == null) { |
| 9334 | return null; |
| 9335 | } |
| 9336 | final long identity = Binder.clearCallingIdentity(); |
| 9337 | try { |
| 9338 | UiccProfile profile = UiccController.getInstance() |
| 9339 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9340 | if (profile != null) { |
| 9341 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9342 | } |
| 9343 | } finally { |
| 9344 | Binder.restoreCallingIdentity(identity); |
| 9345 | } |
| 9346 | return null; |
| 9347 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9348 | |
| 9349 | /** |
| 9350 | * Enable or disable a modem stack. |
| 9351 | */ |
| 9352 | @Override |
| 9353 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9354 | enforceModifyPermission(); |
| 9355 | |
| 9356 | final long identity = Binder.clearCallingIdentity(); |
| 9357 | try { |
| 9358 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9359 | if (phone == null) { |
| 9360 | return false; |
| 9361 | } else { |
| 9362 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9363 | } |
| 9364 | } finally { |
| 9365 | Binder.restoreCallingIdentity(identity); |
| 9366 | } |
| 9367 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9368 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9369 | /** |
| 9370 | * Whether a modem stack is enabled or not. |
| 9371 | */ |
| 9372 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9373 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9374 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9375 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9376 | if (phone == null) return false; |
| 9377 | |
| 9378 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9379 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9380 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9381 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9382 | } |
| 9383 | |
| 9384 | final long identity = Binder.clearCallingIdentity(); |
| 9385 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9386 | try { |
| 9387 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9388 | } catch (NoSuchElementException ex) { |
| 9389 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9390 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9391 | } finally { |
| 9392 | Binder.restoreCallingIdentity(identity); |
| 9393 | } |
| 9394 | } |
| 9395 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9396 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9397 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9398 | enforceModifyPermission(); |
| 9399 | |
| 9400 | final long identity = Binder.clearCallingIdentity(); |
| 9401 | try { |
| 9402 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9403 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9404 | .commit(); |
| 9405 | } finally { |
| 9406 | Binder.restoreCallingIdentity(identity); |
| 9407 | } |
| 9408 | } |
| 9409 | |
| 9410 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9411 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9412 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9413 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9414 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9415 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9416 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9417 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9418 | |
| 9419 | final long identity = Binder.clearCallingIdentity(); |
| 9420 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9421 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9422 | } finally { |
| 9423 | Binder.restoreCallingIdentity(identity); |
| 9424 | } |
| 9425 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9426 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9427 | @TelephonyManager.IsMultiSimSupportedResult |
| 9428 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9429 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9430 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9431 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9432 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9433 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9434 | } |
| 9435 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9436 | // supported by the modem, indicate that it is restricted. |
| 9437 | PhoneCapability staticCapability = |
| 9438 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9439 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9440 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9441 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9442 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9443 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9444 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9445 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9446 | } |
| 9447 | // Check if support of multiple SIMs is restricted by carrier |
| 9448 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9449 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9450 | } |
| 9451 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9452 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9453 | } |
| 9454 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9455 | /** |
| 9456 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9457 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9458 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9459 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9460 | * @param numOfSims number of active sims we want to switch to |
| 9461 | */ |
| 9462 | @Override |
| 9463 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9464 | if (numOfSims == 1) { |
| 9465 | enforceModifyPermission(); |
| 9466 | } else { |
| 9467 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9468 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9469 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9470 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9471 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9472 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9473 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9474 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9475 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9476 | return; |
| 9477 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9478 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9479 | } finally { |
| 9480 | Binder.restoreCallingIdentity(identity); |
| 9481 | } |
| 9482 | } |
| 9483 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9484 | @Override |
| 9485 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9486 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9487 | Phone phone = getPhone(subId); |
| 9488 | if (phone == null) { |
| 9489 | return false; |
| 9490 | } |
| 9491 | final long identity = Binder.clearCallingIdentity(); |
| 9492 | try { |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9493 | UiccPort uiccPort = phone.getUiccPort(); |
| 9494 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9495 | return false; |
| 9496 | } |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9497 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9498 | if (uiccProfile == null) { |
| 9499 | return false; |
| 9500 | } |
| 9501 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9502 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9503 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9504 | } |
| 9505 | return false; |
| 9506 | } finally { |
| 9507 | Binder.restoreCallingIdentity(identity); |
| 9508 | } |
| 9509 | } |
| 9510 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9511 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9512 | * Get whether making changes to modem configurations will trigger reboot. |
| 9513 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9514 | */ |
| 9515 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9516 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9517 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9518 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9519 | mApp, subId, callingPackage, callingFeatureId, |
| 9520 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9521 | return false; |
| 9522 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9523 | final long identity = Binder.clearCallingIdentity(); |
| 9524 | try { |
| 9525 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9526 | } finally { |
| 9527 | Binder.restoreCallingIdentity(identity); |
| 9528 | } |
| 9529 | } |
| 9530 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9531 | private void updateModemStateMetrics() { |
| 9532 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9533 | // TODO: check the state for each modem if the api is ready. |
| 9534 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9535 | } |
| 9536 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9537 | @Override |
sandeepjs | 29b7e8e | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9538 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9539 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | 29b7e8e | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9540 | // Verify that the callingPackage belongs to the calling UID |
| 9541 | mApp.getSystemService(AppOpsManager.class) |
| 9542 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9543 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | 29b7e8e | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9544 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9545 | try { |
sandeepjs | 29b7e8e | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9546 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 9547 | if (slotInfos != null) { |
| 9548 | for (int i = 0; i < slotInfos.length; i++) { |
| 9549 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 9550 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 9551 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 9552 | portInfo.getLogicalSlotIndex())); |
| 9553 | } |
| 9554 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9555 | } |
| 9556 | } |
sandeepjs | 29b7e8e | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9557 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9558 | } finally { |
| 9559 | Binder.restoreCallingIdentity(identity); |
| 9560 | } |
| 9561 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9562 | |
| 9563 | /** |
| 9564 | * Get the IRadio HAL Version |
| 9565 | */ |
| 9566 | @Override |
| 9567 | public int getRadioHalVersion() { |
| 9568 | Phone phone = getDefaultPhone(); |
| 9569 | if (phone == null) return -1; |
| 9570 | HalVersion hv = phone.getHalVersion(); |
| 9571 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9572 | return hv.major * 100 + hv.minor; |
| 9573 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9574 | |
| 9575 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9576 | * Get the current calling package name. |
| 9577 | * @return the current calling package name |
| 9578 | */ |
| 9579 | @Override |
| 9580 | public String getCurrentPackageName() { |
| 9581 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9582 | } |
| 9583 | |
| 9584 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9585 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9586 | * corresponding network requests on a subId. |
| 9587 | * |
| 9588 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9589 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9590 | * 2) APN is un-metered for this subscription, or |
| 9591 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9592 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9593 | * |
| 9594 | * @return whether data is allowed for a apn type. |
| 9595 | * |
| 9596 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9597 | */ |
| 9598 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9599 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9600 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9601 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9602 | |
| 9603 | // Now that all security checks passes, perform the operation as ourselves. |
| 9604 | final long identity = Binder.clearCallingIdentity(); |
| 9605 | try { |
| 9606 | Phone phone = getPhone(subId); |
| 9607 | if (phone == null) return false; |
| 9608 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9609 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9610 | boolean isDataEnabled; |
| 9611 | if (phone.isUsingNewDataStack()) { |
| 9612 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
| 9613 | } else { |
| 9614 | isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9615 | } |
| 9616 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9617 | } finally { |
| 9618 | Binder.restoreCallingIdentity(identity); |
| 9619 | } |
| 9620 | } |
| 9621 | |
| 9622 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9623 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9624 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9625 | |
| 9626 | // Now that all security checks passes, perform the operation as ourselves. |
| 9627 | final long identity = Binder.clearCallingIdentity(); |
| 9628 | try { |
| 9629 | Phone phone = getPhone(subId); |
| 9630 | if (phone == null) return true; // By default return true. |
| 9631 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9632 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9633 | } finally { |
| 9634 | Binder.restoreCallingIdentity(identity); |
| 9635 | } |
| 9636 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9637 | |
| 9638 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9639 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9640 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9641 | enforceModifyPermission(); |
| 9642 | long token = Binder.clearCallingIdentity(); |
| 9643 | try { |
| 9644 | Phone phone = getPhone(subscriptionId); |
| 9645 | if (phone == null) { |
| 9646 | try { |
| 9647 | if (resultCallback != null) { |
| 9648 | resultCallback.accept(false); |
| 9649 | } |
| 9650 | } catch (RemoteException e) { |
| 9651 | // ignore |
| 9652 | } |
| 9653 | return; |
| 9654 | } |
| 9655 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9656 | Pair.create(specifiers, (x) -> { |
| 9657 | try { |
| 9658 | if (resultCallback != null) { |
| 9659 | resultCallback.accept(x); |
| 9660 | } |
| 9661 | } catch (RemoteException e) { |
| 9662 | // ignore |
| 9663 | } |
| 9664 | }); |
| 9665 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9666 | } finally { |
| 9667 | Binder.restoreCallingIdentity(token); |
| 9668 | } |
| 9669 | } |
| 9670 | |
| 9671 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9672 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9673 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9674 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9675 | mApp, subId, "getSystemSelectionChannels"); |
| 9676 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9677 | final long identity = Binder.clearCallingIdentity(); |
| 9678 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 9679 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 9680 | if (result instanceof IllegalStateException) { |
| 9681 | throw (IllegalStateException) result; |
| 9682 | } |
| 9683 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9684 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9685 | return specifiers; |
| 9686 | } finally { |
| 9687 | Binder.restoreCallingIdentity(identity); |
| 9688 | } |
| 9689 | } |
| 9690 | |
| 9691 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9692 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9693 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9694 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9695 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9696 | if (iccRecords == null) { |
| 9697 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9698 | return false; |
| 9699 | } |
| 9700 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9701 | } |
| 9702 | |
| 9703 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9704 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9705 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9706 | if (callingPackage == null) { |
| 9707 | callingPackage = getCurrentPackageName(); |
| 9708 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9709 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9710 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9711 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9712 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9713 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9714 | } |
| 9715 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9716 | Intent intent = new Intent(); |
| 9717 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9718 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9719 | // Bring up choose default SMS subscription dialog right now |
| 9720 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9721 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9722 | mApp.startActivity(intent); |
| 9723 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9724 | |
| 9725 | @Override |
| 9726 | public String getMmsUAProfUrl(int subId) { |
| 9727 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9728 | final long identity = Binder.clearCallingIdentity(); |
| 9729 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9730 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9731 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9732 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9733 | return carrierUAProfUrl; |
| 9734 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9735 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9736 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9737 | } finally { |
| 9738 | Binder.restoreCallingIdentity(identity); |
| 9739 | } |
| 9740 | } |
| 9741 | |
| 9742 | @Override |
| 9743 | public String getMmsUserAgent(int subId) { |
| 9744 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9745 | final long identity = Binder.clearCallingIdentity(); |
| 9746 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9747 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9748 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9749 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9750 | return carrierUserAgent; |
| 9751 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9752 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9753 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9754 | } finally { |
| 9755 | Binder.restoreCallingIdentity(identity); |
| 9756 | } |
| 9757 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9758 | |
| 9759 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9760 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9761 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9762 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9763 | final long identity = Binder.clearCallingIdentity(); |
| 9764 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9765 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9766 | if (phone == null) return false; |
| 9767 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9768 | switch (policy) { |
| 9769 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9770 | if (phone.isUsingNewDataStack()) { |
| 9771 | return phone.getDataSettingsManager().isDataAllowedInVoiceCall(); |
| 9772 | } else { |
| 9773 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9774 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9775 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9776 | if (phone.isUsingNewDataStack()) { |
| 9777 | return phone.getDataSettingsManager().isMmsAlwaysAllowed(); |
| 9778 | } else { |
| 9779 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9780 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9781 | default: |
| 9782 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9783 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9784 | } finally { |
| 9785 | Binder.restoreCallingIdentity(identity); |
| 9786 | } |
| 9787 | } |
| 9788 | |
| 9789 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9790 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9791 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9792 | enforceModifyPermission(); |
| 9793 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9794 | final long identity = Binder.clearCallingIdentity(); |
| 9795 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9796 | Phone phone = getPhone(subscriptionId); |
| 9797 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9798 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9799 | switch (policy) { |
| 9800 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9801 | if (phone.isUsingNewDataStack()) { |
| 9802 | phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled); |
| 9803 | } else { |
| 9804 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9805 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9806 | break; |
| 9807 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9808 | if (phone.isUsingNewDataStack()) { |
| 9809 | phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled); |
| 9810 | } else { |
| 9811 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9812 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9813 | break; |
| 9814 | default: |
| 9815 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9816 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9817 | } finally { |
| 9818 | Binder.restoreCallingIdentity(identity); |
| 9819 | } |
| 9820 | } |
| 9821 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9822 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9823 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9824 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9825 | * otherwise. |
| 9826 | */ |
| 9827 | @Override |
| 9828 | public void setCepEnabled(boolean isCepEnabled) { |
| 9829 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9830 | |
| 9831 | final long identity = Binder.clearCallingIdentity(); |
| 9832 | try { |
| 9833 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9834 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9835 | Phone defaultPhone = phone.getImsPhone(); |
| 9836 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9837 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9838 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9839 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9840 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9841 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9842 | + imsPhone.getMsisdn()); |
| 9843 | } |
| 9844 | } |
| 9845 | } finally { |
| 9846 | Binder.restoreCallingIdentity(identity); |
| 9847 | } |
| 9848 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9849 | |
| 9850 | /** |
| 9851 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9852 | * |
| 9853 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9854 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9855 | * before being read. |
| 9856 | */ |
| 9857 | @Override |
| 9858 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9859 | isCompressed) { |
| 9860 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9861 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9862 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9863 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9864 | } |
| 9865 | if (!isImsAvailableOnDevice()) { |
| 9866 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9867 | "IMS not available on device."); |
| 9868 | } |
| 9869 | |
| 9870 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9871 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9872 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9873 | } finally { |
| 9874 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9875 | } |
| 9876 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9877 | |
| 9878 | @Override |
| 9879 | public boolean isIccLockEnabled(int subId) { |
| 9880 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9881 | |
| 9882 | // Now that all security checks passes, perform the operation as ourselves. |
| 9883 | final long identity = Binder.clearCallingIdentity(); |
| 9884 | try { |
| 9885 | Phone phone = getPhone(subId); |
| 9886 | if (phone != null && phone.getIccCard() != null) { |
| 9887 | return phone.getIccCard().getIccLockEnabled(); |
| 9888 | } else { |
| 9889 | return false; |
| 9890 | } |
| 9891 | } finally { |
| 9892 | Binder.restoreCallingIdentity(identity); |
| 9893 | } |
| 9894 | } |
| 9895 | |
| 9896 | /** |
| 9897 | * Set the ICC pin lock enabled or disabled. |
| 9898 | * |
| 9899 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9900 | * three cases: |
| 9901 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9902 | * successfully. |
| 9903 | * - Positive number and zero for remaining password attempts. |
| 9904 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9905 | * |
| 9906 | */ |
| 9907 | @Override |
| 9908 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9909 | enforceModifyPermission(); |
| 9910 | |
| 9911 | Phone phone = getPhone(subId); |
| 9912 | if (phone == null) { |
| 9913 | return 0; |
| 9914 | } |
| 9915 | // Now that all security checks passes, perform the operation as ourselves. |
| 9916 | final long identity = Binder.clearCallingIdentity(); |
| 9917 | try { |
| 9918 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9919 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9920 | return attemptsRemaining; |
| 9921 | |
| 9922 | } catch (Exception e) { |
| 9923 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9924 | } finally { |
| 9925 | Binder.restoreCallingIdentity(identity); |
| 9926 | } |
| 9927 | return 0; |
| 9928 | } |
| 9929 | |
| 9930 | /** |
| 9931 | * Change the ICC password used in ICC pin lock. |
| 9932 | * |
| 9933 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9934 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9935 | * - Positive number and zero for remaining password attempts. |
| 9936 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9937 | * |
| 9938 | */ |
| 9939 | @Override |
| 9940 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9941 | enforceModifyPermission(); |
| 9942 | |
| 9943 | Phone phone = getPhone(subId); |
| 9944 | if (phone == null) { |
| 9945 | return 0; |
| 9946 | } |
| 9947 | // Now that all security checks passes, perform the operation as ourselves. |
| 9948 | final long identity = Binder.clearCallingIdentity(); |
| 9949 | try { |
| 9950 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9951 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9952 | return attemptsRemaining; |
| 9953 | |
| 9954 | } catch (Exception e) { |
| 9955 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9956 | } finally { |
| 9957 | Binder.restoreCallingIdentity(identity); |
| 9958 | } |
| 9959 | return 0; |
| 9960 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9961 | |
| 9962 | /** |
| 9963 | * Request for receiving user activity notification |
| 9964 | */ |
| 9965 | @Override |
| 9966 | public void requestUserActivityNotification() { |
| 9967 | if (!mNotifyUserActivity.get() |
| 9968 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9969 | mNotifyUserActivity.set(true); |
| 9970 | } |
| 9971 | } |
| 9972 | |
| 9973 | /** |
| 9974 | * Called when userActivity is signalled in the power manager. |
| 9975 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9976 | */ |
| 9977 | @Override |
| 9978 | public void userActivity() { |
| 9979 | // *************************************** |
| 9980 | // * Inherited from PhoneWindowManager * |
| 9981 | // *************************************** |
| 9982 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9983 | // WITH ITS LOCKS HELD. |
| 9984 | // |
| 9985 | // This code must be VERY careful about the locks |
| 9986 | // it acquires. |
| 9987 | // In fact, the current code acquires way too many, |
| 9988 | // and probably has lurking deadlocks. |
| 9989 | |
| 9990 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9991 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9992 | } |
| 9993 | |
| 9994 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9995 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9996 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9997 | } |
| 9998 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9999 | |
| 10000 | @Override |
| 10001 | public boolean canConnectTo5GInDsdsMode() { |
| 10002 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10003 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10004 | |
| 10005 | @Override |
| 10006 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10007 | String callingFeatureId) { |
| 10008 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10009 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10010 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10011 | } |
| 10012 | |
| 10013 | Phone phone = getPhone(subId); |
| 10014 | if (phone == null) { |
| 10015 | throw new RuntimeException("phone is not available"); |
| 10016 | } |
| 10017 | // Now that all security checks passes, perform the operation as ourselves. |
| 10018 | final long identity = Binder.clearCallingIdentity(); |
| 10019 | try { |
| 10020 | return phone.getEquivalentHomePlmns(); |
| 10021 | } finally { |
| 10022 | Binder.restoreCallingIdentity(identity); |
| 10023 | } |
| 10024 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10025 | |
| 10026 | @Override |
| 10027 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10028 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10029 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10030 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10031 | if (radioInterfaceCapabilities == null) { |
| 10032 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10033 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10034 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10035 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10036 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10037 | @Override |
| 10038 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10039 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10040 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10041 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10042 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10043 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10044 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10045 | if (DBG) { |
| 10046 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10047 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10048 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10049 | } |
| 10050 | |
| 10051 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10052 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10053 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10054 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10055 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10056 | if (callback != null) { |
| 10057 | try { |
| 10058 | callback.onAuthenticationFailure( |
| 10059 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10060 | } catch (RemoteException exception) { |
| 10061 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10062 | } |
| 10063 | return; |
| 10064 | } |
| 10065 | } |
| 10066 | |
| 10067 | final long token = Binder.clearCallingIdentity(); |
| 10068 | try { |
| 10069 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10070 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 10071 | forceBootStrapping, callback)); |
| 10072 | } finally { |
| 10073 | Binder.restoreCallingIdentity(token); |
| 10074 | } |
| 10075 | } |
| 10076 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10077 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10078 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10079 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10080 | * requested radio power state will actually be set. See {@link |
| 10081 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10082 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10083 | * @param enable {@code true} if trying to turn radio on. |
| 10084 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10085 | * false}. |
| 10086 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10087 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10088 | boolean isPhoneAvailable = false; |
| 10089 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10090 | Phone phone = PhoneFactory.getPhone(i); |
| 10091 | if (phone != null) { |
| 10092 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 10093 | isPhoneAvailable = true; |
| 10094 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10095 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10096 | |
| 10097 | // return true if successfully informed the phone object about the thermal radio power |
| 10098 | // request. |
| 10099 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10100 | } |
| 10101 | |
| 10102 | private int handleDataThrottlingRequest(int subId, |
| 10103 | DataThrottlingRequest dataThrottlingRequest) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10104 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10105 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10106 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10107 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10108 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10109 | } |
| 10110 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10111 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10112 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10113 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10114 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10115 | } |
| 10116 | |
| 10117 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 10118 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10119 | if (isDataThrottlingSupported) { |
| 10120 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10121 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10122 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10123 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10124 | } else if (thermalMitigationResult |
| 10125 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10126 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10127 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10128 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10129 | } |
| 10130 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10131 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10132 | |
| 10133 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10134 | } |
| 10135 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10136 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10137 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10138 | for (String pckg : context.getResources() |
| 10139 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10140 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10141 | } |
| 10142 | } |
| 10143 | |
| 10144 | return sThermalMitigationAllowlistedPackages; |
| 10145 | } |
| 10146 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10147 | private boolean isAnyPhoneInEmergencyState() { |
| 10148 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10149 | if (tm.isInEmergencyCall()) { |
| 10150 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10151 | return true; |
| 10152 | } |
| 10153 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10154 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10155 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10156 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10157 | + phone.isInEcm()); |
| 10158 | return true; |
| 10159 | } |
| 10160 | } |
| 10161 | |
| 10162 | return false; |
| 10163 | } |
| 10164 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10165 | /** |
| 10166 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10167 | * @param packageName name of package to be allowlisted |
| 10168 | * @param context |
| 10169 | */ |
| 10170 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10171 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10172 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10173 | } |
| 10174 | |
| 10175 | /** |
| 10176 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10177 | * @param packageName name of package to remove from allowlist |
| 10178 | * @param context |
| 10179 | */ |
| 10180 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10181 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10182 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10183 | } |
| 10184 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10185 | /** |
| 10186 | * Thermal mitigation request to control functionalities at modem. |
| 10187 | * |
| 10188 | * @param subId the id of the subscription. |
| 10189 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10190 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10191 | * |
| 10192 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10193 | */ |
| 10194 | @Override |
| 10195 | @ThermalMitigationResult |
| 10196 | public int sendThermalMitigationRequest( |
| 10197 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10198 | ThermalMitigationRequest thermalMitigationRequest, |
| 10199 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10200 | enforceModifyPermission(); |
| 10201 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10202 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10203 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10204 | .contains(callingPackage)) { |
| 10205 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10206 | + "calling package: " + callingPackage); |
| 10207 | } |
| 10208 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10209 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10210 | final long identity = Binder.clearCallingIdentity(); |
| 10211 | |
| 10212 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10213 | try { |
| 10214 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10215 | switch (thermalMitigationAction) { |
| 10216 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10217 | thermalMitigationResult = |
| 10218 | handleDataThrottlingRequest(subId, |
| 10219 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 10220 | break; |
| 10221 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10222 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10223 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10224 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10225 | } |
| 10226 | |
| 10227 | // Ensure that radio is on. If not able to power on due to phone being |
| 10228 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10229 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10230 | thermalMitigationResult = |
| 10231 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10232 | break; |
| 10233 | } |
| 10234 | |
| 10235 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 10236 | false); |
| 10237 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10238 | break; |
| 10239 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10240 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10241 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10242 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10243 | } |
| 10244 | |
| 10245 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10246 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10247 | Phone phone = getPhone(subId); |
| 10248 | if (phone == null) { |
| 10249 | thermalMitigationResult = |
| 10250 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10251 | break; |
| 10252 | } |
| 10253 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10254 | TelephonyConnectionService service = |
| 10255 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10256 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10257 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10258 | thermalMitigationResult = |
| 10259 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10260 | break; |
| 10261 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10262 | thermalMitigationResult = |
| 10263 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10264 | break; |
| 10265 | } |
| 10266 | } else { |
| 10267 | thermalMitigationResult = |
| 10268 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10269 | break; |
| 10270 | } |
| 10271 | |
| 10272 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10273 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10274 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10275 | thermalMitigationResult = |
| 10276 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10277 | break; |
| 10278 | } |
| 10279 | thermalMitigationResult = |
| 10280 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10281 | break; |
| 10282 | default: |
| 10283 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10284 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10285 | } |
| 10286 | } catch (IllegalArgumentException e) { |
| 10287 | throw e; |
| 10288 | } catch (Exception e) { |
| 10289 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10290 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10291 | } finally { |
| 10292 | Binder.restoreCallingIdentity(identity); |
| 10293 | } |
| 10294 | |
| 10295 | if (DBG) { |
| 10296 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10297 | + thermalMitigationResult); |
| 10298 | } |
| 10299 | |
| 10300 | return thermalMitigationResult; |
| 10301 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10302 | |
| 10303 | /** |
| 10304 | * Set the GbaService Package Name that Telephony will bind to. |
| 10305 | * |
| 10306 | * @param subId The sim that the GbaService is associated with. |
| 10307 | * @param packageName The name of the package to be replaced with. |
| 10308 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10309 | */ |
| 10310 | @Override |
| 10311 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10312 | enforceModifyPermission(); |
| 10313 | |
| 10314 | final long identity = Binder.clearCallingIdentity(); |
| 10315 | try { |
| 10316 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10317 | } finally { |
| 10318 | Binder.restoreCallingIdentity(identity); |
| 10319 | } |
| 10320 | } |
| 10321 | |
| 10322 | /** |
| 10323 | * Return the package name of the currently bound GbaService. |
| 10324 | * |
| 10325 | * @param subId The sim that the GbaService is associated with. |
| 10326 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10327 | */ |
| 10328 | @Override |
| 10329 | public String getBoundGbaService(int subId) { |
| 10330 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10331 | |
| 10332 | final long identity = Binder.clearCallingIdentity(); |
| 10333 | try { |
| 10334 | return getGbaManager(subId).getServicePackage(); |
| 10335 | } finally { |
| 10336 | Binder.restoreCallingIdentity(identity); |
| 10337 | } |
| 10338 | } |
| 10339 | |
| 10340 | /** |
| 10341 | * Set the release time for telephony to unbind GbaService. |
| 10342 | * |
| 10343 | * @param subId The sim that the GbaService is associated with. |
| 10344 | * @param interval The release time to unbind GbaService by millisecond. |
| 10345 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10346 | */ |
| 10347 | @Override |
| 10348 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10349 | enforceModifyPermission(); |
| 10350 | |
| 10351 | final long identity = Binder.clearCallingIdentity(); |
| 10352 | try { |
| 10353 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10354 | } finally { |
| 10355 | Binder.restoreCallingIdentity(identity); |
| 10356 | } |
| 10357 | } |
| 10358 | |
| 10359 | /** |
| 10360 | * Return the release time for telephony to unbind GbaService. |
| 10361 | * |
| 10362 | * @param subId The sim that the GbaService is associated with. |
| 10363 | * @return The release time to unbind GbaService by millisecond. |
| 10364 | */ |
| 10365 | @Override |
| 10366 | public int getGbaReleaseTime(int subId) { |
| 10367 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10368 | |
| 10369 | final long identity = Binder.clearCallingIdentity(); |
| 10370 | try { |
| 10371 | return getGbaManager(subId).getReleaseTime(); |
| 10372 | } finally { |
| 10373 | Binder.restoreCallingIdentity(identity); |
| 10374 | } |
| 10375 | } |
| 10376 | |
| 10377 | private GbaManager getGbaManager(int subId) { |
| 10378 | GbaManager instance = GbaManager.getInstance(subId); |
| 10379 | if (instance == null) { |
| 10380 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10381 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10382 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10383 | } |
| 10384 | return instance; |
| 10385 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10386 | |
| 10387 | /** |
| 10388 | * indicate whether the device and the carrier can support |
| 10389 | * RCS VoLTE single registration. |
| 10390 | */ |
| 10391 | @Override |
| 10392 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10393 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10394 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10395 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10396 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10397 | |
| 10398 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10399 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10400 | } |
| 10401 | |
| 10402 | final long identity = Binder.clearCallingIdentity(); |
| 10403 | try { |
| 10404 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10405 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10406 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10407 | if (isCapable != null) { |
| 10408 | return isCapable; |
| 10409 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10410 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10411 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10412 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10413 | } finally { |
| 10414 | Binder.restoreCallingIdentity(identity); |
| 10415 | } |
| 10416 | } |
| 10417 | |
| 10418 | /** |
| 10419 | * Register RCS provisioning callback. |
| 10420 | */ |
| 10421 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10422 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10423 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10424 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10425 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10426 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10427 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10428 | |
| 10429 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10430 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10431 | } |
| 10432 | if (!isImsAvailableOnDevice()) { |
| 10433 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10434 | "IMS not available on device."); |
| 10435 | } |
| 10436 | |
| 10437 | final long identity = Binder.clearCallingIdentity(); |
| 10438 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10439 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10440 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10441 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10442 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10443 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10444 | } finally { |
| 10445 | Binder.restoreCallingIdentity(identity); |
| 10446 | } |
| 10447 | } |
| 10448 | |
| 10449 | /** |
| 10450 | * Unregister RCS provisioning callback. |
| 10451 | */ |
| 10452 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10453 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10454 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10455 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10456 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10457 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10458 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10459 | |
| 10460 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10461 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10462 | } |
| 10463 | if (!isImsAvailableOnDevice()) { |
| 10464 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10465 | "IMS not available on device."); |
| 10466 | } |
| 10467 | |
| 10468 | final long identity = Binder.clearCallingIdentity(); |
| 10469 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10470 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10471 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10472 | } finally { |
| 10473 | Binder.restoreCallingIdentity(identity); |
| 10474 | } |
| 10475 | } |
| 10476 | |
| 10477 | /** |
| 10478 | * trigger RCS reconfiguration. |
| 10479 | */ |
| 10480 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10481 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10482 | "triggerRcsReconfiguration", |
| 10483 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10484 | |
| 10485 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10486 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10487 | } |
| 10488 | if (!isImsAvailableOnDevice()) { |
| 10489 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10490 | "IMS not available on device."); |
| 10491 | } |
| 10492 | |
| 10493 | final long identity = Binder.clearCallingIdentity(); |
| 10494 | try { |
| 10495 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10496 | } finally { |
| 10497 | Binder.restoreCallingIdentity(identity); |
| 10498 | } |
| 10499 | } |
| 10500 | |
| 10501 | /** |
| 10502 | * Provide the client configuration parameters of the RCS application. |
| 10503 | */ |
| 10504 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10505 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10506 | "setRcsClientConfiguration", |
| 10507 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10508 | |
| 10509 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10510 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10511 | } |
| 10512 | if (!isImsAvailableOnDevice()) { |
| 10513 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10514 | "IMS not available on device."); |
| 10515 | } |
| 10516 | |
| 10517 | final long identity = Binder.clearCallingIdentity(); |
| 10518 | |
| 10519 | try { |
| 10520 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10521 | if (configBinder == null) { |
| 10522 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10523 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10524 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10525 | } else { |
| 10526 | configBinder.setRcsClientConfiguration(rcc); |
| 10527 | } |
joonhunshin | fa31464 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 10528 | |
| 10529 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 10530 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10531 | } catch (RemoteException e) { |
| 10532 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10533 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10534 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10535 | } finally { |
| 10536 | Binder.restoreCallingIdentity(identity); |
| 10537 | } |
| 10538 | } |
| 10539 | |
| 10540 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10541 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10542 | */ |
| 10543 | @Override |
| 10544 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10545 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10546 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10547 | |
| 10548 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10549 | } |
| 10550 | |
| 10551 | /** |
| 10552 | * Gets the test mode for RCS VoLTE single registration. |
| 10553 | */ |
| 10554 | @Override |
| 10555 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10556 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10557 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10558 | |
| 10559 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10560 | } |
| 10561 | |
| 10562 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10563 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10564 | */ |
| 10565 | @Override |
| 10566 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10567 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10568 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10569 | enforceModifyPermission(); |
| 10570 | |
| 10571 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10572 | : Boolean.parseBoolean(enabledStr); |
| 10573 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10574 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10575 | } |
| 10576 | |
| 10577 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10578 | * Sends a device to device communication message. Only usable via shell. |
| 10579 | * @param message message to send. |
| 10580 | * @param value message value. |
| 10581 | */ |
| 10582 | @Override |
| 10583 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10584 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10585 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10586 | enforceModifyPermission(); |
| 10587 | |
| 10588 | final long identity = Binder.clearCallingIdentity(); |
| 10589 | try { |
| 10590 | TelephonyConnectionService service = |
| 10591 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10592 | if (service == null) { |
| 10593 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10594 | return; |
| 10595 | } |
| 10596 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10597 | } finally { |
| 10598 | Binder.restoreCallingIdentity(identity); |
| 10599 | } |
| 10600 | } |
| 10601 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10602 | /** |
| 10603 | * Sets the specified device to device transport active. |
| 10604 | * @param transport The transport to set active. |
| 10605 | */ |
| 10606 | @Override |
| 10607 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10608 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10609 | "setActiveDeviceToDeviceTransport"); |
| 10610 | enforceModifyPermission(); |
| 10611 | |
| 10612 | final long identity = Binder.clearCallingIdentity(); |
| 10613 | try { |
| 10614 | TelephonyConnectionService service = |
| 10615 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10616 | if (service == null) { |
| 10617 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10618 | return; |
| 10619 | } |
| 10620 | service.setActiveDeviceToDeviceTransport(transport); |
| 10621 | } finally { |
| 10622 | Binder.restoreCallingIdentity(identity); |
| 10623 | } |
| 10624 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10625 | |
Tyler Gunn | d457521 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10626 | @Override |
| 10627 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10628 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10629 | "setDeviceToDeviceForceEnabled"); |
| 10630 | |
| 10631 | final long identity = Binder.clearCallingIdentity(); |
| 10632 | try { |
| 10633 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10634 | p -> { |
| 10635 | Phone thePhone = p.getImsPhone(); |
| 10636 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10637 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10638 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10639 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10640 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10641 | (ImsPhoneCallTracker) tracker; |
| 10642 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10643 | } |
| 10644 | } |
| 10645 | } |
| 10646 | ); |
| 10647 | } finally { |
| 10648 | Binder.restoreCallingIdentity(identity); |
| 10649 | } |
| 10650 | } |
| 10651 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10652 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10653 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10654 | */ |
| 10655 | @Override |
| 10656 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10657 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10658 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10659 | } |
| 10660 | |
| 10661 | /** |
| 10662 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10663 | */ |
| 10664 | @Override |
| 10665 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10666 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10667 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10668 | enforceModifyPermission(); |
| 10669 | |
| 10670 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10671 | : Boolean.parseBoolean(enabledStr); |
| 10672 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10673 | subId, enabled); |
| 10674 | } |
| 10675 | |
| 10676 | /** |
| 10677 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10678 | */ |
| 10679 | @Override |
| 10680 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10681 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10682 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10683 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10684 | |
| 10685 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 10686 | * Overrides the ims feature validation result |
| 10687 | */ |
| 10688 | @Override |
| 10689 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 10690 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10691 | "setImsFeatureValidationOverride"); |
| 10692 | |
| 10693 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10694 | : Boolean.parseBoolean(enabledStr); |
| 10695 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 10696 | subId, enabled); |
| 10697 | } |
| 10698 | |
| 10699 | /** |
| 10700 | * Gets the ims feature validation override value |
| 10701 | */ |
| 10702 | @Override |
| 10703 | public boolean getImsFeatureValidationOverride(int subId) { |
| 10704 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10705 | "getImsFeatureValidationOverride"); |
| 10706 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 10707 | } |
| 10708 | |
| 10709 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10710 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10711 | * their mobile plan. |
| 10712 | */ |
| 10713 | @Override |
| 10714 | public String getMobileProvisioningUrl() { |
| 10715 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10716 | final long identity = Binder.clearCallingIdentity(); |
| 10717 | try { |
| 10718 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10719 | } finally { |
| 10720 | Binder.restoreCallingIdentity(identity); |
| 10721 | } |
| 10722 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10723 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10724 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10725 | * Get the EAB contact from the EAB database. |
| 10726 | */ |
| 10727 | @Override |
| 10728 | public String getContactFromEab(String contact) { |
| 10729 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10730 | enforceModifyPermission(); |
| 10731 | final long identity = Binder.clearCallingIdentity(); |
| 10732 | try { |
| 10733 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10734 | } finally { |
| 10735 | Binder.restoreCallingIdentity(identity); |
| 10736 | } |
| 10737 | } |
| 10738 | |
| 10739 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 10740 | * Get the EAB capability from the EAB database. |
| 10741 | */ |
| 10742 | @Override |
| 10743 | public String getCapabilityFromEab(String contact) { |
| 10744 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 10745 | enforceModifyPermission(); |
| 10746 | final long identity = Binder.clearCallingIdentity(); |
| 10747 | try { |
| 10748 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 10749 | } finally { |
| 10750 | Binder.restoreCallingIdentity(identity); |
| 10751 | } |
| 10752 | } |
| 10753 | |
| 10754 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10755 | * Remove the EAB contacts from the EAB database. |
| 10756 | */ |
| 10757 | @Override |
| 10758 | public int removeContactFromEab(int subId, String contacts) { |
| 10759 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10760 | enforceModifyPermission(); |
| 10761 | final long identity = Binder.clearCallingIdentity(); |
| 10762 | try { |
| 10763 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10764 | } finally { |
| 10765 | Binder.restoreCallingIdentity(identity); |
| 10766 | } |
| 10767 | } |
| 10768 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10769 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10770 | public boolean getDeviceUceEnabled() { |
| 10771 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10772 | final long identity = Binder.clearCallingIdentity(); |
| 10773 | try { |
| 10774 | return mApp.getDeviceUceEnabled(); |
| 10775 | } finally { |
| 10776 | Binder.restoreCallingIdentity(identity); |
| 10777 | } |
| 10778 | } |
| 10779 | |
| 10780 | @Override |
| 10781 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10782 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10783 | final long identity = Binder.clearCallingIdentity(); |
| 10784 | try { |
| 10785 | mApp.setDeviceUceEnabled(isEnabled); |
| 10786 | } finally { |
| 10787 | Binder.restoreCallingIdentity(identity); |
| 10788 | } |
| 10789 | } |
| 10790 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10791 | /** |
| 10792 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10793 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10794 | */ |
| 10795 | // Used for SHELL command only right now. |
| 10796 | @Override |
| 10797 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 10798 | List<String> featureTags) { |
| 10799 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10800 | "addUceRegistrationOverrideShell"); |
| 10801 | final long identity = Binder.clearCallingIdentity(); |
| 10802 | try { |
| 10803 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 10804 | new ArraySet<>(featureTags)); |
| 10805 | } catch (ImsException e) { |
| 10806 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10807 | } finally { |
| 10808 | Binder.restoreCallingIdentity(identity); |
| 10809 | } |
| 10810 | } |
| 10811 | |
| 10812 | /** |
| 10813 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10814 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10815 | */ |
| 10816 | // Used for SHELL command only right now. |
| 10817 | @Override |
| 10818 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 10819 | List<String> featureTags) { |
| 10820 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10821 | "removeUceRegistrationOverrideShell"); |
| 10822 | final long identity = Binder.clearCallingIdentity(); |
| 10823 | try { |
| 10824 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 10825 | new ArraySet<>(featureTags)); |
| 10826 | } catch (ImsException e) { |
| 10827 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10828 | } finally { |
| 10829 | Binder.restoreCallingIdentity(identity); |
| 10830 | } |
| 10831 | } |
| 10832 | |
| 10833 | /** |
| 10834 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 10835 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10836 | */ |
| 10837 | // Used for SHELL command only right now. |
| 10838 | @Override |
| 10839 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 10840 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10841 | "clearUceRegistrationOverrideShell"); |
| 10842 | final long identity = Binder.clearCallingIdentity(); |
| 10843 | try { |
| 10844 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 10845 | } catch (ImsException e) { |
| 10846 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10847 | } finally { |
| 10848 | Binder.restoreCallingIdentity(identity); |
| 10849 | } |
| 10850 | } |
| 10851 | |
| 10852 | /** |
| 10853 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10854 | */ |
| 10855 | // Used for SHELL command only right now. |
| 10856 | @Override |
| 10857 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 10858 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10859 | "getLatestRcsContactUceCapabilityShell"); |
| 10860 | final long identity = Binder.clearCallingIdentity(); |
| 10861 | try { |
| 10862 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 10863 | } catch (ImsException e) { |
| 10864 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10865 | } finally { |
| 10866 | Binder.restoreCallingIdentity(identity); |
| 10867 | } |
| 10868 | } |
| 10869 | |
| 10870 | /** |
| 10871 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 10872 | * device does not have an active PUBLISH. |
| 10873 | */ |
| 10874 | // Used for SHELL command only right now. |
| 10875 | @Override |
| 10876 | public String getLastUcePidfXmlShell(int subId) { |
| 10877 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 10878 | final long identity = Binder.clearCallingIdentity(); |
| 10879 | try { |
| 10880 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 10881 | } catch (ImsException e) { |
| 10882 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10883 | } finally { |
| 10884 | Binder.restoreCallingIdentity(identity); |
| 10885 | } |
| 10886 | } |
| 10887 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 10888 | /** |
| 10889 | * Remove UCE requests cannot be sent to the network status. |
| 10890 | */ |
| 10891 | // Used for SHELL command only right now. |
| 10892 | @Override |
| 10893 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 10894 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 10895 | final long identity = Binder.clearCallingIdentity(); |
| 10896 | try { |
| 10897 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 10898 | } catch (ImsException e) { |
| 10899 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10900 | } finally { |
| 10901 | Binder.restoreCallingIdentity(identity); |
| 10902 | } |
| 10903 | } |
| 10904 | |
James.cf Lin | 0fc71b0 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 10905 | /** |
| 10906 | * Remove UCE requests cannot be sent to the network status. |
| 10907 | */ |
| 10908 | // Used for SHELL command only. |
| 10909 | @Override |
| 10910 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 10911 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 10912 | final long identity = Binder.clearCallingIdentity(); |
| 10913 | try { |
| 10914 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 10915 | } catch (ImsException e) { |
| 10916 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10917 | } finally { |
| 10918 | Binder.restoreCallingIdentity(identity); |
| 10919 | } |
| 10920 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10921 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10922 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10923 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10924 | String callingPackage) { |
| 10925 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10926 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 10927 | |
| 10928 | final int callingUid = Binder.getCallingUid(); |
| 10929 | // Verify that tha callingPackage belongs to the calling UID |
| 10930 | mApp.getSystemService(AppOpsManager.class) |
| 10931 | .checkPackage(callingUid, callingPackage); |
| 10932 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 10933 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10934 | |
| 10935 | final long identity = Binder.clearCallingIdentity(); |
| 10936 | try { |
| 10937 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10938 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10939 | |
| 10940 | if (result instanceof IllegalStateException) { |
| 10941 | throw (IllegalStateException) result; |
| 10942 | } |
| 10943 | } finally { |
| 10944 | Binder.restoreCallingIdentity(identity); |
| 10945 | } |
| 10946 | } |
| 10947 | |
| 10948 | @Override |
| 10949 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10950 | String callingPackage) { |
| 10951 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10952 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 10953 | |
| 10954 | final int callingUid = Binder.getCallingUid(); |
| 10955 | // Verify that tha callingPackage belongs to the calling UID |
| 10956 | mApp.getSystemService(AppOpsManager.class) |
| 10957 | .checkPackage(callingUid, callingPackage); |
| 10958 | |
| 10959 | final long identity = Binder.clearCallingIdentity(); |
| 10960 | try { |
| 10961 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10962 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10963 | |
| 10964 | if (result instanceof IllegalStateException) { |
| 10965 | throw (IllegalStateException) result; |
| 10966 | } |
| 10967 | } finally { |
| 10968 | Binder.restoreCallingIdentity(identity); |
| 10969 | } |
| 10970 | } |
| 10971 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 10972 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 10973 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10974 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 10975 | // phone/system process do not have further restriction on request |
| 10976 | return; |
| 10977 | } |
| 10978 | |
| 10979 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 10980 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10981 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 10982 | context.enforceCallingOrSelfPermission( |
| 10983 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 10984 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10985 | } |
| 10986 | |
| 10987 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 10988 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 10989 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 10990 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 10991 | || info.isEnabled()) { |
| 10992 | throw new IllegalArgumentException( |
| 10993 | "Only system can set hide fields in SignalThresholdInfo"); |
| 10994 | } |
| 10995 | |
| 10996 | // Thresholds length for each RAN need in range. This has been validated in |
| 10997 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 10998 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 10999 | final int[] thresholds = info.getThresholds(); |
| 11000 | Objects.requireNonNull(thresholds); |
| 11001 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11002 | || thresholds.length |
| 11003 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11004 | throw new IllegalArgumentException( |
| 11005 | "thresholds length is out of range: " + thresholds.length); |
| 11006 | } |
| 11007 | } |
| 11008 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11009 | |
| 11010 | /** |
| 11011 | * Gets the current phone capability. |
| 11012 | * |
| 11013 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11014 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11015 | * It's used to evaluate possible phone config change, for example from single |
| 11016 | * SIM device to multi-SIM device. |
| 11017 | */ |
| 11018 | @Override |
| 11019 | public PhoneCapability getPhoneCapability() { |
| 11020 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11021 | final long identity = Binder.clearCallingIdentity(); |
| 11022 | try { |
| 11023 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11024 | } finally { |
| 11025 | Binder.restoreCallingIdentity(identity); |
| 11026 | } |
| 11027 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11028 | |
| 11029 | /** |
| 11030 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11031 | * required to be done shortly after the API is invoked. |
| 11032 | */ |
| 11033 | @Override |
| 11034 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11035 | public int prepareForUnattendedReboot() { |
| 11036 | enforceRebootPermission(); |
| 11037 | |
| 11038 | final long identity = Binder.clearCallingIdentity(); |
| 11039 | try { |
| 11040 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null); |
| 11041 | } finally { |
| 11042 | Binder.restoreCallingIdentity(identity); |
| 11043 | } |
| 11044 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11045 | |
| 11046 | /** |
| 11047 | * Request to get the current slicing configuration including URSP rules and |
| 11048 | * NSSAIs (configured, allowed and rejected). |
| 11049 | * |
| 11050 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11051 | */ |
| 11052 | @Override |
| 11053 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11054 | TelephonyPermissions |
| 11055 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11056 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11057 | |
| 11058 | final long identity = Binder.clearCallingIdentity(); |
| 11059 | try { |
| 11060 | Phone phone = getDefaultPhone(); |
| 11061 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11062 | } finally { |
| 11063 | Binder.restoreCallingIdentity(identity); |
| 11064 | } |
| 11065 | } |
Hunsuk Choi | c7ebc0f | 2021-11-15 23:46:41 +0000 | [diff] [blame] | 11066 | |
| 11067 | /** |
| 11068 | * Register an IMS connection state callback |
| 11069 | */ |
| 11070 | @Override |
| 11071 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11072 | String callingPackage) { |
| 11073 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11074 | // ImsMmTelManager |
| 11075 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11076 | TelephonyPermissions |
| 11077 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11078 | mApp, subId, "registerImsStateCallback"); |
| 11079 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11080 | // ImsRcsManager or SipDelegateManager |
| 11081 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11082 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11083 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11084 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11085 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11086 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11087 | } |
| 11088 | |
| 11089 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11090 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11091 | "IMS not available on device."); |
| 11092 | } |
| 11093 | |
| 11094 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11095 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11096 | } |
| 11097 | |
| 11098 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11099 | if (controller == null) { |
| 11100 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11101 | "IMS not available on device."); |
| 11102 | } |
| 11103 | |
| 11104 | if (callingPackage == null) { |
| 11105 | callingPackage = getCurrentPackageName(); |
| 11106 | } |
| 11107 | |
| 11108 | final long token = Binder.clearCallingIdentity(); |
| 11109 | try { |
| 11110 | int slotId = getSlotIndexOrException(subId); |
| 11111 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
| 11112 | } catch (ImsException e) { |
| 11113 | throw new ServiceSpecificException(e.getCode()); |
| 11114 | } finally { |
| 11115 | Binder.restoreCallingIdentity(token); |
| 11116 | } |
| 11117 | } |
| 11118 | |
| 11119 | /** |
| 11120 | * Unregister an IMS connection state callback |
| 11121 | */ |
| 11122 | @Override |
| 11123 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11124 | final long token = Binder.clearCallingIdentity(); |
| 11125 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11126 | if (controller == null) { |
| 11127 | return; |
| 11128 | } |
| 11129 | try { |
| 11130 | controller.unregisterImsStateCallback(cb); |
| 11131 | } finally { |
| 11132 | Binder.restoreCallingIdentity(token); |
| 11133 | } |
| 11134 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11135 | |
| 11136 | /** |
| 11137 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11138 | * |
| 11139 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11140 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11141 | * SecurityException. |
| 11142 | * If there is current registered network this value will be same as the registered cell |
| 11143 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11144 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11145 | * it will be cleared and null will be returned. |
| 11146 | * |
| 11147 | */ |
| 11148 | @Override |
| 11149 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11150 | String callingFeatureId) { |
| 11151 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11152 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11153 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11154 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11155 | .setCallingPackage(callingPackage) |
| 11156 | .setCallingFeatureId(callingFeatureId) |
| 11157 | .setCallingPid(Binder.getCallingPid()) |
| 11158 | .setCallingUid(Binder.getCallingUid()) |
| 11159 | .setMethod("getLastKnownCellIdentity") |
| 11160 | .setLogAsInfo(true) |
| 11161 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11162 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11163 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11164 | .build()); |
| 11165 | |
| 11166 | boolean hasFinePermission = |
| 11167 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11168 | if (!hasFinePermission |
| 11169 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11170 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
| 11171 | + "and BIND_CONNECTION_SERVICE permission."); |
| 11172 | } |
| 11173 | |
| 11174 | final long identity = Binder.clearCallingIdentity(); |
| 11175 | try { |
| 11176 | Phone phone = getPhone(subId); |
| 11177 | if (phone == null) return null; |
| 11178 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 11179 | if (sst == null) return null; |
| 11180 | return sst.getLastKnownCellIdentity(); |
| 11181 | } finally { |
| 11182 | Binder.restoreCallingIdentity(identity); |
| 11183 | } |
| 11184 | } |
jimsun | 38340bf | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11185 | |
| 11186 | /** |
| 11187 | * Sets the modem service class Name that Telephony will bind to. |
| 11188 | * |
| 11189 | * @param serviceName The class name of the modem service. |
| 11190 | * @return true if the operation is succeed, otherwise false. |
| 11191 | */ |
| 11192 | public boolean setModemService(String serviceName) { |
| 11193 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11194 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11195 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 11196 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11197 | "setModemService"); |
| 11198 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11199 | } |
| 11200 | |
| 11201 | /** |
| 11202 | * Return the class name of the currently bounded modem service. |
| 11203 | * |
| 11204 | * @return the class name of the modem service. |
| 11205 | */ |
| 11206 | public String getModemService() { |
| 11207 | String result; |
| 11208 | Log.d(LOG_TAG, "getModemService"); |
| 11209 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11210 | TelephonyPermissions |
| 11211 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11212 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11213 | "getModemService"); |
| 11214 | result = mPhoneConfigurationManager.getModemService(); |
| 11215 | Log.d(LOG_TAG, "result = " + result); |
| 11216 | return result; |
| 11217 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 11218 | } |