Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| 20 | |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 22 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 23 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 24 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 25 | import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 26 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 27 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 28 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 29 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 30 | import android.annotation.Nullable; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 31 | import android.annotation.RequiresPermission; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 32 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 33 | import android.app.PendingIntent; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 34 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 35 | import android.app.role.RoleManager; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 36 | import android.compat.Compatibility; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 37 | import android.compat.annotation.ChangeId; |
| 38 | import android.compat.annotation.EnabledSince; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 39 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 40 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.content.Context; |
| 42 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 43 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 44 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 45 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 46 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 47 | import android.net.Uri; |
| 48 | import android.os.AsyncResult; |
| 49 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 50 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 51 | import android.os.Bundle; |
| 52 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 53 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 54 | import android.os.Looper; |
| 55 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 56 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 57 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 58 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 59 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 60 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 61 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 62 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 63 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 64 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 65 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 66 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 67 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 68 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 69 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 70 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 71 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 72 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 73 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 74 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 75 | import android.telecom.TelecomManager; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 76 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 77 | import android.telephony.Annotation.ThermalMitigationResult; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 78 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 79 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 80 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 81 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 82 | import android.telephony.CellIdentityCdma; |
| 83 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 84 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 85 | import android.telephony.CellInfoGsm; |
| 86 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 87 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 88 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 89 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 90 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 91 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 92 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 93 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 94 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 95 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 96 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 97 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 98 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 99 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 100 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 101 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 102 | import android.telephony.SignalStrengthUpdateRequest; |
| 103 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 104 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 105 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 106 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 107 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 108 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 109 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 110 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 111 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 112 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 113 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 114 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 115 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 116 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 117 | import android.telephony.data.ApnSetting; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 118 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 119 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 120 | import android.telephony.gba.GbaAuthRequest; |
| 121 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 122 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 123 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 124 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 125 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 126 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame^] | 127 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 128 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 129 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 130 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 131 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 132 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 133 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 134 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 135 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 136 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 137 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 138 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 139 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 140 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 141 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 142 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 143 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 144 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 145 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 146 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 147 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 148 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 149 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.CallTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 160 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 161 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 163 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 165 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 166 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.IccCard; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 174 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 179 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 180 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 181 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 183 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 184 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 185 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 186 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 187 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 188 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 189 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 190 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 191 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 192 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 193 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 194 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 195 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 196 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 197 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 198 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 199 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 200 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 201 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 202 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 203 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 204 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 205 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 206 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 207 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 208 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 209 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 210 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 211 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 212 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 213 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 214 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 215 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 216 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 217 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 218 | import com.android.services.telephony.TelecomAccountRegistry; |
| 219 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 220 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 221 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 222 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 223 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 224 | import java.io.IOException; |
| 225 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 226 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 227 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 228 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 229 | import java.util.Collection; |
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 | daf060f | 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 |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 416 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 417 | /** |
| 418 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 419 | * one ICCID active at the same time. |
| 420 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 421 | * |
| 422 | * @hide |
| 423 | */ |
| 424 | @ChangeId |
| 425 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 426 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 427 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 428 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 429 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 430 | * operation fails. |
| 431 | */ |
| 432 | @ChangeId |
| 433 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 434 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 435 | |
| 436 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 437 | * A request object to use for transmitting data to an ICC. |
| 438 | */ |
| 439 | private static final class IccAPDUArgument { |
| 440 | public int channel, cla, command, p1, p2, p3; |
| 441 | public String data; |
| 442 | |
| 443 | public IccAPDUArgument(int channel, int cla, int command, |
| 444 | int p1, int p2, int p3, String data) { |
| 445 | this.channel = channel; |
| 446 | this.cla = cla; |
| 447 | this.command = command; |
| 448 | this.p1 = p1; |
| 449 | this.p2 = p2; |
| 450 | this.p3 = p3; |
| 451 | this.data = data; |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 456 | * A request object to use for transmitting data to an ICC. |
| 457 | */ |
| 458 | private static final class ManualNetworkSelectionArgument { |
| 459 | public OperatorInfo operatorInfo; |
| 460 | public boolean persistSelection; |
| 461 | |
| 462 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 463 | this.operatorInfo = operatorInfo; |
| 464 | this.persistSelection = persistSelection; |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 469 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 470 | * request after sending. The main thread will notify the request when it is complete. |
| 471 | */ |
| 472 | private static final class MainThreadRequest { |
| 473 | /** The argument to use for the request */ |
| 474 | public Object argument; |
| 475 | /** The result of the request that is run on the main thread */ |
| 476 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 477 | // The subscriber id that this request applies to. Defaults to |
| 478 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 479 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 480 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 481 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 482 | public Phone phone; |
| 483 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 484 | public WorkSource workSource; |
| 485 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 486 | public MainThreadRequest(Object argument) { |
| 487 | this.argument = argument; |
| 488 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 489 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 490 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 491 | this.argument = argument; |
| 492 | if (phone != null) { |
| 493 | this.phone = phone; |
| 494 | } |
| 495 | this.workSource = workSource; |
| 496 | } |
| 497 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 498 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 499 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 500 | if (subId != null) { |
| 501 | this.subId = subId; |
| 502 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 503 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 504 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 505 | } |
| 506 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 507 | private static final class IncomingThirdPartyCallArgs { |
| 508 | public final ComponentName component; |
| 509 | public final String callId; |
| 510 | public final String callerDisplayName; |
| 511 | |
| 512 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 513 | String callerDisplayName) { |
| 514 | this.component = component; |
| 515 | this.callId = callId; |
| 516 | this.callerDisplayName = callerDisplayName; |
| 517 | } |
| 518 | } |
| 519 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 520 | /** |
| 521 | * A handler that processes messages on the main thread in the phone process. Since many |
| 522 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 523 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 524 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 525 | * on, which will be notified when the operation completes and will contain the result of the |
| 526 | * request. |
| 527 | * |
| 528 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 529 | * note that request.result must be set to something non-null for the calling thread to |
| 530 | * unblock. |
| 531 | */ |
| 532 | private final class MainThreadHandler extends Handler { |
| 533 | @Override |
| 534 | public void handleMessage(Message msg) { |
| 535 | MainThreadRequest request; |
| 536 | Message onCompleted; |
| 537 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 538 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 539 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 540 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 541 | |
| 542 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 543 | case CMD_HANDLE_USSD_REQUEST: { |
| 544 | request = (MainThreadRequest) msg.obj; |
| 545 | final Phone phone = getPhoneFromRequest(request); |
| 546 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 547 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 548 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 549 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 550 | if (!isUssdApiAllowed(request.subId)) { |
| 551 | // Carrier does not support use of this API, return failure. |
| 552 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 553 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 554 | Bundle returnData = new Bundle(); |
| 555 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 556 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 557 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 558 | request.result = true; |
| 559 | notifyRequester(request); |
| 560 | return; |
| 561 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 562 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 563 | try { |
| 564 | request.result = phone != null |
| 565 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 566 | } catch (CallStateException cse) { |
| 567 | request.result = false; |
| 568 | } |
| 569 | // Wake up the requesting thread |
| 570 | notifyRequester(request); |
| 571 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 574 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 575 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 576 | final Phone phone = getPhoneFromRequest(request); |
| 577 | request.result = phone != null ? |
| 578 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 579 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 580 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 581 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 582 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 583 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 584 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 585 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 586 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 587 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 588 | uiccPort = getUiccPortFromRequest(request); |
| 589 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 590 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 591 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 592 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 593 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 594 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 595 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 596 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 597 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 598 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 599 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 600 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 601 | break; |
| 602 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 603 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 604 | ar = (AsyncResult) msg.obj; |
| 605 | request = (MainThreadRequest) ar.userObj; |
| 606 | if (ar.exception == null && ar.result != null) { |
| 607 | request.result = ar.result; |
| 608 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 609 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 610 | if (ar.result == null) { |
| 611 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 612 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 613 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 614 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 615 | } else { |
| 616 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 617 | } |
| 618 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 619 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 620 | break; |
| 621 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 622 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 623 | request = (MainThreadRequest) msg.obj; |
| 624 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 625 | uiccPort = getUiccPortFromRequest(request); |
| 626 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 627 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 628 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 629 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 630 | } else { |
| 631 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 632 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 633 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 634 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 635 | iccArgument.p2, |
| 636 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 637 | } |
| 638 | break; |
| 639 | |
| 640 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 641 | ar = (AsyncResult) msg.obj; |
| 642 | request = (MainThreadRequest) ar.userObj; |
| 643 | if (ar.exception == null && ar.result != null) { |
| 644 | request.result = ar.result; |
| 645 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 646 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 647 | if (ar.result == null) { |
| 648 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 649 | } else if (ar.exception instanceof CommandException) { |
| 650 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 651 | ar.exception); |
| 652 | } else { |
| 653 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 654 | } |
| 655 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 656 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 657 | break; |
| 658 | |
| 659 | case CMD_EXCHANGE_SIM_IO: |
| 660 | request = (MainThreadRequest) msg.obj; |
| 661 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 662 | uiccPort = getUiccPortFromRequest(request); |
| 663 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 664 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 665 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 666 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 667 | } else { |
| 668 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 669 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 670 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 671 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 672 | iccArgument.data, onCompleted); |
| 673 | } |
| 674 | break; |
| 675 | |
| 676 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 677 | ar = (AsyncResult) msg.obj; |
| 678 | request = (MainThreadRequest) ar.userObj; |
| 679 | if (ar.exception == null && ar.result != null) { |
| 680 | request.result = ar.result; |
| 681 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 682 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 683 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 684 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 685 | break; |
| 686 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 687 | case CMD_SEND_ENVELOPE: |
| 688 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 689 | uiccPort = getUiccPortFromRequest(request); |
| 690 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 691 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 692 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 693 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 694 | } else { |
| 695 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 696 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 697 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 698 | break; |
| 699 | |
| 700 | case EVENT_SEND_ENVELOPE_DONE: |
| 701 | ar = (AsyncResult) msg.obj; |
| 702 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 703 | if (ar.exception == null && ar.result != null) { |
| 704 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 705 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 706 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 707 | if (ar.result == null) { |
| 708 | loge("sendEnvelopeWithStatus: Empty response"); |
| 709 | } else if (ar.exception instanceof CommandException) { |
| 710 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 711 | ar.exception); |
| 712 | } else { |
| 713 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 714 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 715 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 716 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 717 | break; |
| 718 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 719 | case CMD_OPEN_CHANNEL: |
| 720 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 721 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 722 | IccLogicalChannelRequest openChannelRequest = |
| 723 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 724 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 725 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 726 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 727 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 728 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 729 | } else { |
| 730 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 731 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 732 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 733 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 734 | break; |
| 735 | |
| 736 | case EVENT_OPEN_CHANNEL_DONE: |
| 737 | ar = (AsyncResult) msg.obj; |
| 738 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 739 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 740 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 741 | int[] result = (int[]) ar.result; |
| 742 | int channelId = result[0]; |
| 743 | byte[] selectResponse = null; |
| 744 | if (result.length > 1) { |
| 745 | selectResponse = new byte[result.length - 1]; |
| 746 | for (int i = 1; i < result.length; ++i) { |
| 747 | selectResponse[i - 1] = (byte) result[i]; |
| 748 | } |
| 749 | } |
| 750 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 751 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 752 | |
| 753 | uiccPort = getUiccPortFromRequest(request); |
| 754 | IccLogicalChannelRequest channelRequest = |
| 755 | (IccLogicalChannelRequest) request.argument; |
| 756 | channelRequest.channel = channelId; |
| 757 | uiccPort.onLogicalChannelOpened(channelRequest); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 758 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 759 | if (ar.result == null) { |
| 760 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 761 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 762 | if (ar.exception != null) { |
| 763 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 764 | } |
| 765 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 766 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 767 | if (ar.exception instanceof CommandException) { |
| 768 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 769 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 770 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 771 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 772 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 773 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 774 | } |
| 775 | } |
| 776 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 777 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 778 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 779 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 780 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 781 | break; |
| 782 | |
| 783 | case CMD_CLOSE_CHANNEL: |
| 784 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 785 | uiccPort = getUiccPortFromRequest(request); |
| 786 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 787 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 788 | // before this feature is enabled, this API should only return false if |
| 789 | // the operation fails instead of throwing runtime exception for |
| 790 | // backward-compatibility. |
| 791 | if (Compatibility.isChangeEnabled(ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE)) { |
| 792 | request.result = new IllegalArgumentException( |
| 793 | "iccCloseLogicalChannel: No UICC"); |
| 794 | } else { |
| 795 | request.result = false; |
| 796 | } |
| 797 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 798 | } else { |
| 799 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 800 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 801 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 802 | break; |
| 803 | |
| 804 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 805 | ar = (AsyncResult) msg.obj; |
| 806 | request = (MainThreadRequest) ar.userObj; |
| 807 | if (ar.exception == null) { |
| 808 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 809 | uiccPort = getUiccPortFromRequest(request); |
| 810 | final int channelId = (Integer) request.argument; |
| 811 | uiccPort.onLogicalChannelClosed(channelId); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 812 | } else { |
| 813 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 814 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 815 | if (ar.exception instanceof CommandException) { |
| 816 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 817 | CommandException.Error error = |
| 818 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 819 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 820 | // should only throw exceptions from the binder threads. |
| 821 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 822 | "iccCloseLogicalChannel: invalid argument "); |
| 823 | } |
| 824 | } else { |
| 825 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 826 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 827 | // before this feature is enabled, this API should only return false if |
| 828 | // the operation fails instead of throwing runtime exception for |
| 829 | // backward-compatibility. |
| 830 | if (Compatibility.isChangeEnabled(ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE)) |
| 831 | request.result = (exception != null) ? exception : |
| 832 | new IllegalStateException( |
| 833 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 834 | } |
| 835 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 836 | break; |
| 837 | |
| 838 | case CMD_NV_READ_ITEM: |
| 839 | request = (MainThreadRequest) msg.obj; |
| 840 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 841 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 842 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 843 | break; |
| 844 | |
| 845 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 846 | ar = (AsyncResult) msg.obj; |
| 847 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 848 | if (ar.exception == null && ar.result != null) { |
| 849 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 850 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 851 | request.result = ""; |
| 852 | if (ar.result == null) { |
| 853 | loge("nvReadItem: Empty response"); |
| 854 | } else if (ar.exception instanceof CommandException) { |
| 855 | loge("nvReadItem: CommandException: " + |
| 856 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 857 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 858 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 859 | } |
| 860 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 861 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 862 | break; |
| 863 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 864 | case CMD_NV_WRITE_ITEM: |
| 865 | request = (MainThreadRequest) msg.obj; |
| 866 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 867 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 868 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 869 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 870 | break; |
| 871 | |
| 872 | case EVENT_NV_WRITE_ITEM_DONE: |
| 873 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 874 | break; |
| 875 | |
| 876 | case CMD_NV_WRITE_CDMA_PRL: |
| 877 | request = (MainThreadRequest) msg.obj; |
| 878 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 879 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 880 | break; |
| 881 | |
| 882 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 883 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 884 | break; |
| 885 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 886 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 887 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 888 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 889 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 890 | break; |
| 891 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 892 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 893 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 894 | break; |
| 895 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 896 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 897 | request = (MainThreadRequest) msg.obj; |
| 898 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 899 | request); |
| 900 | Phone phone = getPhoneFromRequest(request); |
| 901 | if (phone != null) { |
| 902 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 903 | } else { |
| 904 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 905 | request.result = false; |
| 906 | notifyRequester(request); |
| 907 | } |
| 908 | break; |
| 909 | } |
| 910 | |
| 911 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 912 | ar = (AsyncResult) msg.obj; |
| 913 | request = (MainThreadRequest) ar.userObj; |
| 914 | if (ar.exception == null && ar.result != null) { |
| 915 | request.result = ar.result; |
| 916 | } else { |
| 917 | // request.result must be set to something non-null |
| 918 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 919 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 920 | request.result = ar.result; |
| 921 | } else { |
| 922 | request.result = false; |
| 923 | } |
| 924 | if (ar.result == null) { |
| 925 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 926 | } else if (ar.exception instanceof CommandException) { |
| 927 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 928 | + ar.exception); |
| 929 | } else { |
| 930 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 931 | } |
| 932 | } |
| 933 | notifyRequester(request); |
| 934 | break; |
| 935 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 936 | case CMD_IS_VONR_ENABLED: { |
| 937 | request = (MainThreadRequest) msg.obj; |
| 938 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 939 | request); |
| 940 | Phone phone = getPhoneFromRequest(request); |
| 941 | if (phone != null) { |
| 942 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 943 | } else { |
| 944 | loge("isVoNrEnabled: No phone object"); |
| 945 | request.result = false; |
| 946 | notifyRequester(request); |
| 947 | } |
| 948 | break; |
| 949 | } |
| 950 | |
| 951 | case EVENT_IS_VONR_ENABLED_DONE: |
| 952 | ar = (AsyncResult) msg.obj; |
| 953 | request = (MainThreadRequest) ar.userObj; |
| 954 | if (ar.exception == null && ar.result != null) { |
| 955 | request.result = ar.result; |
| 956 | } else { |
| 957 | // request.result must be set to something non-null |
| 958 | // for the calling thread to unblock |
| 959 | if (ar.result != null) { |
| 960 | request.result = ar.result; |
| 961 | } else { |
| 962 | request.result = false; |
| 963 | } |
| 964 | if (ar.result == null) { |
| 965 | loge("isVoNrEnabled: Empty response"); |
| 966 | } else if (ar.exception instanceof CommandException) { |
| 967 | loge("isVoNrEnabled: CommandException: " |
| 968 | + ar.exception); |
| 969 | } else { |
| 970 | loge("isVoNrEnabled: Unknown exception"); |
| 971 | } |
| 972 | } |
| 973 | notifyRequester(request); |
| 974 | break; |
| 975 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 976 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 977 | request = (MainThreadRequest) msg.obj; |
| 978 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 979 | Phone phone = getPhoneFromRequest(request); |
| 980 | if (phone != null) { |
| 981 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 982 | request.workSource); |
| 983 | } else { |
| 984 | loge("enableNrDualConnectivity: No phone object"); |
| 985 | request.result = |
| 986 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 987 | notifyRequester(request); |
| 988 | } |
| 989 | break; |
| 990 | } |
| 991 | |
| 992 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 993 | ar = (AsyncResult) msg.obj; |
| 994 | request = (MainThreadRequest) ar.userObj; |
| 995 | if (ar.exception == null) { |
| 996 | request.result = |
| 997 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 998 | } else { |
| 999 | request.result = |
| 1000 | TelephonyManager |
| 1001 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1002 | if (ar.exception instanceof CommandException) { |
| 1003 | CommandException.Error error = |
| 1004 | ((CommandException) (ar.exception)).getCommandError(); |
| 1005 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1006 | request.result = |
| 1007 | TelephonyManager |
| 1008 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1009 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1010 | request.result = |
| 1011 | TelephonyManager |
| 1012 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1013 | } |
| 1014 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1015 | + ar.exception); |
| 1016 | } else { |
| 1017 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1018 | } |
| 1019 | } |
| 1020 | notifyRequester(request); |
| 1021 | break; |
| 1022 | } |
| 1023 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1024 | case CMD_ENABLE_VONR: { |
| 1025 | request = (MainThreadRequest) msg.obj; |
| 1026 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1027 | Phone phone = getPhoneFromRequest(request); |
| 1028 | if (phone != null) { |
| 1029 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1030 | request.workSource); |
| 1031 | } else { |
| 1032 | loge("setVoNrEnabled: No phone object"); |
| 1033 | request.result = |
| 1034 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1035 | notifyRequester(request); |
| 1036 | } |
| 1037 | break; |
| 1038 | } |
| 1039 | |
| 1040 | case EVENT_ENABLE_VONR_DONE: { |
| 1041 | ar = (AsyncResult) msg.obj; |
| 1042 | request = (MainThreadRequest) ar.userObj; |
| 1043 | if (ar.exception == null) { |
| 1044 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1045 | } else { |
| 1046 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1047 | if (ar.exception instanceof CommandException) { |
| 1048 | CommandException.Error error = |
| 1049 | ((CommandException) (ar.exception)).getCommandError(); |
| 1050 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1051 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1052 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1053 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1054 | } else { |
| 1055 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1056 | } |
| 1057 | loge("setVoNrEnabled" + ": CommandException: " |
| 1058 | + ar.exception); |
| 1059 | } else { |
| 1060 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1061 | } |
| 1062 | } |
| 1063 | notifyRequester(request); |
| 1064 | break; |
| 1065 | } |
| 1066 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1067 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1068 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1069 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1070 | request); |
| 1071 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1072 | break; |
| 1073 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1074 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1075 | ar = (AsyncResult) msg.obj; |
| 1076 | request = (MainThreadRequest) ar.userObj; |
| 1077 | if (ar.exception == null && ar.result != null) { |
| 1078 | request.result = ar.result; // Integer |
| 1079 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1080 | // request.result must be set to something non-null |
| 1081 | // for the calling thread to unblock |
| 1082 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1083 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1084 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1085 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1086 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1087 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1088 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1089 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1090 | } |
| 1091 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1092 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1093 | break; |
| 1094 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1095 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1096 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1097 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1098 | request); |
| 1099 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1100 | (Pair<Integer, Long>) request.argument; |
| 1101 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1102 | reasonWithNetworkTypes.first, |
| 1103 | reasonWithNetworkTypes.second, |
| 1104 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1105 | break; |
| 1106 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1107 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1108 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1109 | break; |
| 1110 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1111 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1112 | request = (MainThreadRequest)msg.obj; |
| 1113 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1114 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1115 | break; |
| 1116 | |
| 1117 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1118 | ar = (AsyncResult)msg.obj; |
| 1119 | request = (MainThreadRequest)ar.userObj; |
| 1120 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1121 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1122 | break; |
| 1123 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1124 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1125 | request = (MainThreadRequest) msg.obj; |
| 1126 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1127 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1128 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1129 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1130 | break; |
| 1131 | |
| 1132 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1133 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1134 | break; |
| 1135 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1136 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1137 | request = (MainThreadRequest) msg.obj; |
| 1138 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1139 | request); |
| 1140 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1141 | break; |
| 1142 | |
| 1143 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1144 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1145 | break; |
| 1146 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1147 | case CMD_PERFORM_NETWORK_SCAN: |
| 1148 | request = (MainThreadRequest) msg.obj; |
| 1149 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1150 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1151 | break; |
| 1152 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1153 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1154 | request = (MainThreadRequest) msg.obj; |
| 1155 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1156 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1157 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1158 | request.argument; |
| 1159 | int callForwardingReason = args.first; |
| 1160 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1161 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1162 | } |
| 1163 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1164 | ar = (AsyncResult) msg.obj; |
| 1165 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1166 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1167 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1168 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1169 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1170 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1171 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1172 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1173 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1174 | // any service for voice call. |
| 1175 | if ((callForwardInfo.serviceClass |
| 1176 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1177 | callForwardingInfo = new CallForwardingInfo( |
| 1178 | callForwardInfo.status |
| 1179 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1180 | callForwardInfo.reason, |
| 1181 | callForwardInfo.number, |
| 1182 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1183 | break; |
| 1184 | } |
| 1185 | } |
| 1186 | // Didn't find a call forward info for voice call. |
| 1187 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1188 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1189 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1190 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1191 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1192 | } else { |
| 1193 | if (ar.result == null) { |
| 1194 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1195 | } |
| 1196 | if (ar.exception != null) { |
| 1197 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1198 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1199 | int errorCode = TelephonyManager |
| 1200 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1201 | if (ar.exception instanceof CommandException) { |
| 1202 | CommandException.Error error = |
| 1203 | ((CommandException) (ar.exception)).getCommandError(); |
| 1204 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1205 | errorCode = TelephonyManager |
| 1206 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1207 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1208 | errorCode = TelephonyManager |
| 1209 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1210 | } |
| 1211 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1212 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1213 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1214 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1215 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1216 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1217 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1218 | request = (MainThreadRequest) msg.obj; |
| 1219 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1220 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1221 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1222 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1223 | request.argument).first; |
| 1224 | request.phone.setCallForwardingOption( |
| 1225 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1226 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1227 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1228 | callForwardingInfoToSet.getReason(), |
| 1229 | callForwardingInfoToSet.getNumber(), |
| 1230 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1231 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1232 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1233 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1234 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1235 | ar = (AsyncResult) msg.obj; |
| 1236 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1237 | Consumer<Integer> callback = |
| 1238 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1239 | request.argument).second; |
| 1240 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1241 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1242 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1243 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1244 | if (ar.exception instanceof CommandException) { |
| 1245 | CommandException.Error error = |
| 1246 | ((CommandException) (ar.exception)).getCommandError(); |
| 1247 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1248 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1249 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1250 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1251 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1252 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1253 | } |
| 1254 | } |
| 1255 | callback.accept(errorCode); |
| 1256 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1257 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1258 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1259 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1260 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1261 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1262 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1263 | request = (MainThreadRequest) msg.obj; |
| 1264 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1265 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1266 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1267 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1268 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1269 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1270 | ar = (AsyncResult) msg.obj; |
| 1271 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1272 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1273 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1274 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1275 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1276 | // Service Class is a bit mask per 3gpp 27.007. |
| 1277 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1278 | if (callForwardResults.length > 1 |
| 1279 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1280 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1281 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1282 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1283 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1284 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1285 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1286 | } |
| 1287 | } else { |
| 1288 | if (ar.result == null) { |
| 1289 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1290 | } |
| 1291 | if (ar.exception != null) { |
| 1292 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1293 | } |
| 1294 | if (ar.exception instanceof CommandException) { |
| 1295 | CommandException.Error error = |
| 1296 | ((CommandException) (ar.exception)).getCommandError(); |
| 1297 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1298 | callForwardingStatus = |
| 1299 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1300 | } |
| 1301 | } |
| 1302 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1303 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1304 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1305 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1306 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1307 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1308 | request = (MainThreadRequest) msg.obj; |
| 1309 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1310 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1311 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1312 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1313 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1314 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1315 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1316 | ar = (AsyncResult) msg.obj; |
| 1317 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1318 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1319 | Consumer<Integer> callback = |
| 1320 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1321 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1322 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1323 | if (ar.exception instanceof CommandException) { |
| 1324 | CommandException.Error error = |
| 1325 | ((CommandException) (ar.exception)).getCommandError(); |
| 1326 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1327 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1328 | } else { |
| 1329 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1330 | } |
| 1331 | } else { |
| 1332 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1333 | } |
| 1334 | } else { |
| 1335 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1336 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1337 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1338 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1339 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1340 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1341 | ar = (AsyncResult) msg.obj; |
| 1342 | request = (MainThreadRequest) ar.userObj; |
| 1343 | CellNetworkScanResult cellScanResult; |
| 1344 | if (ar.exception == null && ar.result != null) { |
| 1345 | cellScanResult = new CellNetworkScanResult( |
| 1346 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1347 | (List<OperatorInfo>) ar.result); |
| 1348 | } else { |
| 1349 | if (ar.result == null) { |
| 1350 | loge("getCellNetworkScanResults: Empty response"); |
| 1351 | } |
| 1352 | if (ar.exception != null) { |
| 1353 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1354 | } |
| 1355 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1356 | if (ar.exception instanceof CommandException) { |
| 1357 | CommandException.Error error = |
| 1358 | ((CommandException) (ar.exception)).getCommandError(); |
| 1359 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1360 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1361 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1362 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1363 | } |
| 1364 | } |
| 1365 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1366 | } |
| 1367 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1368 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1369 | break; |
| 1370 | |
| 1371 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1372 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1373 | ManualNetworkSelectionArgument selArg = |
| 1374 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1375 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1376 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1377 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1378 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1379 | break; |
| 1380 | |
| 1381 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1382 | ar = (AsyncResult) msg.obj; |
| 1383 | request = (MainThreadRequest) ar.userObj; |
| 1384 | if (ar.exception == null) { |
| 1385 | request.result = true; |
| 1386 | } else { |
| 1387 | request.result = false; |
| 1388 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1389 | } |
| 1390 | notifyRequester(request); |
| 1391 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1392 | break; |
| 1393 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1394 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1395 | request = (MainThreadRequest) msg.obj; |
| 1396 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1397 | if (defaultPhone != null) { |
| 1398 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1399 | } else { |
| 1400 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1401 | Bundle bundle = new Bundle(); |
| 1402 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1403 | new ModemActivityInfo(0, 0, 0, |
| 1404 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1405 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1406 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1407 | break; |
| 1408 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1409 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1410 | ar = (AsyncResult) msg.obj; |
| 1411 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1412 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1413 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1414 | ModemActivityInfo ret = null; |
| 1415 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1416 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1417 | // Update the last modem activity info and the result of the request. |
| 1418 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1419 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1420 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1421 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1422 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1423 | .getTransmitTimeMillis(); |
| 1424 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1425 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1426 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1427 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1428 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1429 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1430 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1431 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1432 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1433 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1434 | info.getReceiveTimeMillis() |
| 1435 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1436 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1437 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1438 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1439 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1440 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1441 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1442 | } else { |
| 1443 | if (ar.result == null) { |
| 1444 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1445 | error = TelephonyManager.ModemActivityInfoException |
| 1446 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1447 | } else if (ar.exception instanceof CommandException) { |
| 1448 | loge("queryModemActivityInfo: CommandException: " + |
| 1449 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1450 | error = TelephonyManager.ModemActivityInfoException |
| 1451 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1452 | } else { |
| 1453 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1454 | error = TelephonyManager.ModemActivityInfoException |
| 1455 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1456 | } |
| 1457 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1458 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1459 | if (ret != null) { |
| 1460 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1461 | } else { |
| 1462 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1463 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1464 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1465 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1466 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1467 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1468 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1469 | case CMD_SET_ALLOWED_CARRIERS: |
| 1470 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1471 | CarrierRestrictionRules argument = |
| 1472 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1473 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1474 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1475 | break; |
| 1476 | |
| 1477 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1478 | ar = (AsyncResult) msg.obj; |
| 1479 | request = (MainThreadRequest) ar.userObj; |
| 1480 | if (ar.exception == null && ar.result != null) { |
| 1481 | request.result = ar.result; |
| 1482 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1483 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1484 | if (ar.exception instanceof CommandException) { |
| 1485 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1486 | CommandException.Error error = |
| 1487 | ((CommandException) (ar.exception)).getCommandError(); |
| 1488 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1489 | request.result = |
| 1490 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1491 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1492 | } else { |
| 1493 | loge("setAllowedCarriers: Unknown exception"); |
| 1494 | } |
| 1495 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1496 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1497 | break; |
| 1498 | |
| 1499 | case CMD_GET_ALLOWED_CARRIERS: |
| 1500 | request = (MainThreadRequest) msg.obj; |
| 1501 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1502 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1503 | break; |
| 1504 | |
| 1505 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1506 | ar = (AsyncResult) msg.obj; |
| 1507 | request = (MainThreadRequest) ar.userObj; |
| 1508 | if (ar.exception == null && ar.result != null) { |
| 1509 | request.result = ar.result; |
| 1510 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1511 | request.result = new IllegalStateException( |
| 1512 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1513 | if (ar.result == null) { |
| 1514 | loge("getAllowedCarriers: Empty response"); |
| 1515 | } else if (ar.exception instanceof CommandException) { |
| 1516 | loge("getAllowedCarriers: CommandException: " + |
| 1517 | ar.exception); |
| 1518 | } else { |
| 1519 | loge("getAllowedCarriers: Unknown exception"); |
| 1520 | } |
| 1521 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1522 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1523 | break; |
| 1524 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1525 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1526 | ar = (AsyncResult) msg.obj; |
| 1527 | request = (MainThreadRequest) ar.userObj; |
| 1528 | if (ar.exception == null && ar.result != null) { |
| 1529 | request.result = ar.result; |
| 1530 | } else { |
| 1531 | request.result = new IllegalArgumentException( |
| 1532 | "Failed to retrieve Forbidden Plmns"); |
| 1533 | if (ar.result == null) { |
| 1534 | loge("getForbiddenPlmns: Empty response"); |
| 1535 | } else { |
| 1536 | loge("getForbiddenPlmns: Unknown exception"); |
| 1537 | } |
| 1538 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1539 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1540 | break; |
| 1541 | |
| 1542 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1543 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1544 | uiccPort = getUiccPortFromRequest(request); |
| 1545 | if (uiccPort == null) { |
| 1546 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1547 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1548 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1549 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1550 | break; |
| 1551 | } |
| 1552 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1553 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1554 | if (uiccApp == null) { |
| 1555 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1556 | + appType); |
| 1557 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1558 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1559 | break; |
| 1560 | } else { |
| 1561 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1562 | + " specified type -- " + appType); |
| 1563 | } |
| 1564 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1565 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1566 | onCompleted); |
| 1567 | break; |
| 1568 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1569 | case CMD_SWITCH_SLOTS: |
| 1570 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1571 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1572 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1573 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1574 | break; |
| 1575 | |
| 1576 | case EVENT_SWITCH_SLOTS_DONE: |
| 1577 | ar = (AsyncResult) msg.obj; |
| 1578 | request = (MainThreadRequest) ar.userObj; |
| 1579 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1580 | notifyRequester(request); |
| 1581 | break; |
| 1582 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1583 | request = (MainThreadRequest) msg.obj; |
| 1584 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1585 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1586 | break; |
| 1587 | |
| 1588 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1589 | ar = (AsyncResult) msg.obj; |
| 1590 | request = (MainThreadRequest) ar.userObj; |
| 1591 | if (ar.exception != null) { |
| 1592 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1593 | } else { |
| 1594 | int mode = ((int[]) ar.result)[0]; |
| 1595 | if (mode == 0) { |
| 1596 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1597 | } else { |
| 1598 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1599 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1600 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1601 | notifyRequester(request); |
| 1602 | break; |
| 1603 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1604 | request = (MainThreadRequest) msg.obj; |
| 1605 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1606 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1607 | break; |
| 1608 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1609 | ar = (AsyncResult) msg.obj; |
| 1610 | request = (MainThreadRequest) ar.userObj; |
| 1611 | if (ar.exception != null) { |
| 1612 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1613 | } else { |
| 1614 | request.result = ((int[]) ar.result)[0]; |
| 1615 | } |
| 1616 | notifyRequester(request); |
| 1617 | break; |
| 1618 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1619 | request = (MainThreadRequest) msg.obj; |
| 1620 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1621 | int mode = (int) request.argument; |
| 1622 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1623 | break; |
| 1624 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1625 | ar = (AsyncResult) msg.obj; |
| 1626 | request = (MainThreadRequest) ar.userObj; |
| 1627 | request.result = ar.exception == null; |
| 1628 | notifyRequester(request); |
| 1629 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1630 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1631 | request = (MainThreadRequest) msg.obj; |
| 1632 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1633 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1634 | break; |
| 1635 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1636 | ar = (AsyncResult) msg.obj; |
| 1637 | request = (MainThreadRequest) ar.userObj; |
| 1638 | if (ar.exception != null) { |
| 1639 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1640 | } else { |
| 1641 | request.result = ((int[]) ar.result)[0]; |
| 1642 | } |
| 1643 | notifyRequester(request); |
| 1644 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1645 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1646 | request = (MainThreadRequest) msg.obj; |
| 1647 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1648 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1649 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1650 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1651 | break; |
| 1652 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1653 | ar = (AsyncResult) msg.obj; |
| 1654 | request = (MainThreadRequest) ar.userObj; |
| 1655 | request.result = ar.exception == null; |
| 1656 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1657 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1658 | case CMD_GET_ALL_CELL_INFO: |
| 1659 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1660 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1661 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1662 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1663 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1664 | ar = (AsyncResult) msg.obj; |
| 1665 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1666 | // If a timeout occurs, the response will be null |
| 1667 | request.result = (ar.exception == null && ar.result != null) |
| 1668 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1669 | synchronized (request) { |
| 1670 | request.notifyAll(); |
| 1671 | } |
| 1672 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1673 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1674 | request = (MainThreadRequest) msg.obj; |
| 1675 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1676 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1677 | break; |
| 1678 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1679 | ar = (AsyncResult) msg.obj; |
| 1680 | request = (MainThreadRequest) ar.userObj; |
| 1681 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1682 | try { |
| 1683 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1684 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1685 | cb.onError( |
| 1686 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1687 | ar.exception.getClass().getName(), |
| 1688 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1689 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1690 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1691 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1692 | } else { |
| 1693 | // use the result as returned |
| 1694 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1695 | } |
| 1696 | } catch (RemoteException re) { |
| 1697 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1698 | } |
| 1699 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1700 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1701 | request = (MainThreadRequest) msg.obj; |
| 1702 | WorkSource ws = (WorkSource) request.argument; |
| 1703 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1704 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1705 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1706 | } |
| 1707 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1708 | ar = (AsyncResult) msg.obj; |
| 1709 | request = (MainThreadRequest) ar.userObj; |
| 1710 | if (ar.exception == null) { |
| 1711 | request.result = ar.result; |
| 1712 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1713 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1714 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1715 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1716 | } |
| 1717 | |
| 1718 | synchronized (request) { |
| 1719 | request.notifyAll(); |
| 1720 | } |
| 1721 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1722 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1723 | case CMD_MODEM_REBOOT: |
| 1724 | request = (MainThreadRequest) msg.obj; |
| 1725 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1726 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1727 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1728 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1729 | handleNullReturnEvent(msg, "rebootModem"); |
| 1730 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1731 | case CMD_REQUEST_ENABLE_MODEM: |
| 1732 | request = (MainThreadRequest) msg.obj; |
| 1733 | boolean enable = (boolean) request.argument; |
| 1734 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1735 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1736 | PhoneConfigurationManager.getInstance() |
| 1737 | .enablePhone(request.phone, enable, onCompleted); |
| 1738 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1739 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1740 | ar = (AsyncResult) msg.obj; |
| 1741 | request = (MainThreadRequest) ar.userObj; |
| 1742 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1743 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1744 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1745 | if ((boolean) request.result) { |
| 1746 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1747 | updateModemStateMetrics(); |
| 1748 | } else { |
| 1749 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1750 | + ar.exception); |
| 1751 | } |
| 1752 | notifyRequester(request); |
| 1753 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1754 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1755 | case CMD_GET_MODEM_STATUS: |
| 1756 | request = (MainThreadRequest) msg.obj; |
| 1757 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1758 | PhoneConfigurationManager.getInstance() |
| 1759 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1760 | break; |
| 1761 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1762 | ar = (AsyncResult) msg.obj; |
| 1763 | request = (MainThreadRequest) ar.userObj; |
| 1764 | int id = request.phone.getPhoneId(); |
| 1765 | if (ar.exception == null && ar.result != null) { |
| 1766 | request.result = ar.result; |
| 1767 | //update the cache as modem status has changed |
| 1768 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1769 | (boolean) request.result); |
| 1770 | } else { |
| 1771 | // Return true if modem status cannot be retrieved. For most cases, |
| 1772 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1773 | // and disable modem are not supported. Modem is always on. |
| 1774 | // TODO: this should be fixed in R to support a third |
| 1775 | // status UNKNOWN b/131631629 |
| 1776 | request.result = true; |
| 1777 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1778 | + ar.exception); |
| 1779 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1780 | notifyRequester(request); |
| 1781 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1782 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1783 | request = (MainThreadRequest) msg.obj; |
| 1784 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1785 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1786 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1787 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1788 | break; |
| 1789 | } |
| 1790 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1791 | ar = (AsyncResult) msg.obj; |
| 1792 | request = (MainThreadRequest) ar.userObj; |
| 1793 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1794 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1795 | args.second.accept(ar.exception == null); |
| 1796 | notifyRequester(request); |
| 1797 | break; |
| 1798 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1799 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1800 | request = (MainThreadRequest) msg.obj; |
| 1801 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1802 | Phone phone = getPhoneFromRequest(request); |
| 1803 | if (phone != null) { |
| 1804 | phone.getSystemSelectionChannels(onCompleted); |
| 1805 | } else { |
| 1806 | loge("getSystemSelectionChannels: No phone object"); |
| 1807 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1808 | notifyRequester(request); |
| 1809 | } |
| 1810 | break; |
| 1811 | } |
| 1812 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1813 | ar = (AsyncResult) msg.obj; |
| 1814 | request = (MainThreadRequest) ar.userObj; |
| 1815 | if (ar.exception == null && ar.result != null) { |
| 1816 | request.result = ar.result; |
| 1817 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1818 | request.result = new IllegalStateException( |
| 1819 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1820 | if (ar.result == null) { |
| 1821 | loge("getSystemSelectionChannels: Empty response"); |
| 1822 | } else { |
| 1823 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1824 | } |
| 1825 | } |
| 1826 | notifyRequester(request); |
| 1827 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1828 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1829 | ar = (AsyncResult) msg.obj; |
| 1830 | request = (MainThreadRequest) ar.userObj; |
| 1831 | if (ar.exception == null && ar.result != null) { |
| 1832 | request.result = ar.result; |
| 1833 | } else { |
| 1834 | request.result = -1; |
| 1835 | loge("Failed to set Forbidden Plmns"); |
| 1836 | if (ar.result == null) { |
| 1837 | loge("setForbidenPlmns: Empty response"); |
| 1838 | } else if (ar.exception != null) { |
| 1839 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1840 | request.result = -1; |
| 1841 | } else { |
| 1842 | loge("setForbiddenPlmns: Unknown exception"); |
| 1843 | } |
| 1844 | } |
| 1845 | notifyRequester(request); |
| 1846 | break; |
| 1847 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1848 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1849 | uiccPort = getUiccPortFromRequest(request); |
| 1850 | if (uiccPort == null) { |
| 1851 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1852 | request.result = -1; |
| 1853 | notifyRequester(request); |
| 1854 | break; |
| 1855 | } |
| 1856 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1857 | (Pair<Integer, List<String>>) request.argument; |
| 1858 | appType = setFplmnsArgs.first; |
| 1859 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1860 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1861 | if (uiccApp == null) { |
| 1862 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1863 | request.result = -1; |
| 1864 | loge("Failed to get UICC App"); |
| 1865 | notifyRequester(request); |
| 1866 | } else { |
| 1867 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1868 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1869 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1870 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1871 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1872 | case CMD_ERASE_MODEM_CONFIG: |
| 1873 | request = (MainThreadRequest) msg.obj; |
| 1874 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1875 | defaultPhone.eraseModemConfig(onCompleted); |
| 1876 | break; |
| 1877 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1878 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1879 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1880 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1881 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1882 | request = (MainThreadRequest) msg.obj; |
| 1883 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1884 | notifyRequester(request); |
| 1885 | break; |
| 1886 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1887 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1888 | request = (MainThreadRequest) msg.obj; |
| 1889 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1890 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1891 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1892 | changed.first, changed.second, onCompleted); |
| 1893 | break; |
| 1894 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1895 | ar = (AsyncResult) msg.obj; |
| 1896 | request = (MainThreadRequest) ar.userObj; |
| 1897 | if (ar.exception == null) { |
| 1898 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1899 | // If the operation is successful, update the PIN storage |
| 1900 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1901 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1902 | UiccController.getInstance().getPinStorage() |
| 1903 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1904 | } else { |
| 1905 | request.result = msg.arg1; |
| 1906 | } |
| 1907 | notifyRequester(request); |
| 1908 | break; |
| 1909 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1910 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1911 | request = (MainThreadRequest) msg.obj; |
| 1912 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1913 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1914 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1915 | enabled.first, enabled.second, onCompleted); |
| 1916 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1917 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1918 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1919 | ar = (AsyncResult) msg.obj; |
| 1920 | request = (MainThreadRequest) ar.userObj; |
| 1921 | if (ar.exception == null) { |
| 1922 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1923 | // If the operation is successful, update the PIN storage |
| 1924 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1925 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1926 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1927 | UiccController.getInstance().getPinStorage() |
| 1928 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1929 | } else { |
| 1930 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1931 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1932 | } else { |
| 1933 | request.result = msg.arg1; |
| 1934 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1935 | |
| 1936 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1937 | notifyRequester(request); |
| 1938 | break; |
| 1939 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1940 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1941 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1942 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1943 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1944 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1945 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1946 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1947 | |
| 1948 | case CMD_SET_DATA_THROTTLING: { |
| 1949 | request = (MainThreadRequest) msg.obj; |
| 1950 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1951 | DataThrottlingRequest dataThrottlingRequest = |
| 1952 | (DataThrottlingRequest) request.argument; |
| 1953 | Phone phone = getPhoneFromRequest(request); |
| 1954 | if (phone != null) { |
| 1955 | phone.setDataThrottling(onCompleted, |
| 1956 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1957 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1958 | } else { |
| 1959 | loge("setDataThrottling: No phone object"); |
| 1960 | request.result = |
| 1961 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1962 | notifyRequester(request); |
| 1963 | } |
| 1964 | |
| 1965 | break; |
| 1966 | } |
| 1967 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1968 | ar = (AsyncResult) msg.obj; |
| 1969 | request = (MainThreadRequest) ar.userObj; |
| 1970 | |
| 1971 | if (ar.exception == null) { |
| 1972 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1973 | } else if (ar.exception instanceof CommandException) { |
| 1974 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1975 | CommandException.Error error = |
| 1976 | ((CommandException) (ar.exception)).getCommandError(); |
| 1977 | |
| 1978 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1979 | request.result = TelephonyManager |
| 1980 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1981 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1982 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 1983 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1984 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1985 | } else { |
| 1986 | request.result = |
| 1987 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1988 | } |
| 1989 | } else { |
| 1990 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1991 | } |
| 1992 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1993 | notifyRequester(request); |
| 1994 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1995 | |
| 1996 | case CMD_SET_SIM_POWER: { |
| 1997 | request = (MainThreadRequest) msg.obj; |
| 1998 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1999 | request = (MainThreadRequest) msg.obj; |
| 2000 | int stateToSet = |
| 2001 | ((Pair<Integer, IIntegerConsumer>) |
| 2002 | request.argument).first; |
| 2003 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2004 | break; |
| 2005 | } |
| 2006 | case EVENT_SET_SIM_POWER_DONE: { |
| 2007 | ar = (AsyncResult) msg.obj; |
| 2008 | request = (MainThreadRequest) ar.userObj; |
| 2009 | IIntegerConsumer callback = |
| 2010 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2011 | if (ar.exception != null) { |
| 2012 | loge("setSimPower exception: " + ar.exception); |
| 2013 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2014 | .RESULT_ERROR_UNKNOWN; |
| 2015 | if (ar.exception instanceof CommandException) { |
| 2016 | CommandException.Error error = |
| 2017 | ((CommandException) (ar.exception)).getCommandError(); |
| 2018 | if (error == CommandException.Error.SIM_ERR) { |
| 2019 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2020 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2021 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2022 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2023 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2024 | } else { |
| 2025 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2026 | } |
| 2027 | } |
| 2028 | try { |
| 2029 | callback.accept(errorCode); |
| 2030 | } catch (RemoteException e) { |
| 2031 | // Ignore if the remote process is no longer available to call back. |
| 2032 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2033 | } |
| 2034 | } else { |
| 2035 | try { |
| 2036 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2037 | } catch (RemoteException e) { |
| 2038 | // Ignore if the remote process is no longer available to call back. |
| 2039 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2040 | } |
| 2041 | } |
| 2042 | break; |
| 2043 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2044 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2045 | request = (MainThreadRequest) msg.obj; |
| 2046 | |
| 2047 | final Phone phone = getPhoneFromRequest(request); |
| 2048 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2049 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2050 | notifyRequester(request); |
| 2051 | break; |
| 2052 | } |
| 2053 | |
| 2054 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2055 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2056 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2057 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2058 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2059 | request.subId, pair.first /*callingUid*/, |
| 2060 | pair.second /*request*/, onCompleted); |
| 2061 | break; |
| 2062 | } |
| 2063 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2064 | ar = (AsyncResult) msg.obj; |
| 2065 | request = (MainThreadRequest) ar.userObj; |
| 2066 | // request.result will be the exception of ar if present, true otherwise. |
| 2067 | // Be cautious not to leave result null which will wait() forever |
| 2068 | request.result = ar.exception != null ? ar.exception : true; |
| 2069 | notifyRequester(request); |
| 2070 | break; |
| 2071 | } |
| 2072 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2073 | request = (MainThreadRequest) msg.obj; |
| 2074 | |
| 2075 | Phone phone = getPhoneFromRequest(request); |
| 2076 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2077 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2078 | notifyRequester(request); |
| 2079 | break; |
| 2080 | } |
| 2081 | |
| 2082 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2083 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2084 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2085 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2086 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2087 | request.subId, pair.first /*callingUid*/, |
| 2088 | pair.second /*request*/, onCompleted); |
| 2089 | break; |
| 2090 | } |
| 2091 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2092 | ar = (AsyncResult) msg.obj; |
| 2093 | request = (MainThreadRequest) ar.userObj; |
| 2094 | request.result = ar.exception != null ? ar.exception : true; |
| 2095 | notifyRequester(request); |
| 2096 | break; |
| 2097 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2098 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2099 | case CMD_GET_SLICING_CONFIG: { |
| 2100 | request = (MainThreadRequest) msg.obj; |
| 2101 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2102 | request.phone.getSlicingConfig(onCompleted); |
| 2103 | break; |
| 2104 | } |
| 2105 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2106 | ar = (AsyncResult) msg.obj; |
| 2107 | request = (MainThreadRequest) ar.userObj; |
| 2108 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2109 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2110 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2111 | Bundle bundle = new Bundle(); |
| 2112 | int resultCode = 0; |
| 2113 | if (ar.exception != null) { |
| 2114 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2115 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2116 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2117 | } else if (ar.result == null) { |
| 2118 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2119 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2120 | } else { |
| 2121 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2122 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2123 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2124 | } |
| 2125 | |
| 2126 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2127 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2128 | } |
| 2129 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2130 | result.send(resultCode, bundle); |
| 2131 | notifyRequester(request); |
| 2132 | break; |
| 2133 | } |
| 2134 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2135 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2136 | request = (MainThreadRequest) msg.obj; |
| 2137 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2138 | UiccController.getInstance().getPinStorage() |
| 2139 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2140 | notifyRequester(request); |
| 2141 | break; |
| 2142 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2143 | default: |
| 2144 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2145 | break; |
| 2146 | } |
| 2147 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2148 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2149 | private void notifyRequester(MainThreadRequest request) { |
| 2150 | synchronized (request) { |
| 2151 | request.notifyAll(); |
| 2152 | } |
| 2153 | } |
| 2154 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2155 | private void handleNullReturnEvent(Message msg, String command) { |
| 2156 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2157 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2158 | if (ar.exception == null) { |
| 2159 | request.result = true; |
| 2160 | } else { |
| 2161 | request.result = false; |
| 2162 | if (ar.exception instanceof CommandException) { |
| 2163 | loge(command + ": CommandException: " + ar.exception); |
| 2164 | } else { |
| 2165 | loge(command + ": Unknown exception"); |
| 2166 | } |
| 2167 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2168 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2169 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2170 | } |
| 2171 | |
| 2172 | /** |
| 2173 | * Posts the specified command to be executed on the main thread, |
| 2174 | * waits for the request to complete, and returns the result. |
| 2175 | * @see #sendRequestAsync |
| 2176 | */ |
| 2177 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2178 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2179 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2180 | } |
| 2181 | |
| 2182 | /** |
| 2183 | * Posts the specified command to be executed on the main thread, |
| 2184 | * waits for the request to complete, and returns the result. |
| 2185 | * @see #sendRequestAsync |
| 2186 | */ |
| 2187 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2188 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2189 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2190 | } |
| 2191 | |
| 2192 | /** |
| 2193 | * Posts the specified command to be executed on the main thread, |
| 2194 | * waits for the request to complete, and returns the result. |
| 2195 | * @see #sendRequestAsync |
| 2196 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2197 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2198 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2199 | } |
| 2200 | |
| 2201 | /** |
| 2202 | * Posts the specified command to be executed on the main thread, |
| 2203 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2204 | * if not timeout or null otherwise. |
| 2205 | * @see #sendRequestAsync |
| 2206 | */ |
| 2207 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2208 | long timeoutInMs) { |
| 2209 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2210 | } |
| 2211 | |
| 2212 | /** |
| 2213 | * Posts the specified command to be executed on the main thread, |
| 2214 | * waits for the request to complete, and returns the result. |
| 2215 | * @see #sendRequestAsync |
| 2216 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2217 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2218 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2219 | } |
| 2220 | |
| 2221 | /** |
| 2222 | * Posts the specified command to be executed on the main thread, |
| 2223 | * waits for the request to complete, and returns the result. |
| 2224 | * @see #sendRequestAsync |
| 2225 | */ |
| 2226 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2227 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2228 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2229 | } |
| 2230 | |
| 2231 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2232 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2233 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2234 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2235 | * @see #sendRequestAsync |
| 2236 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2237 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2238 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2239 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2240 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2241 | } |
| 2242 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2243 | MainThreadRequest request = null; |
| 2244 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2245 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2246 | } else if (phone != null) { |
| 2247 | request = new MainThreadRequest(argument, phone, workSource); |
| 2248 | } else { |
| 2249 | request = new MainThreadRequest(argument, subId, workSource); |
| 2250 | } |
| 2251 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2252 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2253 | msg.sendToTarget(); |
| 2254 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2255 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2256 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2257 | if (timeoutInMs >= 0) { |
| 2258 | // Wait for at least timeoutInMs before returning null request result |
| 2259 | long now = SystemClock.elapsedRealtime(); |
| 2260 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2261 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2262 | try { |
| 2263 | request.wait(deadline - now); |
| 2264 | } catch (InterruptedException e) { |
| 2265 | // Do nothing, go back and check if request is completed or timeout |
| 2266 | } finally { |
| 2267 | now = SystemClock.elapsedRealtime(); |
| 2268 | } |
| 2269 | } |
| 2270 | } else { |
| 2271 | // Wait for the request to complete |
| 2272 | while (request.result == null) { |
| 2273 | try { |
| 2274 | request.wait(); |
| 2275 | } catch (InterruptedException e) { |
| 2276 | // Do nothing, go back and wait until the request is complete |
| 2277 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2278 | } |
| 2279 | } |
| 2280 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2281 | if (request.result == null) { |
| 2282 | Log.wtf(LOG_TAG, |
| 2283 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2284 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2285 | return request.result; |
| 2286 | } |
| 2287 | |
| 2288 | /** |
| 2289 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2290 | * Posts the specified command to be executed on the main thread, and |
| 2291 | * returns immediately. |
| 2292 | * @see #sendRequest |
| 2293 | */ |
| 2294 | private void sendRequestAsync(int command) { |
| 2295 | mMainThreadHandler.sendEmptyMessage(command); |
| 2296 | } |
| 2297 | |
| 2298 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2299 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2300 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2301 | */ |
| 2302 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2303 | sendRequestAsync(command, argument, null, null); |
| 2304 | } |
| 2305 | |
| 2306 | /** |
| 2307 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2308 | * @see {@link #sendRequest(int,Object)} |
| 2309 | */ |
| 2310 | private void sendRequestAsync( |
| 2311 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2312 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2313 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2314 | msg.sendToTarget(); |
| 2315 | } |
| 2316 | |
| 2317 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2318 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2319 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2320 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2321 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2322 | synchronized (PhoneInterfaceManager.class) { |
| 2323 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2324 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2325 | } else { |
| 2326 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2327 | } |
| 2328 | return sInstance; |
| 2329 | } |
| 2330 | } |
| 2331 | |
| 2332 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2333 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2334 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2335 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2336 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2337 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2338 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2339 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2340 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2341 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2342 | mTelephonySharedPreferences = |
| 2343 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2344 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2345 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2346 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2347 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2348 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2349 | publish(); |
| 2350 | } |
| 2351 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2352 | private Phone getDefaultPhone() { |
| 2353 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2354 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2355 | } |
| 2356 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2357 | private void publish() { |
| 2358 | if (DBG) log("publish: " + this); |
| 2359 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2360 | TelephonyFrameworkInitializer |
| 2361 | .getTelephonyServiceManager() |
| 2362 | .getTelephonyServiceRegisterer() |
| 2363 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2364 | } |
| 2365 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2366 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2367 | if (request.phone != null) { |
| 2368 | return request.phone; |
| 2369 | } else { |
| 2370 | return getPhoneFromSubId(request.subId); |
| 2371 | } |
| 2372 | } |
| 2373 | |
| 2374 | private Phone getPhoneFromSubId(int subId) { |
| 2375 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2376 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2377 | } |
| 2378 | |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2379 | private UiccPort getUiccPortFromRequest(MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2380 | Phone phone = getPhoneFromRequest(request); |
| 2381 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2382 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2383 | } |
| 2384 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2385 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2386 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2387 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2388 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2389 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2390 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2391 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2392 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2393 | } |
| 2394 | |
| 2395 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2396 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2397 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2398 | } |
| 2399 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2400 | private boolean isImsAvailableOnDevice() { |
| 2401 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2402 | if (pm == null) { |
| 2403 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2404 | // so do not throw error and allow. |
| 2405 | return true; |
| 2406 | } |
| 2407 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2408 | } |
| 2409 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2410 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2411 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2412 | } |
| 2413 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2414 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2415 | if (DBG) log("dial: " + number); |
| 2416 | // No permission check needed here: This is just a wrapper around the |
| 2417 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2418 | // the UI before it does anything. |
| 2419 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2420 | final long identity = Binder.clearCallingIdentity(); |
| 2421 | try { |
| 2422 | String url = createTelUrl(number); |
| 2423 | if (url == null) { |
| 2424 | return; |
| 2425 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2426 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2427 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2428 | PhoneConstants.State state = mCM.getState(subId); |
| 2429 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2430 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2431 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2432 | mApp.startActivity(intent); |
| 2433 | } |
| 2434 | } finally { |
| 2435 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2436 | } |
| 2437 | } |
| 2438 | |
| 2439 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2440 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2441 | } |
| 2442 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2443 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2444 | if (DBG) log("call: " + number); |
| 2445 | |
| 2446 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2447 | // need to do a permission check since we're calling startActivity() |
| 2448 | // from the context of the phone app. |
| 2449 | enforceCallPermission(); |
| 2450 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2451 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2452 | != AppOpsManager.MODE_ALLOWED) { |
| 2453 | return; |
| 2454 | } |
| 2455 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2456 | final long identity = Binder.clearCallingIdentity(); |
| 2457 | try { |
| 2458 | String url = createTelUrl(number); |
| 2459 | if (url == null) { |
| 2460 | return; |
| 2461 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2462 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2463 | boolean isValid = false; |
| 2464 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2465 | if (slist != null) { |
| 2466 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2467 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2468 | isValid = true; |
| 2469 | break; |
| 2470 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2471 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2472 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2473 | if (!isValid) { |
| 2474 | return; |
| 2475 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2476 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2477 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2478 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2479 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2480 | mApp.startActivity(intent); |
| 2481 | } finally { |
| 2482 | Binder.restoreCallingIdentity(identity); |
| 2483 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2484 | } |
| 2485 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2486 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2487 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2488 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2489 | } |
| 2490 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2491 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2492 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2493 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2494 | } |
| 2495 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2496 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2497 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2498 | |
| 2499 | final long identity = Binder.clearCallingIdentity(); |
| 2500 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2501 | Phone phone = getPhone(subId); |
| 2502 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2503 | checkSimPin.start(); |
| 2504 | return checkSimPin.unlockSim(null, pin); |
| 2505 | } finally { |
| 2506 | Binder.restoreCallingIdentity(identity); |
| 2507 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2508 | } |
| 2509 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2510 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2511 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2512 | |
| 2513 | final long identity = Binder.clearCallingIdentity(); |
| 2514 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2515 | Phone phone = getPhone(subId); |
| 2516 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2517 | checkSimPuk.start(); |
| 2518 | return checkSimPuk.unlockSim(puk, pin); |
| 2519 | } finally { |
| 2520 | Binder.restoreCallingIdentity(identity); |
| 2521 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2522 | } |
| 2523 | |
| 2524 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2525 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2526 | * a synchronous one. |
| 2527 | */ |
| 2528 | private static class UnlockSim extends Thread { |
| 2529 | |
| 2530 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2531 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2532 | |
| 2533 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2534 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2535 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2536 | |
| 2537 | // For replies from SimCard interface |
| 2538 | private Handler mHandler; |
| 2539 | |
| 2540 | // For async handler to identify request type |
| 2541 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2542 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2543 | UnlockSim(int phoneId, IccCard simCard) { |
| 2544 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2545 | mSimCard = simCard; |
| 2546 | } |
| 2547 | |
| 2548 | @Override |
| 2549 | public void run() { |
| 2550 | Looper.prepare(); |
| 2551 | synchronized (UnlockSim.this) { |
| 2552 | mHandler = new Handler() { |
| 2553 | @Override |
| 2554 | public void handleMessage(Message msg) { |
| 2555 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2556 | switch (msg.what) { |
| 2557 | case SUPPLY_PIN_COMPLETE: |
| 2558 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2559 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2560 | mRetryCount = msg.arg1; |
| 2561 | if (ar.exception != null) { |
| 2562 | if (ar.exception instanceof CommandException && |
| 2563 | ((CommandException)(ar.exception)).getCommandError() |
| 2564 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2565 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2566 | } //When UiccCardApp dispose,handle message and return exception |
| 2567 | else if (ar.exception instanceof CommandException && |
| 2568 | ((CommandException) (ar.exception)).getCommandError() |
| 2569 | == CommandException.Error.ABORTED) { |
| 2570 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2571 | } else { |
| 2572 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2573 | } |
| 2574 | } else { |
| 2575 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2576 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2577 | mDone = true; |
| 2578 | UnlockSim.this.notifyAll(); |
| 2579 | } |
| 2580 | break; |
| 2581 | } |
| 2582 | } |
| 2583 | }; |
| 2584 | UnlockSim.this.notifyAll(); |
| 2585 | } |
| 2586 | Looper.loop(); |
| 2587 | } |
| 2588 | |
| 2589 | /* |
| 2590 | * Use PIN or PUK to unlock SIM card |
| 2591 | * |
| 2592 | * If PUK is null, unlock SIM card with PIN |
| 2593 | * |
| 2594 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2595 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2596 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2597 | |
| 2598 | while (mHandler == null) { |
| 2599 | try { |
| 2600 | wait(); |
| 2601 | } catch (InterruptedException e) { |
| 2602 | Thread.currentThread().interrupt(); |
| 2603 | } |
| 2604 | } |
| 2605 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2606 | |
| 2607 | if (puk == null) { |
| 2608 | mSimCard.supplyPin(pin, callback); |
| 2609 | } else { |
| 2610 | mSimCard.supplyPuk(puk, pin, callback); |
| 2611 | } |
| 2612 | |
| 2613 | while (!mDone) { |
| 2614 | try { |
| 2615 | Log.d(LOG_TAG, "wait for done"); |
| 2616 | wait(); |
| 2617 | } catch (InterruptedException e) { |
| 2618 | // Restore the interrupted status |
| 2619 | Thread.currentThread().interrupt(); |
| 2620 | } |
| 2621 | } |
| 2622 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2623 | int[] resultArray = new int[2]; |
| 2624 | resultArray[0] = mResult; |
| 2625 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2626 | |
| 2627 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2628 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2629 | } |
| 2630 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2631 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2632 | } |
| 2633 | } |
| 2634 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2635 | /** |
| 2636 | * This method has been removed due to privacy and stability concerns. |
| 2637 | */ |
| 2638 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2639 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2640 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2641 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2642 | } |
| 2643 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2644 | @Override |
| 2645 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2646 | mApp.getSystemService(AppOpsManager.class) |
| 2647 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2648 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2649 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2650 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2651 | // Callers targeting S have no business invoking this method. |
| 2652 | return; |
| 2653 | } |
| 2654 | |
| 2655 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2656 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2657 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2658 | .setCallingPackage(callingPackage) |
| 2659 | .setCallingFeatureId(null) |
| 2660 | .setCallingPid(Binder.getCallingPid()) |
| 2661 | .setCallingUid(Binder.getCallingUid()) |
| 2662 | .setMethod("updateServiceLocation") |
| 2663 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2664 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2665 | .build()); |
| 2666 | // Apps that lack location permission have no business calling this method; |
| 2667 | // however, because no permission was declared in the public API, denials must |
| 2668 | // all be "soft". |
| 2669 | switch (locationResult) { |
| 2670 | case DENIED_HARD: /* fall through */ |
| 2671 | case DENIED_SOFT: |
| 2672 | return; |
| 2673 | } |
| 2674 | |
| 2675 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2676 | final long identity = Binder.clearCallingIdentity(); |
| 2677 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2678 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2679 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2680 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2681 | } |
| 2682 | } finally { |
| 2683 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2684 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2685 | } |
| 2686 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2687 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2688 | @Override |
| 2689 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2690 | return isRadioOnWithFeature(callingPackage, null); |
| 2691 | } |
| 2692 | |
| 2693 | |
| 2694 | @Override |
| 2695 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2696 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2697 | callingFeatureId); |
| 2698 | } |
| 2699 | |
| 2700 | @Deprecated |
| 2701 | @Override |
| 2702 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2703 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2704 | } |
| 2705 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2706 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2707 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2708 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2709 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2710 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2711 | return false; |
| 2712 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2713 | |
| 2714 | final long identity = Binder.clearCallingIdentity(); |
| 2715 | try { |
| 2716 | return isRadioOnForSubscriber(subId); |
| 2717 | } finally { |
| 2718 | Binder.restoreCallingIdentity(identity); |
| 2719 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2720 | } |
| 2721 | |
| 2722 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2723 | final long identity = Binder.clearCallingIdentity(); |
| 2724 | try { |
| 2725 | final Phone phone = getPhone(subId); |
| 2726 | if (phone != null) { |
| 2727 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2728 | } else { |
| 2729 | return false; |
| 2730 | } |
| 2731 | } finally { |
| 2732 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2733 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2734 | } |
| 2735 | |
| 2736 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2737 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2738 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2739 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2740 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2741 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2742 | |
| 2743 | final long identity = Binder.clearCallingIdentity(); |
| 2744 | try { |
| 2745 | final Phone phone = getPhone(subId); |
| 2746 | if (phone != null) { |
| 2747 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2748 | } |
| 2749 | } finally { |
| 2750 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2751 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2752 | } |
| 2753 | |
| 2754 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2755 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2756 | } |
| 2757 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2758 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2759 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2760 | |
| 2761 | final long identity = Binder.clearCallingIdentity(); |
| 2762 | try { |
| 2763 | final Phone phone = getPhone(subId); |
| 2764 | if (phone == null) { |
| 2765 | return false; |
| 2766 | } |
| 2767 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2768 | toggleRadioOnOffForSubscriber(subId); |
| 2769 | } |
| 2770 | return true; |
| 2771 | } finally { |
| 2772 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2773 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2774 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2775 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2776 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2777 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2778 | /* |
| 2779 | * If any of the Radios are available, it will need to be |
| 2780 | * shutdown. So return true if any Radio is available. |
| 2781 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2782 | final long identity = Binder.clearCallingIdentity(); |
| 2783 | try { |
| 2784 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2785 | Phone phone = PhoneFactory.getPhone(i); |
| 2786 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2787 | } |
| 2788 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2789 | return false; |
| 2790 | } finally { |
| 2791 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2792 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2793 | } |
| 2794 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2795 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2796 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2797 | enforceModifyPermission(); |
| 2798 | |
| 2799 | final long identity = Binder.clearCallingIdentity(); |
| 2800 | try { |
| 2801 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2802 | logv("Shutting down Phone " + i); |
| 2803 | shutdownRadioUsingPhoneId(i); |
| 2804 | } |
| 2805 | } finally { |
| 2806 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2807 | } |
| 2808 | } |
| 2809 | |
| 2810 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2811 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2812 | if (phone != null && phone.isRadioAvailable()) { |
| 2813 | phone.shutdownRadio(); |
| 2814 | } |
| 2815 | } |
| 2816 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2817 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2818 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2819 | |
| 2820 | final long identity = Binder.clearCallingIdentity(); |
| 2821 | try { |
| 2822 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2823 | if (defaultPhone != null) { |
| 2824 | defaultPhone.setRadioPower(turnOn); |
| 2825 | return true; |
| 2826 | } else { |
| 2827 | loge("There's no default phone."); |
| 2828 | return false; |
| 2829 | } |
| 2830 | } finally { |
| 2831 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2832 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2833 | } |
| 2834 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2835 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2836 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2837 | |
| 2838 | final long identity = Binder.clearCallingIdentity(); |
| 2839 | try { |
| 2840 | final Phone phone = getPhone(subId); |
| 2841 | if (phone != null) { |
| 2842 | phone.setRadioPower(turnOn); |
| 2843 | return true; |
| 2844 | } else { |
| 2845 | return false; |
| 2846 | } |
| 2847 | } finally { |
| 2848 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2849 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2850 | } |
| 2851 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2852 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2853 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2854 | public boolean enableDataConnectivity() { |
| 2855 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2856 | |
| 2857 | final long identity = Binder.clearCallingIdentity(); |
| 2858 | try { |
| 2859 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2860 | final Phone phone = getPhone(subId); |
| 2861 | if (phone != null) { |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 2862 | if (phone.isUsingNewDataStack()) { |
| 2863 | phone.getDataSettingsManager().setDataEnabled( |
| 2864 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
| 2865 | } else { |
| 2866 | phone.getDataEnabledSettings().setDataEnabled( |
| 2867 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
| 2868 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2869 | return true; |
| 2870 | } else { |
| 2871 | return false; |
| 2872 | } |
| 2873 | } finally { |
| 2874 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2875 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2876 | } |
| 2877 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2878 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2879 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2880 | public boolean disableDataConnectivity() { |
| 2881 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2882 | |
| 2883 | final long identity = Binder.clearCallingIdentity(); |
| 2884 | try { |
| 2885 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2886 | final Phone phone = getPhone(subId); |
| 2887 | if (phone != null) { |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 2888 | if (phone.isUsingNewDataStack()) { |
| 2889 | phone.getDataSettingsManager().setDataEnabled( |
| 2890 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
| 2891 | } else { |
| 2892 | phone.getDataEnabledSettings().setDataEnabled( |
| 2893 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
| 2894 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2895 | return true; |
| 2896 | } else { |
| 2897 | return false; |
| 2898 | } |
| 2899 | } finally { |
| 2900 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2901 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2902 | } |
| 2903 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2904 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2905 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2906 | final long identity = Binder.clearCallingIdentity(); |
| 2907 | try { |
| 2908 | final Phone phone = getPhone(subId); |
| 2909 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2910 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2911 | } else { |
| 2912 | return false; |
| 2913 | } |
| 2914 | } finally { |
| 2915 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2916 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2917 | } |
| 2918 | |
| 2919 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2920 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2921 | } |
| 2922 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2923 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2924 | enforceCallPermission(); |
| 2925 | |
| 2926 | final long identity = Binder.clearCallingIdentity(); |
| 2927 | try { |
| 2928 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2929 | return; |
| 2930 | } |
| 2931 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2932 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2933 | } finally { |
| 2934 | Binder.restoreCallingIdentity(identity); |
| 2935 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2936 | }; |
| 2937 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2938 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2939 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2940 | |
| 2941 | final long identity = Binder.clearCallingIdentity(); |
| 2942 | try { |
| 2943 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2944 | return false; |
| 2945 | } |
| 2946 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2947 | } finally { |
| 2948 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2949 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2950 | } |
| 2951 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2952 | /** |
| 2953 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 2954 | * tag on getCallState Binder call. |
| 2955 | */ |
| 2956 | @Deprecated |
| 2957 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2958 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2959 | if (CompatChanges.isChangeEnabled( |
| 2960 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2961 | Binder.getCallingUid())) { |
| 2962 | // Do not allow this API to be called on API version 31+, it should only be |
| 2963 | // called on old apps using this Binder call directly. |
| 2964 | throw new SecurityException("This method can only be used for applications " |
| 2965 | + "targeting API version 30 or less."); |
| 2966 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2967 | final long identity = Binder.clearCallingIdentity(); |
| 2968 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2969 | Phone phone = getPhone(getDefaultSubscription()); |
| 2970 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2971 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2972 | } finally { |
| 2973 | Binder.restoreCallingIdentity(identity); |
| 2974 | } |
| 2975 | } |
| 2976 | |
| 2977 | @Override |
| 2978 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 2979 | if (CompatChanges.isChangeEnabled( |
| 2980 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2981 | Binder.getCallingUid())) { |
| 2982 | // Check READ_PHONE_STATE for API version 31+ |
| 2983 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2984 | featureId, "getCallStateForSubscription")) { |
| 2985 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 2986 | + "targeting API level 31+."); |
| 2987 | } |
| 2988 | } |
| 2989 | final long identity = Binder.clearCallingIdentity(); |
| 2990 | try { |
| 2991 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2992 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2993 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2994 | } finally { |
| 2995 | Binder.restoreCallingIdentity(identity); |
| 2996 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2997 | } |
| 2998 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2999 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3000 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3001 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 3002 | } |
| 3003 | |
| 3004 | @Override |
| 3005 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3006 | final long identity = Binder.clearCallingIdentity(); |
| 3007 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3008 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3009 | if (phone != null) { |
Jack Yu | 2c45095 | 2021-11-29 11:36:17 -0800 | [diff] [blame] | 3010 | if (phone.isUsingNewDataStack()) { |
| 3011 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
| 3012 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3013 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 3014 | } else { |
| 3015 | return PhoneConstantConversions.convertDataState( |
| 3016 | PhoneConstants.DataState.DISCONNECTED); |
| 3017 | } |
| 3018 | } finally { |
| 3019 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3020 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3021 | } |
| 3022 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3023 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3024 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3025 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 3026 | } |
| 3027 | |
| 3028 | @Override |
| 3029 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3030 | final long identity = Binder.clearCallingIdentity(); |
| 3031 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3032 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3033 | if (phone != null) { |
| 3034 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 3035 | } else { |
| 3036 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3037 | } |
| 3038 | } finally { |
| 3039 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3040 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3041 | } |
| 3042 | |
| 3043 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3044 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3045 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3046 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3047 | |
| 3048 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3049 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3050 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3051 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3052 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3053 | .setCallingPid(Binder.getCallingPid()) |
| 3054 | .setCallingUid(Binder.getCallingUid()) |
| 3055 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3056 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3057 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3058 | .build()); |
| 3059 | switch (locationResult) { |
| 3060 | case DENIED_HARD: |
| 3061 | throw new SecurityException("Not allowed to access cell location"); |
| 3062 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3063 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3064 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3065 | } |
| 3066 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3067 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3068 | final long identity = Binder.clearCallingIdentity(); |
| 3069 | try { |
| 3070 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3071 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3072 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3073 | } finally { |
| 3074 | Binder.restoreCallingIdentity(identity); |
| 3075 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3076 | } |
| 3077 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3078 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3079 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3080 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3081 | // registered cell info, so return a NULL country instead. |
| 3082 | final long identity = Binder.clearCallingIdentity(); |
| 3083 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3084 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3085 | // Get default phone in this case. |
| 3086 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3087 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3088 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3089 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3090 | if (phone == null) return ""; |
| 3091 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3092 | if (sst == null) return ""; |
| 3093 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3094 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3095 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3096 | } finally { |
| 3097 | Binder.restoreCallingIdentity(identity); |
| 3098 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3099 | } |
| 3100 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3101 | /** |
| 3102 | * This method was removed due to potential issues caused by performing partial |
| 3103 | * updates of service state, and lack of a credible use case. |
| 3104 | * |
| 3105 | * This has the ability to break the telephony implementation by disabling notification of |
| 3106 | * changes in device connectivity. DO NOT USE THIS! |
| 3107 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3108 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3109 | public void enableLocationUpdates() { |
| 3110 | mApp.enforceCallingOrSelfPermission( |
| 3111 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3112 | } |
| 3113 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3114 | /** |
| 3115 | * This method was removed due to potential issues caused by performing partial |
| 3116 | * updates of service state, and lack of a credible use case. |
| 3117 | * |
| 3118 | * This has the ability to break the telephony implementation by disabling notification of |
| 3119 | * changes in device connectivity. DO NOT USE THIS! |
| 3120 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3121 | @Override |
| 3122 | public void disableLocationUpdates() { |
| 3123 | mApp.enforceCallingOrSelfPermission( |
| 3124 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3125 | } |
| 3126 | |
| 3127 | @Override |
| 3128 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3129 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3130 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3131 | try { |
| 3132 | mApp.getSystemService(AppOpsManager.class) |
| 3133 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3134 | } catch (SecurityException e) { |
| 3135 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3136 | throw e; |
| 3137 | } |
| 3138 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3139 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3140 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3141 | throw new SecurityException( |
| 3142 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3143 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3144 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3145 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3146 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3147 | return null; |
| 3148 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3149 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3150 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3151 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3152 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3153 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3154 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3155 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3156 | for (CellInfo ci : info) { |
| 3157 | if (ci instanceof CellInfoGsm) { |
| 3158 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3159 | } else if (ci instanceof CellInfoWcdma) { |
| 3160 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3161 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3162 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3163 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3164 | } |
| 3165 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3166 | private List<CellInfo> getCachedCellInfo() { |
| 3167 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3168 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3169 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3170 | if (info != null) cellInfos.addAll(info); |
| 3171 | } |
| 3172 | return cellInfos; |
| 3173 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3174 | |
| 3175 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3176 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3177 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3178 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3179 | |
| 3180 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3181 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3182 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3183 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3184 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3185 | .setCallingPid(Binder.getCallingPid()) |
| 3186 | .setCallingUid(Binder.getCallingUid()) |
| 3187 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3188 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3189 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3190 | .build()); |
| 3191 | switch (locationResult) { |
| 3192 | case DENIED_HARD: |
| 3193 | throw new SecurityException("Not allowed to access cell info"); |
| 3194 | case DENIED_SOFT: |
| 3195 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3196 | } |
| 3197 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3198 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3199 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3200 | return getCachedCellInfo(); |
| 3201 | } |
| 3202 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3203 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3204 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3205 | final long identity = Binder.clearCallingIdentity(); |
| 3206 | try { |
| 3207 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3208 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3209 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3210 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3211 | if (info != null) cellInfos.addAll(info); |
| 3212 | } |
| 3213 | return cellInfos; |
| 3214 | } finally { |
| 3215 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3216 | } |
| 3217 | } |
| 3218 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3219 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3220 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3221 | String callingFeatureId) { |
| 3222 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3223 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3224 | } |
| 3225 | |
| 3226 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3227 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3228 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3229 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3230 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3231 | } |
| 3232 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3233 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3234 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3235 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3236 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3237 | |
| 3238 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3239 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3240 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3241 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3242 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3243 | .setCallingPid(Binder.getCallingPid()) |
| 3244 | .setCallingUid(Binder.getCallingUid()) |
| 3245 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3246 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3247 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3248 | .build()); |
| 3249 | switch (locationResult) { |
| 3250 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3251 | if (TelephonyPermissions |
| 3252 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3253 | // Safetynet logging for b/154934934 |
| 3254 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3255 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3256 | throw new SecurityException("Not allowed to access cell info"); |
| 3257 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3258 | if (TelephonyPermissions |
| 3259 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3260 | // Safetynet logging for b/154934934 |
| 3261 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3262 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3263 | try { |
| 3264 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3265 | } catch (RemoteException re) { |
| 3266 | // Drop without consequences |
| 3267 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3268 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3269 | } |
| 3270 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3271 | |
| 3272 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3273 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3274 | |
| 3275 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3276 | } |
| 3277 | |
| 3278 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3279 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3280 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3281 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3282 | |
| 3283 | final long identity = Binder.clearCallingIdentity(); |
| 3284 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3285 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3286 | } finally { |
| 3287 | Binder.restoreCallingIdentity(identity); |
| 3288 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3289 | } |
| 3290 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3291 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3292 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3293 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3294 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3295 | return null; |
| 3296 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3297 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3298 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3299 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3300 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3301 | return null; |
| 3302 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3303 | |
| 3304 | final long identity = Binder.clearCallingIdentity(); |
| 3305 | try { |
| 3306 | return phone.getImei(); |
| 3307 | } finally { |
| 3308 | Binder.restoreCallingIdentity(identity); |
| 3309 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3310 | } |
| 3311 | |
| 3312 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3313 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3314 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3315 | String tac = null; |
| 3316 | if (phone != null) { |
| 3317 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3318 | try { |
| 3319 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3320 | } catch (IndexOutOfBoundsException e) { |
| 3321 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3322 | return null; |
| 3323 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3324 | } |
| 3325 | return tac; |
| 3326 | } |
| 3327 | |
| 3328 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3329 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3330 | try { |
| 3331 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3332 | } catch (SecurityException se) { |
| 3333 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3334 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3335 | + Binder.getCallingUid()); |
| 3336 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3337 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3338 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3339 | return null; |
| 3340 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3341 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3342 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3343 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3344 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3345 | return null; |
| 3346 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3347 | |
| 3348 | final long identity = Binder.clearCallingIdentity(); |
| 3349 | try { |
| 3350 | return phone.getMeid(); |
| 3351 | } finally { |
| 3352 | Binder.restoreCallingIdentity(identity); |
| 3353 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3354 | } |
| 3355 | |
| 3356 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3357 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3358 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3359 | String manufacturerCode = null; |
| 3360 | if (phone != null) { |
| 3361 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3362 | try { |
| 3363 | manufacturerCode = |
| 3364 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3365 | } catch (IndexOutOfBoundsException e) { |
| 3366 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3367 | return null; |
| 3368 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3369 | } |
| 3370 | return manufacturerCode; |
| 3371 | } |
| 3372 | |
| 3373 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3374 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3375 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3376 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3377 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3378 | return null; |
| 3379 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3380 | int subId = phone.getSubId(); |
| 3381 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3382 | mApp, subId, callingPackage, callingFeatureId, |
| 3383 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3384 | return null; |
| 3385 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3386 | |
| 3387 | final long identity = Binder.clearCallingIdentity(); |
| 3388 | try { |
| 3389 | return phone.getDeviceSvn(); |
| 3390 | } finally { |
| 3391 | Binder.restoreCallingIdentity(identity); |
| 3392 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3393 | } |
| 3394 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3395 | @Override |
| 3396 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3397 | final long identity = Binder.clearCallingIdentity(); |
| 3398 | try { |
| 3399 | final Phone phone = getPhone(subId); |
| 3400 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3401 | } finally { |
| 3402 | Binder.restoreCallingIdentity(identity); |
| 3403 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3404 | } |
| 3405 | |
| 3406 | @Override |
| 3407 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3408 | final long identity = Binder.clearCallingIdentity(); |
| 3409 | try { |
| 3410 | final Phone phone = getPhone(subId); |
| 3411 | return phone == null ? null : phone.getCarrierName(); |
| 3412 | } finally { |
| 3413 | Binder.restoreCallingIdentity(identity); |
| 3414 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3415 | } |
| 3416 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3417 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3418 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3419 | final long identity = Binder.clearCallingIdentity(); |
| 3420 | try { |
| 3421 | final Phone phone = getPhone(subId); |
| 3422 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3423 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3424 | } finally { |
| 3425 | Binder.restoreCallingIdentity(identity); |
| 3426 | } |
| 3427 | } |
| 3428 | |
| 3429 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3430 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3431 | final long identity = Binder.clearCallingIdentity(); |
| 3432 | try { |
| 3433 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3434 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3435 | } finally { |
| 3436 | Binder.restoreCallingIdentity(identity); |
| 3437 | } |
| 3438 | } |
| 3439 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3440 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3441 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3442 | if (!isSubscriptionMccMnc) { |
| 3443 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3444 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3445 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3446 | if (phone == null) { |
| 3447 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3448 | } |
| 3449 | final long identity = Binder.clearCallingIdentity(); |
| 3450 | try { |
| 3451 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3452 | } finally { |
| 3453 | Binder.restoreCallingIdentity(identity); |
| 3454 | } |
| 3455 | } |
| 3456 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3457 | // |
| 3458 | // Internal helper methods. |
| 3459 | // |
| 3460 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3461 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3462 | * Make sure the caller is the calling package itself |
| 3463 | * |
| 3464 | * @throws SecurityException if the caller is not the calling package |
| 3465 | */ |
| 3466 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3467 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3468 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3469 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3470 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3471 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3472 | } catch (PackageManager.NameNotFoundException e) { |
| 3473 | // packageUid is -1 |
| 3474 | } |
| 3475 | if (packageUid != callingUid) { |
| 3476 | throw new SecurityException(message + ": Package " + callingPackage |
| 3477 | + " does not belong to " + callingUid); |
| 3478 | } |
| 3479 | } |
| 3480 | |
| 3481 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3482 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3483 | * |
| 3484 | * @throws SecurityException if the caller does not have the required permission |
| 3485 | */ |
| 3486 | private void enforceModifyPermission() { |
| 3487 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3488 | } |
| 3489 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3490 | private void enforceActiveEmergencySessionPermission() { |
| 3491 | mApp.enforceCallingOrSelfPermission( |
| 3492 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3493 | } |
| 3494 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3495 | /** |
| 3496 | * Make sure the caller has the CALL_PHONE permission. |
| 3497 | * |
| 3498 | * @throws SecurityException if the caller does not have the required permission |
| 3499 | */ |
| 3500 | private void enforceCallPermission() { |
| 3501 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3502 | } |
| 3503 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3504 | private void enforceSettingsPermission() { |
| 3505 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3506 | } |
| 3507 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3508 | private void enforceRebootPermission() { |
| 3509 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3510 | } |
| 3511 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3512 | private String createTelUrl(String number) { |
| 3513 | if (TextUtils.isEmpty(number)) { |
| 3514 | return null; |
| 3515 | } |
| 3516 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3517 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3518 | } |
| 3519 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3520 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3521 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3522 | } |
| 3523 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3524 | private static void logv(String msg) { |
| 3525 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3526 | } |
| 3527 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3528 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3529 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3530 | } |
| 3531 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3532 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3533 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3534 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3535 | } |
| 3536 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3537 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3538 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3539 | final long identity = Binder.clearCallingIdentity(); |
| 3540 | try { |
| 3541 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3542 | if (phone == null) { |
| 3543 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3544 | } else { |
| 3545 | return phone.getPhoneType(); |
| 3546 | } |
| 3547 | } finally { |
| 3548 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3549 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3550 | } |
| 3551 | |
| 3552 | /** |
| 3553 | * Returns the CDMA ERI icon index to display |
| 3554 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3555 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3556 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3557 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3558 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3559 | } |
| 3560 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3561 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3562 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3563 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3564 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3565 | mApp, subId, callingPackage, callingFeatureId, |
| 3566 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3567 | return -1; |
| 3568 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3569 | |
| 3570 | final long identity = Binder.clearCallingIdentity(); |
| 3571 | try { |
| 3572 | final Phone phone = getPhone(subId); |
| 3573 | if (phone != null) { |
| 3574 | return phone.getCdmaEriIconIndex(); |
| 3575 | } else { |
| 3576 | return -1; |
| 3577 | } |
| 3578 | } finally { |
| 3579 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3580 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3581 | } |
| 3582 | |
| 3583 | /** |
| 3584 | * Returns the CDMA ERI icon mode, |
| 3585 | * 0 - ON |
| 3586 | * 1 - FLASHING |
| 3587 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3588 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3589 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3590 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3591 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3592 | } |
| 3593 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3594 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3595 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3596 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3597 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3598 | mApp, subId, callingPackage, callingFeatureId, |
| 3599 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3600 | return -1; |
| 3601 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3602 | |
| 3603 | final long identity = Binder.clearCallingIdentity(); |
| 3604 | try { |
| 3605 | final Phone phone = getPhone(subId); |
| 3606 | if (phone != null) { |
| 3607 | return phone.getCdmaEriIconMode(); |
| 3608 | } else { |
| 3609 | return -1; |
| 3610 | } |
| 3611 | } finally { |
| 3612 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3613 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3614 | } |
| 3615 | |
| 3616 | /** |
| 3617 | * Returns the CDMA ERI text, |
| 3618 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3619 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3620 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3621 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3622 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3623 | } |
| 3624 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3625 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3626 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3627 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3628 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3629 | mApp, subId, callingPackage, callingFeatureId, |
| 3630 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3631 | return null; |
| 3632 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3633 | |
| 3634 | final long identity = Binder.clearCallingIdentity(); |
| 3635 | try { |
| 3636 | final Phone phone = getPhone(subId); |
| 3637 | if (phone != null) { |
| 3638 | return phone.getCdmaEriText(); |
| 3639 | } else { |
| 3640 | return null; |
| 3641 | } |
| 3642 | } finally { |
| 3643 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3644 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3645 | } |
| 3646 | |
| 3647 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3648 | * Returns the CDMA MDN. |
| 3649 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3650 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3651 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3652 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3653 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3654 | |
| 3655 | final long identity = Binder.clearCallingIdentity(); |
| 3656 | try { |
| 3657 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3658 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3659 | return phone.getLine1Number(); |
| 3660 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3661 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3662 | return null; |
| 3663 | } |
| 3664 | } finally { |
| 3665 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3666 | } |
| 3667 | } |
| 3668 | |
| 3669 | /** |
| 3670 | * Returns the CDMA MIN. |
| 3671 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3672 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3673 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3674 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3675 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3676 | |
| 3677 | final long identity = Binder.clearCallingIdentity(); |
| 3678 | try { |
| 3679 | final Phone phone = getPhone(subId); |
| 3680 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3681 | return phone.getCdmaMin(); |
| 3682 | } else { |
| 3683 | return null; |
| 3684 | } |
| 3685 | } finally { |
| 3686 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3687 | } |
| 3688 | } |
| 3689 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3690 | @Override |
| 3691 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3692 | INumberVerificationCallback callback, String callingPackage) { |
| 3693 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3694 | != PERMISSION_GRANTED) { |
| 3695 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3696 | } |
| 3697 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3698 | |
| 3699 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3700 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3701 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3702 | + "calling package: " + callingPackage |
| 3703 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3704 | } |
| 3705 | |
| 3706 | if (range == null) { |
| 3707 | throw new NullPointerException("Range must be non-null"); |
| 3708 | } |
| 3709 | |
| 3710 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3711 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3712 | |
| 3713 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3714 | } |
| 3715 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3716 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3717 | * Returns true if CDMA provisioning needs to run. |
| 3718 | */ |
| 3719 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3720 | final long identity = Binder.clearCallingIdentity(); |
| 3721 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3722 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3723 | } finally { |
| 3724 | Binder.restoreCallingIdentity(identity); |
| 3725 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3726 | } |
| 3727 | |
| 3728 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3729 | * Sets the voice mail number of a given subId. |
| 3730 | */ |
| 3731 | @Override |
| 3732 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3733 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3734 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3735 | |
| 3736 | final long identity = Binder.clearCallingIdentity(); |
| 3737 | try { |
| 3738 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3739 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3740 | return success; |
| 3741 | } finally { |
| 3742 | Binder.restoreCallingIdentity(identity); |
| 3743 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3744 | } |
| 3745 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3746 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3747 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3748 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3749 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3750 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3751 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3752 | throw new SecurityException("caller must be system dialer"); |
| 3753 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3754 | |
| 3755 | final long identity = Binder.clearCallingIdentity(); |
| 3756 | try { |
| 3757 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3758 | if (phoneAccountHandle == null) { |
| 3759 | return null; |
| 3760 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3761 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3762 | } finally { |
| 3763 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3764 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3765 | } |
| 3766 | |
| 3767 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3768 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3769 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3770 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3771 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3772 | mApp, subId, callingPackage, callingFeatureId, |
| 3773 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3774 | return null; |
| 3775 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3776 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3777 | final long identity = Binder.clearCallingIdentity(); |
| 3778 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3779 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3780 | } finally { |
| 3781 | Binder.restoreCallingIdentity(identity); |
| 3782 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3783 | } |
| 3784 | |
| 3785 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3786 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3787 | VisualVoicemailSmsFilterSettings settings) { |
| 3788 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3789 | |
| 3790 | final long identity = Binder.clearCallingIdentity(); |
| 3791 | try { |
| 3792 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3793 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3794 | } finally { |
| 3795 | Binder.restoreCallingIdentity(identity); |
| 3796 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3797 | } |
| 3798 | |
| 3799 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3800 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3801 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3802 | |
| 3803 | final long identity = Binder.clearCallingIdentity(); |
| 3804 | try { |
| 3805 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3806 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3807 | } finally { |
| 3808 | Binder.restoreCallingIdentity(identity); |
| 3809 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3810 | } |
| 3811 | |
| 3812 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3813 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3814 | String callingPackage, int subId) { |
| 3815 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3816 | |
| 3817 | final long identity = Binder.clearCallingIdentity(); |
| 3818 | try { |
| 3819 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3820 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3821 | } finally { |
| 3822 | Binder.restoreCallingIdentity(identity); |
| 3823 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3824 | } |
| 3825 | |
| 3826 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3827 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3828 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3829 | |
| 3830 | final long identity = Binder.clearCallingIdentity(); |
| 3831 | try { |
| 3832 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3833 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3834 | } finally { |
| 3835 | Binder.restoreCallingIdentity(identity); |
| 3836 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3837 | } |
| 3838 | |
| 3839 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3840 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3841 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3842 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3843 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3844 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3845 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3846 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3847 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3848 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3849 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3850 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3851 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3852 | * Sets the voice activation state of a given subId. |
| 3853 | */ |
| 3854 | @Override |
| 3855 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3856 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3857 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3858 | |
| 3859 | final long identity = Binder.clearCallingIdentity(); |
| 3860 | try { |
| 3861 | final Phone phone = getPhone(subId); |
| 3862 | if (phone != null) { |
| 3863 | phone.setVoiceActivationState(activationState); |
| 3864 | } else { |
| 3865 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3866 | } |
| 3867 | } finally { |
| 3868 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3869 | } |
| 3870 | } |
| 3871 | |
| 3872 | /** |
| 3873 | * Sets the data activation state of a given subId. |
| 3874 | */ |
| 3875 | @Override |
| 3876 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3877 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3878 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3879 | |
| 3880 | final long identity = Binder.clearCallingIdentity(); |
| 3881 | try { |
| 3882 | final Phone phone = getPhone(subId); |
| 3883 | if (phone != null) { |
| 3884 | phone.setDataActivationState(activationState); |
| 3885 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3886 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3887 | } |
| 3888 | } finally { |
| 3889 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3890 | } |
| 3891 | } |
| 3892 | |
| 3893 | /** |
| 3894 | * Returns the voice activation state of a given subId. |
| 3895 | */ |
| 3896 | @Override |
| 3897 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3898 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3899 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3900 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3901 | final long identity = Binder.clearCallingIdentity(); |
| 3902 | try { |
| 3903 | if (phone != null) { |
| 3904 | return phone.getVoiceActivationState(); |
| 3905 | } else { |
| 3906 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3907 | } |
| 3908 | } finally { |
| 3909 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3910 | } |
| 3911 | } |
| 3912 | |
| 3913 | /** |
| 3914 | * Returns the data activation state of a given subId. |
| 3915 | */ |
| 3916 | @Override |
| 3917 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3918 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3919 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3920 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3921 | final long identity = Binder.clearCallingIdentity(); |
| 3922 | try { |
| 3923 | if (phone != null) { |
| 3924 | return phone.getDataActivationState(); |
| 3925 | } else { |
| 3926 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3927 | } |
| 3928 | } finally { |
| 3929 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3930 | } |
| 3931 | } |
| 3932 | |
| 3933 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3934 | * Returns the unread count of voicemails for a subId |
| 3935 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3936 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3937 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3938 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3939 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3940 | mApp, subId, callingPackage, callingFeatureId, |
| 3941 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3942 | return 0; |
| 3943 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3944 | final long identity = Binder.clearCallingIdentity(); |
| 3945 | try { |
| 3946 | final Phone phone = getPhone(subId); |
| 3947 | if (phone != null) { |
| 3948 | return phone.getVoiceMessageCount(); |
| 3949 | } else { |
| 3950 | return 0; |
| 3951 | } |
| 3952 | } finally { |
| 3953 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3954 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3955 | } |
| 3956 | |
| 3957 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3958 | * returns true, if the device is in a state where both voice and data |
| 3959 | * are supported simultaneously. This can change based on location or network condition. |
| 3960 | */ |
| 3961 | @Override |
| 3962 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3963 | final long identity = Binder.clearCallingIdentity(); |
| 3964 | try { |
| 3965 | final Phone phone = getPhone(subId); |
| 3966 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3967 | } finally { |
| 3968 | Binder.restoreCallingIdentity(identity); |
| 3969 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3970 | } |
| 3971 | |
| 3972 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3973 | * Send the dialer code if called from the current default dialer or the caller has |
| 3974 | * carrier privilege. |
| 3975 | * @param inputCode The dialer code to send |
| 3976 | */ |
| 3977 | @Override |
| 3978 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3979 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3980 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3981 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3982 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3983 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3984 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3985 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3986 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3987 | |
| 3988 | final long identity = Binder.clearCallingIdentity(); |
| 3989 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3990 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3991 | } finally { |
| 3992 | Binder.restoreCallingIdentity(identity); |
| 3993 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3994 | } |
| 3995 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3996 | @Override |
| 3997 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3998 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3999 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4000 | mApp, subId, "getNetworkSelectionMode"); |
| 4001 | final long identity = Binder.clearCallingIdentity(); |
| 4002 | try { |
| 4003 | if (!isActiveSubscription(subId)) { |
| 4004 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4005 | } |
| 4006 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4007 | } finally { |
| 4008 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4009 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4010 | } |
| 4011 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4012 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4013 | public boolean isInEmergencySmsMode() { |
| 4014 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4015 | final long identity = Binder.clearCallingIdentity(); |
| 4016 | try { |
| 4017 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4018 | if (phone.isInEmergencySmsMode()) { |
| 4019 | return true; |
| 4020 | } |
| 4021 | } |
| 4022 | } finally { |
| 4023 | Binder.restoreCallingIdentity(identity); |
| 4024 | } |
| 4025 | return false; |
| 4026 | } |
| 4027 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4028 | /** |
| 4029 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4030 | * @param subId The subscription to use to check the configuration. |
| 4031 | * @param c The callback that will be used to send the result. |
| 4032 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4033 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4034 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4035 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4036 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4037 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4038 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4039 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4040 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4041 | "IMS not available on device."); |
| 4042 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4043 | final long token = Binder.clearCallingIdentity(); |
| 4044 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4045 | int slotId = getSlotIndexOrException(subId); |
| 4046 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4047 | ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4048 | } catch (ImsException e) { |
| 4049 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4050 | } finally { |
| 4051 | Binder.restoreCallingIdentity(token); |
| 4052 | } |
| 4053 | } |
| 4054 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4055 | /** |
| 4056 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4057 | * @param subId The subscription to use to check the configuration. |
| 4058 | * @param c The callback that will be used to send the result. |
| 4059 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4060 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4061 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4062 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4063 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4064 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4065 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4066 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4067 | final long token = Binder.clearCallingIdentity(); |
| 4068 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4069 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 4070 | .removeRegistrationCallbackForSubscription(c, subId); |
| 4071 | } catch (ImsException e) { |
| 4072 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4073 | + "is inactive, ignoring unregister."); |
| 4074 | // If the subscription is no longer active, just return, since the callback |
| 4075 | // will already have been removed internally. |
| 4076 | } finally { |
| 4077 | Binder.restoreCallingIdentity(token); |
| 4078 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4079 | } |
| 4080 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4081 | /** |
| 4082 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4083 | */ |
| 4084 | @Override |
| 4085 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4086 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4087 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4088 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4089 | "IMS not available on device."); |
| 4090 | } |
| 4091 | final long token = Binder.clearCallingIdentity(); |
| 4092 | try { |
| 4093 | Phone phone = getPhone(subId); |
| 4094 | if (phone == null) { |
| 4095 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4096 | + subId + "'"); |
| 4097 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4098 | } |
| 4099 | phone.getImsRegistrationState(regState -> { |
| 4100 | try { |
| 4101 | consumer.accept((regState == null) |
| 4102 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4103 | } catch (RemoteException e) { |
| 4104 | // Ignore if the remote process is no longer available to call back. |
| 4105 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4106 | } |
| 4107 | }); |
| 4108 | } finally { |
| 4109 | Binder.restoreCallingIdentity(token); |
| 4110 | } |
| 4111 | } |
| 4112 | |
| 4113 | /** |
| 4114 | * Get the transport type for the IMS service registration state. |
| 4115 | */ |
| 4116 | @Override |
| 4117 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4118 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4119 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4120 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4121 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4122 | "IMS not available on device."); |
| 4123 | } |
| 4124 | final long token = Binder.clearCallingIdentity(); |
| 4125 | try { |
| 4126 | Phone phone = getPhone(subId); |
| 4127 | if (phone == null) { |
| 4128 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4129 | + subId + "'"); |
| 4130 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4131 | } |
| 4132 | phone.getImsRegistrationTech(regTech -> { |
| 4133 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4134 | int regTechConverted = (regTech == null) |
| 4135 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4136 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4137 | regTechConverted); |
| 4138 | try { |
| 4139 | consumer.accept(regTechConverted); |
| 4140 | } catch (RemoteException e) { |
| 4141 | // Ignore if the remote process is no longer available to call back. |
| 4142 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4143 | } |
| 4144 | }); |
| 4145 | } finally { |
| 4146 | Binder.restoreCallingIdentity(token); |
| 4147 | } |
| 4148 | } |
| 4149 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4150 | /** |
| 4151 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4152 | * @param subId The subscription to use to check the configuration. |
| 4153 | * @param c The callback that will be used to send the result. |
| 4154 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4155 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4156 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4157 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4158 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4159 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4160 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4161 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4162 | "IMS not available on device."); |
| 4163 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4164 | final long token = Binder.clearCallingIdentity(); |
| 4165 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4166 | int slotId = getSlotIndexOrException(subId); |
| 4167 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4168 | ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4169 | } catch (ImsException e) { |
| 4170 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4171 | } finally { |
| 4172 | Binder.restoreCallingIdentity(token); |
| 4173 | } |
| 4174 | } |
| 4175 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4176 | /** |
| 4177 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4178 | * @param subId The subscription to use to check the configuration. |
| 4179 | * @param c The callback that will be used to send the result. |
| 4180 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4181 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4182 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4183 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4184 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4185 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4186 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4187 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4188 | |
| 4189 | final long token = Binder.clearCallingIdentity(); |
| 4190 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4191 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4192 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4193 | } catch (ImsException e) { |
| 4194 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4195 | + "is inactive, ignoring unregister."); |
| 4196 | // If the subscription is no longer active, just return, since the callback |
| 4197 | // will already have been removed internally. |
| 4198 | } finally { |
| 4199 | Binder.restoreCallingIdentity(token); |
| 4200 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4201 | } |
| 4202 | |
| 4203 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4204 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4205 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4206 | final long token = Binder.clearCallingIdentity(); |
| 4207 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4208 | int slotId = getSlotIndexOrException(subId); |
| 4209 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4210 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4211 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4212 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4213 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4214 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4215 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4216 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4217 | } finally { |
| 4218 | Binder.restoreCallingIdentity(token); |
| 4219 | } |
| 4220 | } |
| 4221 | |
| 4222 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4223 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4224 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4225 | final long token = Binder.clearCallingIdentity(); |
| 4226 | try { |
| 4227 | Phone phone = getPhone(subId); |
| 4228 | if (phone == null) return false; |
| 4229 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4230 | } catch (com.android.ims.ImsException e) { |
| 4231 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4232 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4233 | } finally { |
| 4234 | Binder.restoreCallingIdentity(token); |
| 4235 | } |
| 4236 | } |
| 4237 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4238 | /** |
| 4239 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4240 | * subscription. |
| 4241 | * @param subId The subscription to use to check the configuration. |
| 4242 | * @param callback The callback that will be used to send the result. |
| 4243 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4244 | * @param transportType The transport type of the MmTelFeature capability. |
| 4245 | */ |
| 4246 | @Override |
| 4247 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4248 | int transportType) { |
| 4249 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 4250 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4251 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4252 | "IMS not available on device."); |
| 4253 | } |
| 4254 | final long token = Binder.clearCallingIdentity(); |
| 4255 | try { |
| 4256 | int slotId = getSlotIndex(subId); |
| 4257 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4258 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4259 | + subId + "'"); |
| 4260 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4261 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4262 | verifyImsMmTelConfiguredOrThrow(slotId); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4263 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4264 | transportType, aBoolean -> { |
| 4265 | try { |
| 4266 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4267 | } catch (RemoteException e) { |
| 4268 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4269 | + "running. Ignore"); |
| 4270 | } |
| 4271 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4272 | } catch (ImsException e) { |
| 4273 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4274 | } finally { |
| 4275 | Binder.restoreCallingIdentity(token); |
| 4276 | } |
| 4277 | } |
| 4278 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4279 | /** |
| 4280 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4281 | * @param subId The subscription to use to check the configuration. |
| 4282 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4283 | @Override |
| 4284 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4285 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4286 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4287 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4288 | final long token = Binder.clearCallingIdentity(); |
| 4289 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4290 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4291 | // 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] | 4292 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4293 | } catch (ImsException e) { |
| 4294 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4295 | } finally { |
| 4296 | Binder.restoreCallingIdentity(token); |
| 4297 | } |
| 4298 | } |
| 4299 | |
| 4300 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4301 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4302 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4303 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4304 | final long identity = Binder.clearCallingIdentity(); |
| 4305 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4306 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4307 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4308 | // 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] | 4309 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4310 | } catch (ImsException e) { |
| 4311 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4312 | } finally { |
| 4313 | Binder.restoreCallingIdentity(identity); |
| 4314 | } |
| 4315 | } |
| 4316 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4317 | /** |
| 4318 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4319 | * @param subId The subscription to use to check the configuration. |
| 4320 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4321 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4322 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4323 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4324 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4325 | final long identity = Binder.clearCallingIdentity(); |
| 4326 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4327 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4328 | // 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] | 4329 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4330 | } catch (ImsException e) { |
| 4331 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4332 | } finally { |
| 4333 | Binder.restoreCallingIdentity(identity); |
| 4334 | } |
| 4335 | } |
| 4336 | |
| 4337 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4338 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4339 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4340 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4341 | final long identity = Binder.clearCallingIdentity(); |
| 4342 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4343 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4344 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4345 | // 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] | 4346 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4347 | } catch (ImsException e) { |
| 4348 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4349 | } finally { |
| 4350 | Binder.restoreCallingIdentity(identity); |
| 4351 | } |
| 4352 | } |
| 4353 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4354 | /** |
| 4355 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4356 | * @param subId The subscription to use to check the configuration. |
| 4357 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4358 | @Override |
| 4359 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4360 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4361 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4362 | final long identity = Binder.clearCallingIdentity(); |
| 4363 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4364 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4365 | // 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] | 4366 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4367 | } catch (ImsException e) { |
| 4368 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4369 | } finally { |
| 4370 | Binder.restoreCallingIdentity(identity); |
| 4371 | } |
| 4372 | } |
| 4373 | |
| 4374 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4375 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4376 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4377 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4378 | final long identity = Binder.clearCallingIdentity(); |
| 4379 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4380 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4381 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4382 | // 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] | 4383 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4384 | } catch (ImsException e) { |
| 4385 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4386 | } finally { |
| 4387 | Binder.restoreCallingIdentity(identity); |
| 4388 | } |
| 4389 | } |
| 4390 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4391 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4392 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4393 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4394 | * @param subId The subscription to use to check the configuration. |
| 4395 | */ |
| 4396 | @Override |
| 4397 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4398 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4399 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4400 | final long identity = Binder.clearCallingIdentity(); |
| 4401 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4402 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4403 | // 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] | 4404 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4405 | } catch (ImsException e) { |
| 4406 | throw new ServiceSpecificException(e.getCode()); |
| 4407 | } finally { |
| 4408 | Binder.restoreCallingIdentity(identity); |
| 4409 | } |
| 4410 | } |
| 4411 | |
| 4412 | /** |
| 4413 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4414 | * Requires MODIFY_PHONE_STATE permission. |
| 4415 | * @param subId The subscription to use to check the configuration. |
| 4416 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4417 | * false otherwise |
| 4418 | */ |
| 4419 | @Override |
| 4420 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4421 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4422 | "setCrossSimCallingEnabled"); |
| 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 doesn't require an active ImsService connection, so do not verify. The |
| 4427 | // 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] | 4428 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4429 | } catch (ImsException e) { |
| 4430 | throw new ServiceSpecificException(e.getCode()); |
| 4431 | } finally { |
| 4432 | Binder.restoreCallingIdentity(identity); |
| 4433 | } |
| 4434 | } |
| 4435 | |
| 4436 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4437 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4438 | * @param subId The subscription to use to check the configuration. |
| 4439 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4440 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4441 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4442 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4443 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4444 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4445 | final long identity = Binder.clearCallingIdentity(); |
| 4446 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4447 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4448 | // 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] | 4449 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4450 | } catch (ImsException e) { |
| 4451 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4452 | } finally { |
| 4453 | Binder.restoreCallingIdentity(identity); |
| 4454 | } |
| 4455 | } |
| 4456 | |
| 4457 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4458 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4459 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4460 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4461 | final long identity = Binder.clearCallingIdentity(); |
| 4462 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4463 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4464 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4465 | // 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] | 4466 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4467 | } catch (ImsException e) { |
| 4468 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4469 | } finally { |
| 4470 | Binder.restoreCallingIdentity(identity); |
| 4471 | } |
| 4472 | } |
| 4473 | |
| 4474 | @Override |
| 4475 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4476 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4477 | "setVoWiFiNonPersistent"); |
| 4478 | final long identity = Binder.clearCallingIdentity(); |
| 4479 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4480 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4481 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4482 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4483 | } catch (ImsException e) { |
| 4484 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4485 | } finally { |
| 4486 | Binder.restoreCallingIdentity(identity); |
| 4487 | } |
| 4488 | } |
| 4489 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4490 | /** |
| 4491 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4492 | * @param subId The subscription to use to check the configuration. |
| 4493 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4494 | @Override |
| 4495 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4496 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4497 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4498 | final long identity = Binder.clearCallingIdentity(); |
| 4499 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4500 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4501 | // 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] | 4502 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4503 | } catch (ImsException e) { |
| 4504 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4505 | } finally { |
| 4506 | Binder.restoreCallingIdentity(identity); |
| 4507 | } |
| 4508 | } |
| 4509 | |
| 4510 | @Override |
| 4511 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4512 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4513 | "setVoWiFiModeSetting"); |
| 4514 | final long identity = Binder.clearCallingIdentity(); |
| 4515 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4516 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4517 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4518 | // 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] | 4519 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4520 | } catch (ImsException e) { |
| 4521 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4522 | } finally { |
| 4523 | Binder.restoreCallingIdentity(identity); |
| 4524 | } |
| 4525 | } |
| 4526 | |
| 4527 | @Override |
| 4528 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4529 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4530 | final long identity = Binder.clearCallingIdentity(); |
| 4531 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4532 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4533 | // 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] | 4534 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4535 | } catch (ImsException e) { |
| 4536 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4537 | } finally { |
| 4538 | Binder.restoreCallingIdentity(identity); |
| 4539 | } |
| 4540 | } |
| 4541 | |
| 4542 | @Override |
| 4543 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4544 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4545 | "setVoWiFiRoamingModeSetting"); |
| 4546 | final long identity = Binder.clearCallingIdentity(); |
| 4547 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4548 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4549 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4550 | // 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] | 4551 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4552 | } catch (ImsException e) { |
| 4553 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4554 | } finally { |
| 4555 | Binder.restoreCallingIdentity(identity); |
| 4556 | } |
| 4557 | } |
| 4558 | |
| 4559 | @Override |
| 4560 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4561 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4562 | "setRttCapabilityEnabled"); |
| 4563 | final long identity = Binder.clearCallingIdentity(); |
| 4564 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4565 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4566 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4567 | // 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] | 4568 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4569 | } catch (ImsException e) { |
| 4570 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4571 | } finally { |
| 4572 | Binder.restoreCallingIdentity(identity); |
| 4573 | } |
| 4574 | } |
| 4575 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4576 | /** |
| 4577 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4578 | * @param subId The subscription to use to check the configuration. |
| 4579 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4580 | @Override |
| 4581 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4582 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4583 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4584 | final long identity = Binder.clearCallingIdentity(); |
| 4585 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4586 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4587 | // 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] | 4588 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4589 | } catch (ImsException e) { |
| 4590 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4591 | } finally { |
| 4592 | Binder.restoreCallingIdentity(identity); |
| 4593 | } |
| 4594 | } |
| 4595 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4596 | @Override |
| 4597 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4598 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame^] | 4599 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4600 | final long identity = Binder.clearCallingIdentity(); |
| 4601 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4602 | if (!isImsAvailableOnDevice()) { |
| 4603 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4604 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4605 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4606 | int slotId = getSlotIndexOrException(subId); |
| 4607 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4608 | ImsManager.getInstance(mApp, slotId) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4609 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4610 | } catch (ImsException e) { |
| 4611 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4612 | } finally { |
| 4613 | Binder.restoreCallingIdentity(identity); |
| 4614 | } |
| 4615 | } |
| 4616 | |
| 4617 | @Override |
| 4618 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4619 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame^] | 4620 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4621 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4622 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4623 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4624 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4625 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4626 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4627 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4628 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4629 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4630 | + "is inactive, ignoring unregister."); |
| 4631 | // If the subscription is no longer active, just return, since the callback will already |
| 4632 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4633 | } finally { |
| 4634 | Binder.restoreCallingIdentity(identity); |
| 4635 | } |
| 4636 | } |
| 4637 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame^] | 4638 | @Override |
| 4639 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 4640 | IFeatureProvisioningCallback callback) { |
| 4641 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4642 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 4643 | |
| 4644 | final long identity = Binder.clearCallingIdentity(); |
| 4645 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4646 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4647 | } |
| 4648 | |
| 4649 | ImsProvisioningController.getInstance() |
| 4650 | .addFeatureProvisioningChangedCallback(subId, callback); |
| 4651 | |
| 4652 | Binder.restoreCallingIdentity(identity); |
| 4653 | } |
| 4654 | |
| 4655 | @Override |
| 4656 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 4657 | IFeatureProvisioningCallback callback) { |
| 4658 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4659 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 4660 | |
| 4661 | final long identity = Binder.clearCallingIdentity(); |
| 4662 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4663 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4664 | } |
| 4665 | |
| 4666 | ImsProvisioningController.getInstance() |
| 4667 | .removeFeatureProvisioningChangedCallback(subId, callback); |
| 4668 | |
| 4669 | Binder.restoreCallingIdentity(identity); |
| 4670 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4671 | |
| 4672 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4673 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4674 | message); |
| 4675 | } |
| 4676 | |
| 4677 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4678 | boolean isMmtelCapability) { |
| 4679 | Phone phone = getPhone(subId); |
| 4680 | if (phone == null) { |
| 4681 | loge("phone instance null for subid " + subId); |
| 4682 | return false; |
| 4683 | } |
| 4684 | if (isMmtelCapability) { |
| 4685 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4686 | return false; |
| 4687 | } |
| 4688 | } else { |
| 4689 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4690 | return false; |
| 4691 | } |
| 4692 | } |
| 4693 | return true; |
| 4694 | } |
| 4695 | |
| 4696 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame^] | 4697 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4698 | boolean isProvisioned) { |
| 4699 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4700 | |
| 4701 | final long identity = Binder.clearCallingIdentity(); |
| 4702 | try { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame^] | 4703 | ImsProvisioningController.getInstance() |
| 4704 | .setRcsProvisioningStatusForCapability(subId, capability, tech, isProvisioned); |
| 4705 | return; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4706 | } finally { |
| 4707 | Binder.restoreCallingIdentity(identity); |
| 4708 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4709 | } |
| 4710 | |
| 4711 | |
| 4712 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame^] | 4713 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4714 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4715 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 4716 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4717 | final long identity = Binder.clearCallingIdentity(); |
| 4718 | try { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame^] | 4719 | return ImsProvisioningController.getInstance() |
| 4720 | .getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4721 | } finally { |
| 4722 | Binder.restoreCallingIdentity(identity); |
| 4723 | } |
| 4724 | } |
| 4725 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4726 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4727 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4728 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4729 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame^] | 4730 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4731 | final long identity = Binder.clearCallingIdentity(); |
| 4732 | try { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame^] | 4733 | ImsProvisioningController.getInstance() |
| 4734 | .setImsProvisioningStatusForCapability(subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4735 | } finally { |
| 4736 | Binder.restoreCallingIdentity(identity); |
| 4737 | } |
| 4738 | } |
| 4739 | |
| 4740 | @Override |
| 4741 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame^] | 4742 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4743 | mApp, subId, "getProvisioningStatusForCapability"); |
| 4744 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4745 | final long identity = Binder.clearCallingIdentity(); |
| 4746 | try { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame^] | 4747 | return ImsProvisioningController.getInstance() |
| 4748 | .getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4749 | |
| 4750 | } finally { |
| 4751 | Binder.restoreCallingIdentity(identity); |
| 4752 | } |
| 4753 | } |
| 4754 | |
| 4755 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame^] | 4756 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4757 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4758 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 4759 | |
| 4760 | final long identity = Binder.clearCallingIdentity(); |
| 4761 | try { |
| 4762 | return ImsProvisioningController.getInstance() |
| 4763 | .isImsProvisioningRequiredForCapability(subId, capability, tech); |
| 4764 | } finally { |
| 4765 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4766 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4767 | } |
| 4768 | |
| 4769 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame^] | 4770 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4771 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4772 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4773 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame^] | 4774 | final long identity = Binder.clearCallingIdentity(); |
| 4775 | try { |
| 4776 | return ImsProvisioningController.getInstance() |
| 4777 | .isRcsProvisioningRequiredForCapability(subId, capability, tech); |
| 4778 | } finally { |
| 4779 | Binder.restoreCallingIdentity(identity); |
| 4780 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4781 | } |
| 4782 | |
| 4783 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4784 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4785 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4786 | } |
| 4787 | |
| 4788 | /** |
| 4789 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4790 | * carrier associated with the subscription id. |
| 4791 | */ |
| 4792 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4793 | int capability) { |
| 4794 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4795 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4796 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4797 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4798 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4799 | false); |
| 4800 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4801 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4802 | |
| 4803 | // First check to make sure that the capability requires provisioning. |
| 4804 | switch (capability) { |
| 4805 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4806 | // intentional fallthrough |
| 4807 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4808 | if (requireVoiceVtProvisioning) { |
| 4809 | // Voice and Video requires provisioning |
| 4810 | return true; |
| 4811 | } |
| 4812 | break; |
| 4813 | } |
| 4814 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4815 | if (requireUtProvisioning) { |
| 4816 | // UT requires provisioning |
| 4817 | return true; |
| 4818 | } |
| 4819 | break; |
| 4820 | } |
| 4821 | } |
| 4822 | return false; |
| 4823 | } |
| 4824 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4825 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4826 | int capability) { |
| 4827 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4828 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4829 | |
| 4830 | boolean requireRcsProvisioning = c.getBoolean( |
| 4831 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4832 | |
| 4833 | // First check to make sure that the capability requires provisioning. |
| 4834 | switch (capability) { |
| 4835 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4836 | // intentional fallthrough |
| 4837 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4838 | if (requireRcsProvisioning) { |
| 4839 | // OPTION or PRESENCE requires provisioning |
| 4840 | return true; |
| 4841 | } |
| 4842 | break; |
| 4843 | } |
| 4844 | } |
| 4845 | return false; |
| 4846 | } |
| 4847 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4848 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4849 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4850 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4851 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4852 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame^] | 4853 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4854 | mApp, subId, "getImsProvisioningInt"); |
| 4855 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4856 | final long identity = Binder.clearCallingIdentity(); |
| 4857 | try { |
| 4858 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4859 | int slotId = getSlotIndex(subId); |
| 4860 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4861 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4862 | + subId + "' for key:" + key); |
| 4863 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4864 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame^] | 4865 | |
| 4866 | int retVal = ImsProvisioningController.getInstance().getProvisioningValue(subId, key); |
| 4867 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 4868 | return retVal; |
| 4869 | } |
| 4870 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4871 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4872 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4873 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4874 | + subId + "' for key:" + key); |
| 4875 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4876 | } finally { |
| 4877 | Binder.restoreCallingIdentity(identity); |
| 4878 | } |
| 4879 | } |
| 4880 | |
| 4881 | @Override |
| 4882 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4883 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4884 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4885 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame^] | 4886 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4887 | mApp, subId, "getImsProvisioningString"); |
| 4888 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4889 | final long identity = Binder.clearCallingIdentity(); |
| 4890 | try { |
| 4891 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4892 | int slotId = getSlotIndex(subId); |
| 4893 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4894 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4895 | + subId + "' for key:" + key); |
| 4896 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4897 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4898 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4899 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4900 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4901 | + subId + "' for key:" + key); |
| 4902 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4903 | } finally { |
| 4904 | Binder.restoreCallingIdentity(identity); |
| 4905 | } |
| 4906 | } |
| 4907 | |
| 4908 | @Override |
| 4909 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4910 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4911 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4912 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4913 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4914 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame^] | 4915 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4916 | final long identity = Binder.clearCallingIdentity(); |
| 4917 | try { |
| 4918 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4919 | int slotId = getSlotIndex(subId); |
| 4920 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4921 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4922 | + subId + "' for key:" + key); |
| 4923 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4924 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame^] | 4925 | |
| 4926 | int retVal = ImsProvisioningController.getInstance() |
| 4927 | .setProvisioningValue(subId, key, value); |
| 4928 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 4929 | return retVal; |
| 4930 | } |
| 4931 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4932 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4933 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4934 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4935 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4936 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4937 | } finally { |
| 4938 | Binder.restoreCallingIdentity(identity); |
| 4939 | } |
| 4940 | } |
| 4941 | |
| 4942 | @Override |
| 4943 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4944 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4945 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4946 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4947 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4948 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4949 | final long identity = Binder.clearCallingIdentity(); |
| 4950 | try { |
| 4951 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4952 | int slotId = getSlotIndex(subId); |
| 4953 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4954 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4955 | + subId + "' for key:" + key); |
| 4956 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4957 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4958 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4959 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4960 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4961 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4962 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4963 | } finally { |
| 4964 | Binder.restoreCallingIdentity(identity); |
| 4965 | } |
| 4966 | } |
| 4967 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4968 | /** |
| 4969 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 4970 | * for the given slot ID or no ImsResolver instance has been created. |
| 4971 | * @param slotId The slot ID that the IMS service is created for. |
| 4972 | * @throws ImsException If there is no ImsService configured for this slot. |
| 4973 | */ |
| 4974 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 4975 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 4976 | ImsFeature.FEATURE_MMTEL)) { |
| 4977 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 4978 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4979 | } |
| 4980 | } |
| 4981 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4982 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4983 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4984 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4985 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4986 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4987 | } |
| 4988 | return slotId; |
| 4989 | } |
| 4990 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4991 | private int getSlotIndex(int subId) { |
| 4992 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4993 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4994 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4995 | } |
| 4996 | return slotId; |
| 4997 | } |
| 4998 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4999 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5000 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5001 | */ |
| 5002 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5003 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5004 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5005 | try { |
| 5006 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5007 | } catch (SecurityException se) { |
| 5008 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5009 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5010 | + Binder.getCallingUid()); |
| 5011 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5012 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5013 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5014 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5015 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5016 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5017 | mApp, subId, callingPackage, callingFeatureId, |
| 5018 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5019 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5020 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5021 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5022 | final long identity = Binder.clearCallingIdentity(); |
| 5023 | try { |
| 5024 | final Phone phone = getPhone(subId); |
| 5025 | if (phone != null) { |
| 5026 | return phone.getServiceState().getDataNetworkType(); |
| 5027 | } else { |
| 5028 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5029 | } |
| 5030 | } finally { |
| 5031 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5032 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5033 | } |
| 5034 | |
| 5035 | /** |
| 5036 | * Returns the data network type |
| 5037 | */ |
| 5038 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5039 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5040 | return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(), |
| 5041 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5042 | } |
| 5043 | |
| 5044 | /** |
| 5045 | * Returns the data network type for a subId |
| 5046 | */ |
| 5047 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5048 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5049 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5050 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5051 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5052 | mApp, functionName)) { |
| 5053 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5054 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5055 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5056 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5057 | } |
| 5058 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5059 | final long identity = Binder.clearCallingIdentity(); |
| 5060 | try { |
| 5061 | final Phone phone = getPhone(subId); |
| 5062 | if (phone != null) { |
| 5063 | return phone.getServiceState().getDataNetworkType(); |
| 5064 | } else { |
| 5065 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5066 | } |
| 5067 | } finally { |
| 5068 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5069 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5070 | } |
| 5071 | |
| 5072 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5073 | * Returns the Voice network type for a subId |
| 5074 | */ |
| 5075 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5076 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5077 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5078 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5079 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5080 | mApp, functionName)) { |
| 5081 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5082 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5083 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5084 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5085 | } |
| 5086 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5087 | final long identity = Binder.clearCallingIdentity(); |
| 5088 | try { |
| 5089 | final Phone phone = getPhone(subId); |
| 5090 | if (phone != null) { |
| 5091 | return phone.getServiceState().getVoiceNetworkType(); |
| 5092 | } else { |
| 5093 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5094 | } |
| 5095 | } finally { |
| 5096 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5097 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5098 | } |
| 5099 | |
| 5100 | /** |
| 5101 | * @return true if a ICC card is present |
| 5102 | */ |
| 5103 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5104 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5105 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 5106 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5107 | } |
| 5108 | |
| 5109 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5110 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5111 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5112 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5113 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5114 | final long identity = Binder.clearCallingIdentity(); |
| 5115 | try { |
| 5116 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5117 | if (phone != null) { |
| 5118 | return phone.getIccCard().hasIccCard(); |
| 5119 | } else { |
| 5120 | return false; |
| 5121 | } |
| 5122 | } finally { |
| 5123 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5124 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5125 | } |
| 5126 | |
| 5127 | /** |
| 5128 | * Return if the current radio is LTE on CDMA. This |
| 5129 | * is a tri-state return value as for a period of time |
| 5130 | * the mode may be unknown. |
| 5131 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5132 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5133 | * @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] | 5134 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5135 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5136 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5137 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5138 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5139 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5140 | } |
| 5141 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5142 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5143 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5144 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5145 | try { |
| 5146 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5147 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5148 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5149 | } |
| 5150 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5151 | final long identity = Binder.clearCallingIdentity(); |
| 5152 | try { |
| 5153 | final Phone phone = getPhone(subId); |
| 5154 | if (phone == null) { |
| 5155 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5156 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5157 | return TelephonyProperties.lte_on_cdma_device() |
| 5158 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5159 | } |
| 5160 | } finally { |
| 5161 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5162 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5163 | } |
| 5164 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5165 | /** |
| 5166 | * {@hide} |
| 5167 | * Returns Default subId, 0 in the case of single standby. |
| 5168 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5169 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5170 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5171 | } |
| 5172 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5173 | private int getSlotForDefaultSubscription() { |
| 5174 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 5175 | } |
| 5176 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5177 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5178 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5179 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5180 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5181 | private boolean isActiveSubscription(int subId) { |
| 5182 | return mSubscriptionController.isActiveSubId(subId); |
| 5183 | } |
| 5184 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5185 | /** |
| 5186 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5187 | */ |
| 5188 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5189 | final long identity = Binder.clearCallingIdentity(); |
| 5190 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5191 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5192 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5193 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5194 | } finally { |
| 5195 | Binder.restoreCallingIdentity(identity); |
| 5196 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5197 | } |
| 5198 | |
| 5199 | /** |
| 5200 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5201 | */ |
| 5202 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5203 | final long identity = Binder.clearCallingIdentity(); |
| 5204 | try { |
| 5205 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5206 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5207 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5208 | } finally { |
| 5209 | Binder.restoreCallingIdentity(identity); |
| 5210 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5211 | } |
| 5212 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5213 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5214 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5215 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5216 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5217 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5218 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5219 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5220 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5221 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5222 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
| 5223 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5224 | } |
| 5225 | return PhoneFactory.getPhone(phoneId); |
| 5226 | } |
| 5227 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5228 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5229 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5230 | @NonNull IccLogicalChannelRequest request) { |
| 5231 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5232 | /*message=*/ "iccOpenLogicalChannel"); |
| 5233 | |
| 5234 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5235 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5236 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5237 | |
| 5238 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5239 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5240 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5241 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5242 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5243 | Phone phone; |
| 5244 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5245 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5246 | mApp, request.subId, message); |
| 5247 | phone = getPhoneFromSubId(request.subId); |
| 5248 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5249 | enforceModifyPermission(); |
| 5250 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5251 | } else { |
| 5252 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5253 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5254 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5255 | } |
| 5256 | |
| 5257 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5258 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5259 | final long identity = Binder.clearCallingIdentity(); |
| 5260 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5261 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5262 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5263 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5264 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5265 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5266 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5267 | loge("The calling package is not allowed to access ISD-R."); |
| 5268 | throw new SecurityException( |
| 5269 | "The calling package is not allowed to access ISD-R."); |
| 5270 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5271 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5272 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5273 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5274 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5275 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5276 | return response; |
| 5277 | } finally { |
| 5278 | Binder.restoreCallingIdentity(identity); |
| 5279 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5280 | } |
| 5281 | |
| 5282 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5283 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5284 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5285 | /*message=*/"iccCloseLogicalChannel"); |
| 5286 | |
| 5287 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5288 | |
| 5289 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5290 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5291 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5292 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5293 | IccLogicalChannelRequest request) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5294 | final long identity = Binder.clearCallingIdentity(); |
| 5295 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5296 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5297 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5298 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5299 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5300 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5301 | Boolean success = false; |
| 5302 | if (result instanceof RuntimeException) { |
| 5303 | // if there is an exception returned, throw from the binder thread here. |
| 5304 | throw (RuntimeException) result; |
| 5305 | } else if (result instanceof Boolean) { |
| 5306 | success = (Boolean) result; |
| 5307 | } else { |
| 5308 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5309 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5310 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5311 | return success; |
| 5312 | } finally { |
| 5313 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5314 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5315 | } |
| 5316 | |
| 5317 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5318 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5319 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5320 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5321 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5322 | if (DBG) { |
| 5323 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5324 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5325 | + p3 + " data=" + data); |
| 5326 | } |
| 5327 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5328 | command, p1, p2, p3, data); |
| 5329 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5330 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5331 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5332 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
| 5333 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5334 | enforceModifyPermission(); |
| 5335 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5336 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5337 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5338 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5339 | } |
| 5340 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5341 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5342 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5343 | } |
| 5344 | |
| 5345 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5346 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5347 | final long identity = Binder.clearCallingIdentity(); |
| 5348 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5349 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5350 | return ""; |
| 5351 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5352 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5353 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5354 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5355 | null /* workSource */); |
| 5356 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5357 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5358 | // Append the returned status code to the end of the response payload. |
| 5359 | String s = Integer.toHexString( |
| 5360 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5361 | if (response.payload != null) { |
| 5362 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5363 | } |
| 5364 | return s; |
| 5365 | } finally { |
| 5366 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5367 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5368 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5369 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5370 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5371 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5372 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5373 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5374 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5375 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5376 | if (DBG) { |
| 5377 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5378 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5379 | } |
| 5380 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5381 | cla, command, p1, p2, p3, data); |
| 5382 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5383 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5384 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5385 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
| 5386 | 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] | 5387 | enforceModifyPermission(); |
| 5388 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5389 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5390 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5391 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5392 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5393 | } |
| 5394 | |
| 5395 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5396 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5397 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5398 | } |
| 5399 | |
| 5400 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5401 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5402 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5403 | final long identity = Binder.clearCallingIdentity(); |
| 5404 | try { |
| 5405 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5406 | && TextUtils.equals(ISDR_AID, data)) { |
| 5407 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5408 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5409 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5410 | if (bestComponent == null |
| 5411 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5412 | loge("The calling package is not allowed to select ISD-R."); |
| 5413 | throw new SecurityException( |
| 5414 | "The calling package is not allowed to select ISD-R."); |
| 5415 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5416 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5417 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5418 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5419 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5420 | null /* workSource */); |
| 5421 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5422 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5423 | // Append the returned status code to the end of the response payload. |
| 5424 | String s = Integer.toHexString( |
| 5425 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5426 | if (response.payload != null) { |
| 5427 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5428 | } |
| 5429 | return s; |
| 5430 | } finally { |
| 5431 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5432 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5433 | } |
| 5434 | |
| 5435 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5436 | 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] | 5437 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5438 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5439 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5440 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5441 | final long identity = Binder.clearCallingIdentity(); |
| 5442 | try { |
| 5443 | if (DBG) { |
| 5444 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5445 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5446 | } |
| 5447 | |
| 5448 | IccIoResult response = |
| 5449 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5450 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5451 | subId); |
| 5452 | |
| 5453 | if (DBG) { |
| 5454 | log("Exchange SIM_IO [R]" + response); |
| 5455 | } |
| 5456 | |
| 5457 | byte[] result = null; |
| 5458 | int length = 2; |
| 5459 | if (response.payload != null) { |
| 5460 | length = 2 + response.payload.length; |
| 5461 | result = new byte[length]; |
| 5462 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5463 | } else { |
| 5464 | result = new byte[length]; |
| 5465 | } |
| 5466 | |
| 5467 | result[length - 1] = (byte) response.sw2; |
| 5468 | result[length - 2] = (byte) response.sw1; |
| 5469 | return result; |
| 5470 | } finally { |
| 5471 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5472 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5473 | } |
| 5474 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5475 | /** |
| 5476 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5477 | * on a particular subscription |
| 5478 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5479 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5480 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5481 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5482 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5483 | return null; |
| 5484 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5485 | |
| 5486 | final long identity = Binder.clearCallingIdentity(); |
| 5487 | try { |
| 5488 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5489 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5490 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5491 | return null; |
| 5492 | } |
| 5493 | Object response = sendRequest( |
| 5494 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5495 | if (response instanceof String[]) { |
| 5496 | return (String[]) response; |
| 5497 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5498 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5499 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5500 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5501 | } finally { |
| 5502 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5503 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5504 | } |
| 5505 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5506 | /** |
| 5507 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5508 | * subscription. |
| 5509 | * |
| 5510 | * @param subId the id of the subscription. |
| 5511 | * @param appType the uicc app type, must be USIM or SIM. |
| 5512 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5513 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5514 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5515 | * @return number of fplmns that is successfully written to the SIM. |
| 5516 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5517 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5518 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5519 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5520 | mApp, subId, "setForbiddenPlmns"); |
| 5521 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5522 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5523 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5524 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5525 | } |
| 5526 | if (fplmns == null) { |
| 5527 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5528 | } |
| 5529 | for (String fplmn : fplmns) { |
| 5530 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5531 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5532 | } |
| 5533 | } |
| 5534 | final long identity = Binder.clearCallingIdentity(); |
| 5535 | try { |
| 5536 | Object response = sendRequest( |
| 5537 | CMD_SET_FORBIDDEN_PLMNS, |
| 5538 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5539 | subId); |
| 5540 | return (int) response; |
| 5541 | } finally { |
| 5542 | Binder.restoreCallingIdentity(identity); |
| 5543 | } |
| 5544 | } |
| 5545 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5546 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5547 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5548 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5549 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5550 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5551 | final long identity = Binder.clearCallingIdentity(); |
| 5552 | try { |
| 5553 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5554 | if (response.payload == null) { |
| 5555 | return ""; |
| 5556 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5557 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5558 | // Append the returned status code to the end of the response payload. |
| 5559 | String s = Integer.toHexString( |
| 5560 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5561 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5562 | return s; |
| 5563 | } finally { |
| 5564 | Binder.restoreCallingIdentity(identity); |
| 5565 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5566 | } |
| 5567 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5568 | /** |
| 5569 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5570 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5571 | * |
| 5572 | * @param itemID the ID of the item to read |
| 5573 | * @return the NV item as a String, or null on error. |
| 5574 | */ |
| 5575 | @Override |
| 5576 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5577 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5578 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5579 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5580 | |
| 5581 | final long identity = Binder.clearCallingIdentity(); |
| 5582 | try { |
| 5583 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5584 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5585 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5586 | return value; |
| 5587 | } finally { |
| 5588 | Binder.restoreCallingIdentity(identity); |
| 5589 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5590 | } |
| 5591 | |
| 5592 | /** |
| 5593 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5594 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5595 | * |
| 5596 | * @param itemID the ID of the item to read |
| 5597 | * @param itemValue the value to write, as a String |
| 5598 | * @return true on success; false on any failure |
| 5599 | */ |
| 5600 | @Override |
| 5601 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5602 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5603 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5604 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5605 | |
| 5606 | final long identity = Binder.clearCallingIdentity(); |
| 5607 | try { |
| 5608 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5609 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5610 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5611 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5612 | return success; |
| 5613 | } finally { |
| 5614 | Binder.restoreCallingIdentity(identity); |
| 5615 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5616 | } |
| 5617 | |
| 5618 | /** |
| 5619 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5620 | * Used for device configuration by some CDMA operators. |
| 5621 | * |
| 5622 | * @param preferredRoamingList byte array containing the new PRL |
| 5623 | * @return true on success; false on any failure |
| 5624 | */ |
| 5625 | @Override |
| 5626 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5627 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5628 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5629 | |
| 5630 | final long identity = Binder.clearCallingIdentity(); |
| 5631 | try { |
| 5632 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5633 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5634 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5635 | return success; |
| 5636 | } finally { |
| 5637 | Binder.restoreCallingIdentity(identity); |
| 5638 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5639 | } |
| 5640 | |
| 5641 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5642 | * 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] | 5643 | * Used for device configuration by some CDMA operators. |
| 5644 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5645 | * @param slotIndex - device slot. |
| 5646 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5647 | * @return true on success; false on any failure |
| 5648 | */ |
| 5649 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5650 | public boolean resetModemConfig(int slotIndex) { |
| 5651 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5652 | if (phone != null) { |
| 5653 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5654 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5655 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5656 | final long identity = Binder.clearCallingIdentity(); |
| 5657 | try { |
| 5658 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5659 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5660 | return success; |
| 5661 | } finally { |
| 5662 | Binder.restoreCallingIdentity(identity); |
| 5663 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5664 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5665 | return false; |
| 5666 | } |
| 5667 | |
| 5668 | /** |
| 5669 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5670 | * |
| 5671 | * @param slotIndex - device slot. |
| 5672 | * |
| 5673 | * @return true on success; false on any failure |
| 5674 | */ |
| 5675 | @Override |
| 5676 | public boolean rebootModem(int slotIndex) { |
| 5677 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5678 | if (phone != null) { |
| 5679 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5680 | mApp, phone.getSubId(), "rebootModem"); |
| 5681 | |
| 5682 | final long identity = Binder.clearCallingIdentity(); |
| 5683 | try { |
| 5684 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5685 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5686 | return success; |
| 5687 | } finally { |
| 5688 | Binder.restoreCallingIdentity(identity); |
| 5689 | } |
| 5690 | } |
| 5691 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5692 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5693 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5694 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5695 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5696 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5697 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5698 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5699 | return new String[0]; |
| 5700 | } |
| 5701 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5702 | final long identity = Binder.clearCallingIdentity(); |
| 5703 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5704 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5705 | } finally { |
| 5706 | Binder.restoreCallingIdentity(identity); |
| 5707 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5708 | } |
| 5709 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5710 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5711 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5712 | * {@link #disableIms(int)}. |
| 5713 | * @param slotIndex device slot. |
| 5714 | */ |
| 5715 | public void resetIms(int slotIndex) { |
| 5716 | enforceModifyPermission(); |
| 5717 | |
| 5718 | final long identity = Binder.clearCallingIdentity(); |
| 5719 | try { |
| 5720 | if (mImsResolver == null) { |
| 5721 | // may happen if the does not support IMS. |
| 5722 | return; |
| 5723 | } |
| 5724 | mImsResolver.disableIms(slotIndex); |
| 5725 | mImsResolver.enableIms(slotIndex); |
| 5726 | } finally { |
| 5727 | Binder.restoreCallingIdentity(identity); |
| 5728 | } |
| 5729 | } |
| 5730 | |
| 5731 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5732 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5733 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5734 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5735 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5736 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5737 | |
| 5738 | final long identity = Binder.clearCallingIdentity(); |
| 5739 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5740 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5741 | // may happen if the device does not support IMS. |
| 5742 | return; |
| 5743 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5744 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5745 | } finally { |
| 5746 | Binder.restoreCallingIdentity(identity); |
| 5747 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5748 | } |
| 5749 | |
| 5750 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5751 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5752 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5753 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5754 | public void disableIms(int slotId) { |
| 5755 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5756 | |
| 5757 | final long identity = Binder.clearCallingIdentity(); |
| 5758 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5759 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5760 | // may happen if the device does not support IMS. |
| 5761 | return; |
| 5762 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5763 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5764 | } finally { |
| 5765 | Binder.restoreCallingIdentity(identity); |
| 5766 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5767 | } |
| 5768 | |
| 5769 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5770 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5771 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5772 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5773 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5774 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5775 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5776 | |
| 5777 | final long identity = Binder.clearCallingIdentity(); |
| 5778 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5779 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5780 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5781 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5782 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5783 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5784 | } finally { |
| 5785 | Binder.restoreCallingIdentity(identity); |
| 5786 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5787 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5788 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5789 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5790 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5791 | @Override |
| 5792 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5793 | enforceModifyPermission(); |
| 5794 | |
| 5795 | final long identity = Binder.clearCallingIdentity(); |
| 5796 | try { |
| 5797 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5798 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5799 | } finally { |
| 5800 | Binder.restoreCallingIdentity(identity); |
| 5801 | } |
| 5802 | } |
| 5803 | |
| 5804 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5805 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5806 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5807 | */ |
| 5808 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5809 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5810 | |
| 5811 | final long identity = Binder.clearCallingIdentity(); |
| 5812 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5813 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5814 | // may happen if the device does not support IMS. |
| 5815 | return null; |
| 5816 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5817 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5818 | } finally { |
| 5819 | Binder.restoreCallingIdentity(identity); |
| 5820 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5821 | } |
| 5822 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5823 | /** |
| 5824 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5825 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5826 | */ |
| 5827 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5828 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5829 | |
| 5830 | final long identity = Binder.clearCallingIdentity(); |
| 5831 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5832 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5833 | // may happen if the device does not support IMS. |
| 5834 | return null; |
| 5835 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5836 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5837 | } finally { |
| 5838 | Binder.restoreCallingIdentity(identity); |
| 5839 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5840 | } |
| 5841 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5842 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5843 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5844 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5845 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5846 | * @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] | 5847 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5848 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5849 | * @param packageName The name of the package that the current configuration will be replaced |
| 5850 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5851 | * @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] | 5852 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5853 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5854 | int[] featureTypes, String packageName) { |
| 5855 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5856 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5857 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5858 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5859 | "setBoundImsServiceOverride"); |
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 false; |
| 5866 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5867 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5868 | for (int featureType : featureTypes) { |
| 5869 | featureConfig.put(featureType, packageName); |
| 5870 | } |
| 5871 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5872 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5873 | } finally { |
| 5874 | Binder.restoreCallingIdentity(identity); |
| 5875 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5876 | } |
| 5877 | |
| 5878 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5879 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5880 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5881 | * |
| 5882 | * This should only be used for testing. |
| 5883 | * |
| 5884 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5885 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5886 | */ |
| 5887 | @Override |
| 5888 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5889 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5890 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5891 | "clearCarrierImsServiceOverride"); |
| 5892 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5893 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5894 | "clearCarrierImsServiceOverride"); |
| 5895 | |
| 5896 | final long identity = Binder.clearCallingIdentity(); |
| 5897 | try { |
| 5898 | if (mImsResolver == null) { |
| 5899 | // may happen if the device does not support IMS. |
| 5900 | return false; |
| 5901 | } |
| 5902 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5903 | } finally { |
| 5904 | Binder.restoreCallingIdentity(identity); |
| 5905 | } |
| 5906 | } |
| 5907 | |
| 5908 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5909 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5910 | * |
| 5911 | * @param slotId The slot that the ImsService is associated with. |
| 5912 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5913 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5914 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5915 | * @return the package name of the ImsService configuration. |
| 5916 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5917 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5918 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5919 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5920 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5921 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5922 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5923 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5924 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5925 | final long identity = Binder.clearCallingIdentity(); |
| 5926 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5927 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5928 | // may happen if the device does not support IMS. |
| 5929 | return ""; |
| 5930 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5931 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5932 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5933 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5934 | } finally { |
| 5935 | Binder.restoreCallingIdentity(identity); |
| 5936 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5937 | } |
| 5938 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5939 | /** |
| 5940 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5941 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5942 | * @param callback A callback with an integer containing the |
| 5943 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5944 | */ |
| 5945 | @Override |
| 5946 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5947 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5948 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5949 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5950 | "IMS not available on device."); |
| 5951 | } |
| 5952 | final long token = Binder.clearCallingIdentity(); |
| 5953 | try { |
| 5954 | int slotId = getSlotIndex(subId); |
| 5955 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5956 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5957 | + subId + "'"); |
| 5958 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5959 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5960 | verifyImsMmTelConfiguredOrThrow(slotId); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5961 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5962 | try { |
| 5963 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5964 | } catch (RemoteException e) { |
| 5965 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5966 | + "Ignore"); |
| 5967 | } |
| 5968 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5969 | } catch (ImsException e) { |
| 5970 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5971 | } finally { |
| 5972 | Binder.restoreCallingIdentity(token); |
| 5973 | } |
| 5974 | } |
| 5975 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5976 | /** |
| 5977 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5978 | */ |
| 5979 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5980 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5981 | |
| 5982 | final long identity = Binder.clearCallingIdentity(); |
| 5983 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5984 | // NOTE: Before S, this method only set the default phone. |
| 5985 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5986 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5987 | phone.setImsRegistrationState(registered); |
| 5988 | } |
| 5989 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5990 | } finally { |
| 5991 | Binder.restoreCallingIdentity(identity); |
| 5992 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5993 | } |
| 5994 | |
| 5995 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5996 | * Set the network selection mode to automatic. |
| 5997 | * |
| 5998 | */ |
| 5999 | @Override |
| 6000 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6001 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6002 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6003 | |
| 6004 | final long identity = Binder.clearCallingIdentity(); |
| 6005 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6006 | if (!isActiveSubscription(subId)) { |
| 6007 | return; |
| 6008 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6009 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6010 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6011 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6012 | } finally { |
| 6013 | Binder.restoreCallingIdentity(identity); |
| 6014 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6015 | } |
| 6016 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6017 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6018 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6019 | * |
| 6020 | * @param subId the id of the subscription. |
| 6021 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6022 | * the operator to attach to. |
| 6023 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6024 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6025 | * normal network selection next time. |
| 6026 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6027 | */ |
| 6028 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6029 | public boolean setNetworkSelectionModeManual( |
| 6030 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6031 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6032 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6033 | |
| 6034 | if (!isActiveSubscription(subId)) { |
| 6035 | return false; |
| 6036 | } |
| 6037 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6038 | final long identity = Binder.clearCallingIdentity(); |
| 6039 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6040 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6041 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6042 | if (DBG) { |
| 6043 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6044 | + " operator: " + operatorInfo); |
| 6045 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6046 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6047 | } finally { |
| 6048 | Binder.restoreCallingIdentity(identity); |
| 6049 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6050 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6051 | /** |
| 6052 | * Get the manual network selection |
| 6053 | * |
| 6054 | * @param subId the id of the subscription. |
| 6055 | * |
| 6056 | * @return the previously saved user selected PLMN |
| 6057 | */ |
| 6058 | @Override |
| 6059 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6060 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6061 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6062 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 6063 | |
| 6064 | final long identity = Binder.clearCallingIdentity(); |
| 6065 | try { |
| 6066 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6067 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6068 | } |
| 6069 | |
| 6070 | final Phone phone = getPhone(subId); |
| 6071 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6072 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6073 | } |
| 6074 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6075 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6076 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6077 | } finally { |
| 6078 | Binder.restoreCallingIdentity(identity); |
| 6079 | } |
| 6080 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6081 | |
| 6082 | /** |
| 6083 | * Scans for available networks. |
| 6084 | */ |
| 6085 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6086 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6087 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6088 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6089 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6090 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6091 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6092 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6093 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6094 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6095 | .setCallingPid(Binder.getCallingPid()) |
| 6096 | .setCallingUid(Binder.getCallingUid()) |
| 6097 | .setMethod("getCellNetworkScanResults") |
| 6098 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6099 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6100 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6101 | .build()); |
| 6102 | switch (locationResult) { |
| 6103 | case DENIED_HARD: |
| 6104 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6105 | case DENIED_SOFT: |
| 6106 | return null; |
| 6107 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6108 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6109 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6110 | try { |
| 6111 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6112 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6113 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6114 | } finally { |
| 6115 | Binder.restoreCallingIdentity(identity); |
| 6116 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6117 | } |
| 6118 | |
| 6119 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6120 | * Get the call forwarding info, given the call forwarding reason. |
| 6121 | */ |
| 6122 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6123 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6124 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6125 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6126 | long identity = Binder.clearCallingIdentity(); |
| 6127 | try { |
| 6128 | if (DBG) { |
| 6129 | log("getCallForwarding: subId " + subId |
| 6130 | + " callForwardingReason" + callForwardingReason); |
| 6131 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6132 | |
| 6133 | Phone phone = getPhone(subId); |
| 6134 | if (phone == null) { |
| 6135 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6136 | callback.onError( |
| 6137 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6138 | } catch (RemoteException e) { |
| 6139 | // ignore |
| 6140 | } |
| 6141 | return; |
| 6142 | } |
| 6143 | |
| 6144 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6145 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6146 | @Override |
| 6147 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6148 | try { |
| 6149 | callback.onCallForwardingInfoAvailable(info); |
| 6150 | } catch (RemoteException e) { |
| 6151 | // ignore |
| 6152 | } |
| 6153 | } |
| 6154 | |
| 6155 | @Override |
| 6156 | public void onError(int error) { |
| 6157 | try { |
| 6158 | callback.onError(error); |
| 6159 | } catch (RemoteException e) { |
| 6160 | // ignore |
| 6161 | } |
| 6162 | } |
| 6163 | }); |
| 6164 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6165 | } finally { |
| 6166 | Binder.restoreCallingIdentity(identity); |
| 6167 | } |
| 6168 | } |
| 6169 | |
| 6170 | /** |
| 6171 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6172 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6173 | */ |
| 6174 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6175 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6176 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6177 | enforceModifyPermission(); |
| 6178 | long identity = Binder.clearCallingIdentity(); |
| 6179 | try { |
| 6180 | if (DBG) { |
| 6181 | log("setCallForwarding: subId " + subId |
| 6182 | + " callForwardingInfo" + callForwardingInfo); |
| 6183 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6184 | |
| 6185 | Phone phone = getPhone(subId); |
| 6186 | if (phone == null) { |
| 6187 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6188 | callback.accept( |
| 6189 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6190 | } catch (RemoteException e) { |
| 6191 | // ignore |
| 6192 | } |
| 6193 | return; |
| 6194 | } |
| 6195 | |
| 6196 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6197 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6198 | |
| 6199 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6200 | } finally { |
| 6201 | Binder.restoreCallingIdentity(identity); |
| 6202 | } |
| 6203 | } |
| 6204 | |
| 6205 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6206 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6207 | */ |
| 6208 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6209 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6210 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6211 | long identity = Binder.clearCallingIdentity(); |
| 6212 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6213 | Phone phone = getPhone(subId); |
| 6214 | if (phone == null) { |
| 6215 | try { |
| 6216 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6217 | } catch (RemoteException e) { |
| 6218 | // ignore |
| 6219 | } |
| 6220 | return; |
| 6221 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6222 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6223 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6224 | boolean requireUssd = c.getBoolean( |
| 6225 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6226 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6227 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6228 | if (requireUssd) { |
| 6229 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6230 | getSubscriptionCarrierId(subId)); |
| 6231 | String newUssdCommand = ""; |
| 6232 | try { |
| 6233 | newUssdCommand = carrierXmlParser.getFeature( |
| 6234 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6235 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6236 | } catch (NullPointerException e) { |
| 6237 | loge("Failed to generate USSD number" + e); |
| 6238 | } |
| 6239 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6240 | mMainThreadHandler, callback, carrierXmlParser, |
| 6241 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6242 | final String ussdCommand = newUssdCommand; |
| 6243 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6244 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6245 | }); |
| 6246 | } else { |
| 6247 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6248 | callback::accept); |
| 6249 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6250 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6251 | } finally { |
| 6252 | Binder.restoreCallingIdentity(identity); |
| 6253 | } |
| 6254 | } |
| 6255 | |
| 6256 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6257 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6258 | */ |
| 6259 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6260 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6261 | enforceModifyPermission(); |
| 6262 | long identity = Binder.clearCallingIdentity(); |
| 6263 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6264 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6265 | |
| 6266 | Phone phone = getPhone(subId); |
| 6267 | if (phone == null) { |
| 6268 | try { |
| 6269 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6270 | } catch (RemoteException e) { |
| 6271 | // ignore |
| 6272 | } |
| 6273 | return; |
| 6274 | } |
| 6275 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6276 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6277 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6278 | boolean requireUssd = c.getBoolean( |
| 6279 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6280 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6281 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6282 | if (requireUssd) { |
| 6283 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6284 | getSubscriptionCarrierId(subId)); |
| 6285 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6286 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6287 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6288 | String newUssdCommand = ""; |
| 6289 | try { |
| 6290 | newUssdCommand = carrierXmlParser.getFeature( |
| 6291 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6292 | .makeCommand(ssAction, null); |
| 6293 | } catch (NullPointerException e) { |
| 6294 | loge("Failed to generate USSD number" + e); |
| 6295 | } |
| 6296 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6297 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6298 | final String ussdCommand = newUssdCommand; |
| 6299 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6300 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6301 | }); |
| 6302 | } else { |
| 6303 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6304 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6305 | |
| 6306 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6307 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6308 | } finally { |
| 6309 | Binder.restoreCallingIdentity(identity); |
| 6310 | } |
| 6311 | } |
| 6312 | |
| 6313 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6314 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6315 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6316 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6317 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6318 | * location related information which will be sent if the caller already possess |
| 6319 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6320 | * @param request contains the radio access networks with bands/channels to scan |
| 6321 | * @param messenger callback messenger for scan results or errors |
| 6322 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6323 | * @return the id of the requested scan which can be used to stop the scan. |
| 6324 | */ |
| 6325 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6326 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6327 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6328 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6329 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6330 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6331 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6332 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6333 | if (!renounceFineLocationAccess) { |
| 6334 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
| 6335 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6336 | .setCallingPackage(callingPackage) |
| 6337 | .setCallingFeatureId(callingFeatureId) |
| 6338 | .setCallingPid(Binder.getCallingPid()) |
| 6339 | .setCallingUid(Binder.getCallingUid()) |
| 6340 | .setMethod("requestNetworkScan") |
| 6341 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6342 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6343 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6344 | .build()); |
| 6345 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6346 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6347 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6348 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6349 | if (e != null) { |
| 6350 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6351 | throw e; |
| 6352 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6353 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6354 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6355 | } |
| 6356 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6357 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6358 | int callingUid = Binder.getCallingUid(); |
| 6359 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6360 | final long identity = Binder.clearCallingIdentity(); |
| 6361 | try { |
| 6362 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6363 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6364 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6365 | } finally { |
| 6366 | Binder.restoreCallingIdentity(identity); |
| 6367 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6368 | } |
| 6369 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6370 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6371 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6372 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6373 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6374 | boolean hasNetworkScanPermission = |
| 6375 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6376 | == PERMISSION_GRANTED; |
| 6377 | |
| 6378 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6379 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6380 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6381 | } |
| 6382 | |
| 6383 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6384 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6385 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6386 | return new SecurityException("Specific channels must not be" |
| 6387 | + " scanned without location access."); |
| 6388 | } |
| 6389 | } |
| 6390 | } |
| 6391 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6392 | return null; |
| 6393 | } |
| 6394 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6395 | /** |
| 6396 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6397 | * |
| 6398 | * @param subId id of the subscription |
| 6399 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6400 | */ |
| 6401 | @Override |
| 6402 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6403 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6404 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6405 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6406 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6407 | final long identity = Binder.clearCallingIdentity(); |
| 6408 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6409 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6410 | } finally { |
| 6411 | Binder.restoreCallingIdentity(identity); |
| 6412 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6413 | } |
| 6414 | |
| 6415 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6416 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6417 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6418 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6419 | */ |
| 6420 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6421 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6422 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6423 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6424 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6425 | |
| 6426 | final long identity = Binder.clearCallingIdentity(); |
| 6427 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6428 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6429 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6430 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6431 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6432 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6433 | } finally { |
| 6434 | Binder.restoreCallingIdentity(identity); |
| 6435 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6436 | } |
| 6437 | |
| 6438 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6439 | * Get the allowed network types for certain reason. |
| 6440 | * |
| 6441 | * @param subId the id of the subscription. |
| 6442 | * @param reason the reason the allowed network type change is taking place |
| 6443 | * @return the allowed network types. |
| 6444 | */ |
| 6445 | @Override |
| 6446 | public long getAllowedNetworkTypesForReason(int subId, |
| 6447 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6448 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6449 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6450 | final long identity = Binder.clearCallingIdentity(); |
| 6451 | try { |
| 6452 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6453 | } finally { |
| 6454 | Binder.restoreCallingIdentity(identity); |
| 6455 | } |
| 6456 | } |
| 6457 | |
| 6458 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6459 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6460 | * @param subId subscription id of the sim card |
| 6461 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6462 | * This can be passed following states |
| 6463 | * <ol> |
| 6464 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6465 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6466 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6467 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6468 | * </ol> |
| 6469 | * @return operation result. |
| 6470 | */ |
| 6471 | @Override |
| 6472 | public int setNrDualConnectivityState(int subId, |
| 6473 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6474 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6475 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6476 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6477 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6478 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6479 | } |
| 6480 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6481 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6482 | final long identity = Binder.clearCallingIdentity(); |
| 6483 | try { |
| 6484 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6485 | nrDualConnectivityState, subId, |
| 6486 | workSource); |
| 6487 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6488 | return result; |
| 6489 | } finally { |
| 6490 | Binder.restoreCallingIdentity(identity); |
| 6491 | } |
| 6492 | } |
| 6493 | |
| 6494 | /** |
| 6495 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6496 | * @return true if dual connectivity is enabled else false |
| 6497 | */ |
| 6498 | @Override |
| 6499 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6500 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6501 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6502 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6503 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6504 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6505 | return false; |
| 6506 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6507 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6508 | final long identity = Binder.clearCallingIdentity(); |
| 6509 | try { |
| 6510 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6511 | null, subId, workSource); |
| 6512 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6513 | return isEnabled; |
| 6514 | } finally { |
| 6515 | Binder.restoreCallingIdentity(identity); |
| 6516 | } |
| 6517 | } |
| 6518 | |
| 6519 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6520 | * Set the allowed network types of the device and |
| 6521 | * provide the reason triggering the allowed network change. |
| 6522 | * |
| 6523 | * @param subId the id of the subscription. |
| 6524 | * @param reason the reason the allowed network type change is taking place |
| 6525 | * @param allowedNetworkTypes the allowed network types. |
| 6526 | * @return true on success; false on any failure. |
| 6527 | */ |
| 6528 | @Override |
| 6529 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6530 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6531 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6532 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6533 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6534 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6535 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6536 | return false; |
| 6537 | } |
| 6538 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6539 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6540 | return false; |
| 6541 | } |
| 6542 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6543 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6544 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6545 | |
| 6546 | |
| 6547 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6548 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6549 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6550 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6551 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6552 | final long identity = Binder.clearCallingIdentity(); |
| 6553 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6554 | Boolean success = (Boolean) sendRequest( |
| 6555 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6556 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6557 | |
| 6558 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6559 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6560 | } finally { |
| 6561 | Binder.restoreCallingIdentity(identity); |
| 6562 | } |
| 6563 | } |
| 6564 | |
| 6565 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6566 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6567 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6568 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6569 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6570 | * @hide |
| 6571 | */ |
| 6572 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6573 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6574 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6575 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6576 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6577 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6578 | if (phone != null) { |
| 6579 | return phone.hasMatchedTetherApnSetting(); |
| 6580 | } else { |
| 6581 | return false; |
| 6582 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6583 | } finally { |
| 6584 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6585 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6586 | } |
| 6587 | |
| 6588 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6589 | * Get the user enabled state of Mobile Data. |
| 6590 | * |
| 6591 | * TODO: remove and use isUserDataEnabled. |
| 6592 | * This can't be removed now because some vendor codes |
| 6593 | * calls through ITelephony directly while they should |
| 6594 | * use TelephonyManager. |
| 6595 | * |
| 6596 | * @return true on enabled |
| 6597 | */ |
| 6598 | @Override |
| 6599 | public boolean getDataEnabled(int subId) { |
| 6600 | return isUserDataEnabled(subId); |
| 6601 | } |
| 6602 | |
| 6603 | /** |
| 6604 | * Get whether mobile data is enabled per user setting. |
| 6605 | * |
| 6606 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6607 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6608 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6609 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6610 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6611 | * |
| 6612 | * @return {@code true} if data is enabled else {@code false} |
| 6613 | */ |
| 6614 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6615 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6616 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6617 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6618 | try { |
| 6619 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6620 | functionName); |
| 6621 | } catch (Exception e) { |
| 6622 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6623 | } |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6624 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6625 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6626 | mApp, subId, functionName); |
| 6627 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6628 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6629 | |
| 6630 | final long identity = Binder.clearCallingIdentity(); |
| 6631 | try { |
| 6632 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6633 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6634 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6635 | if (phone != null) { |
| 6636 | boolean retVal = phone.isUserDataEnabled(); |
| 6637 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6638 | return retVal; |
| 6639 | } else { |
| 6640 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6641 | return false; |
| 6642 | } |
| 6643 | } finally { |
| 6644 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6645 | } |
| 6646 | } |
| 6647 | |
| 6648 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6649 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6650 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6651 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6652 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6653 | * @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] | 6654 | */ |
| 6655 | @Override |
| 6656 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6657 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6658 | try { |
| 6659 | try { |
| 6660 | mApp.enforceCallingOrSelfPermission( |
| 6661 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6662 | functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6663 | } catch (Exception e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6664 | try { |
| 6665 | mApp.enforceCallingOrSelfPermission( |
| 6666 | android.Manifest.permission.READ_PHONE_STATE, |
| 6667 | functionName); |
| 6668 | } catch (Exception e2) { |
| 6669 | mApp.enforceCallingOrSelfPermission( |
| 6670 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6671 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6672 | } |
| 6673 | } catch (Exception e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6674 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6675 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6676 | |
| 6677 | final long identity = Binder.clearCallingIdentity(); |
| 6678 | try { |
| 6679 | int phoneId = mSubscriptionController.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6680 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6681 | if (phone != null) { |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6682 | boolean retVal; |
| 6683 | if (phone.isUsingNewDataStack()) { |
| 6684 | retVal = phone.getDataNetworkController().getDataSettingsManager() |
| 6685 | .isDataEnabled(); |
| 6686 | } else { |
| 6687 | retVal = phone.getDataEnabledSettings().isDataEnabled(); |
| 6688 | } |
| 6689 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6690 | return retVal; |
| 6691 | } else { |
| 6692 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6693 | return false; |
| 6694 | } |
| 6695 | } finally { |
| 6696 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6697 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6698 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6699 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6700 | /** |
| 6701 | * Check if data is enabled for a specific reason |
| 6702 | * @param subId Subscription index |
| 6703 | * @param reason the reason the data enable change is taking place |
| 6704 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6705 | */ |
| 6706 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6707 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6708 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6709 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6710 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6711 | try { |
| 6712 | mApp.enforceCallingOrSelfPermission( |
| 6713 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6714 | functionName); |
| 6715 | } catch (Exception e) { |
| 6716 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6717 | functionName); |
| 6718 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6719 | } catch (Exception e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6720 | try { |
| 6721 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6722 | functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6723 | } catch (Exception e2) { |
| 6724 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6725 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6726 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6727 | } |
| 6728 | |
| 6729 | |
| 6730 | final long identity = Binder.clearCallingIdentity(); |
| 6731 | try { |
| 6732 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6733 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6734 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6735 | + " reason=" + reason); |
| 6736 | } |
| 6737 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6738 | if (phone != null) { |
| 6739 | boolean retVal; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 6740 | if (phone.isUsingNewDataStack()) { |
| 6741 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6742 | } else { |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 6743 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6744 | retVal = phone.isUserDataEnabled(); |
| 6745 | } else { |
| 6746 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
| 6747 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6748 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6749 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6750 | return retVal; |
| 6751 | } else { |
| 6752 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6753 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6754 | + subId + " retVal=false"); |
| 6755 | } |
| 6756 | return false; |
| 6757 | } |
| 6758 | } finally { |
| 6759 | Binder.restoreCallingIdentity(identity); |
| 6760 | } |
| 6761 | } |
| 6762 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6763 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6764 | Phone phone) { |
Sarah Chin | 3394efe | 2021-04-09 10:37:15 -0700 | [diff] [blame] | 6765 | if (uid == Process.PHONE_UID) { |
| 6766 | // Skip the check if it's the phone UID (system UID removed in b/184713596) |
| 6767 | // 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] | 6768 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6769 | } |
| 6770 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6771 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6772 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6773 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6774 | || subController == null) return privilegeFromSim; |
| 6775 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6776 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6777 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6778 | |
| 6779 | final long identity = Binder.clearCallingIdentity(); |
| 6780 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6781 | int subId = phone.getSubId(); |
| 6782 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6783 | // A test override is in place for the privileges for this subId, so don't try to |
| 6784 | // read the subscription privileges. |
| 6785 | return privilegeFromSim; |
| 6786 | } |
| 6787 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6788 | SubscriptionManager subManager = (SubscriptionManager) |
| 6789 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6790 | for (String pkg : packages) { |
| 6791 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6792 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6793 | } |
| 6794 | } |
| 6795 | return privilegeFromSim; |
| 6796 | } finally { |
| 6797 | Binder.restoreCallingIdentity(identity); |
| 6798 | } |
| 6799 | } |
| 6800 | |
| 6801 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6802 | String pkgName) { |
| 6803 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6804 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6805 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6806 | || subController == null) return privilegeFromSim; |
| 6807 | |
| 6808 | final long identity = Binder.clearCallingIdentity(); |
| 6809 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6810 | int subId = phone.getSubId(); |
| 6811 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6812 | // A test override is in place for the privileges for this subId, so don't try to |
| 6813 | // read the subscription privileges. |
| 6814 | return privilegeFromSim; |
| 6815 | } |
| 6816 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6817 | SubscriptionManager subManager = (SubscriptionManager) |
| 6818 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6819 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6820 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6821 | } finally { |
| 6822 | Binder.restoreCallingIdentity(identity); |
| 6823 | } |
| 6824 | } |
| 6825 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6826 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6827 | public int getCarrierPrivilegeStatus(int subId) { |
| 6828 | final Phone phone = getPhone(subId); |
| 6829 | if (phone == null) { |
| 6830 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6831 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6832 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6833 | UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
| 6834 | if (port == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6835 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6836 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6837 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6838 | |
| 6839 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6840 | port.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6841 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6842 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6843 | |
| 6844 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6845 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6846 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6847 | final Phone phone = getPhone(subId); |
| 6848 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6849 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6850 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6851 | } |
| 6852 | UiccProfile profile = |
| 6853 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6854 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6855 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6856 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6857 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6858 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6859 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6860 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6861 | } |
| 6862 | |
| 6863 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6864 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6865 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6866 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6867 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6868 | } |
| 6869 | |
| 6870 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6871 | UiccPort port = UiccController.getInstance().getUiccPort(phoneId); |
| 6872 | if (port == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6873 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6874 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6875 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6876 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6877 | port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6878 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6879 | } |
| 6880 | |
| 6881 | @Override |
| 6882 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Sarah Chin | fc3169b | 2021-04-28 20:21:03 -0700 | [diff] [blame] | 6883 | // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6884 | if (TextUtils.isEmpty(pkgName)) |
| 6885 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6886 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6887 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6888 | UiccPort port = UiccController.getInstance().getUiccPort(i); |
| 6889 | if (port == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6890 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6891 | continue; |
| 6892 | } |
| 6893 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6894 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6895 | port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6896 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6897 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6898 | break; |
| 6899 | } |
| 6900 | } |
| 6901 | |
| 6902 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6903 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6904 | |
| 6905 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6906 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6907 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6908 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6909 | loge("phoneId " + phoneId + " is not valid."); |
| 6910 | return null; |
| 6911 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6912 | UiccPort port = UiccController.getInstance().getUiccPort(phoneId); |
| 6913 | if (port == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6914 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6915 | return null ; |
| 6916 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6917 | return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6918 | } |
| 6919 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6920 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6921 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6922 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6923 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6924 | List<String> privilegedPackages = new ArrayList<>(); |
| 6925 | List<PackageInfo> packages = null; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6926 | UiccPort port = UiccController.getInstance().getUiccPort(phoneId); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6927 | // has UICC in that slot. |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6928 | if (port != null) { |
| 6929 | if (port.hasCarrierPrivilegeRules()) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6930 | if (packages == null) { |
| 6931 | // Only check packages in user 0 for now |
| 6932 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6933 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6934 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6935 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6936 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6937 | } |
| 6938 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6939 | PackageInfo pkgInfo = packages.get(p); |
| 6940 | if (pkgInfo != null && pkgInfo.packageName != null |
Sooraj Sasindran | 97bce6f | 2021-09-28 21:37:29 +0000 | [diff] [blame] | 6941 | && getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6942 | port.getCarrierPrivilegeStatus(pkgInfo), |
| 6943 | getPhone(phoneId), pkgInfo.packageName) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6944 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6945 | privilegedPackages.add(pkgInfo.packageName); |
| 6946 | } |
| 6947 | } |
| 6948 | } |
| 6949 | } |
| 6950 | return privilegedPackages; |
| 6951 | } |
| 6952 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6953 | @Override |
| 6954 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6955 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6956 | |
| 6957 | final long identity = Binder.clearCallingIdentity(); |
| 6958 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6959 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6960 | try { |
| 6961 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6962 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6963 | } |
| 6964 | } finally { |
| 6965 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6966 | } |
| 6967 | return privilegedPackages; |
| 6968 | } |
| 6969 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6970 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6971 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6972 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 6973 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6974 | return null; |
| 6975 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6976 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6977 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6978 | return null; |
| 6979 | } |
| 6980 | return iccId; |
| 6981 | } |
| 6982 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6983 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6984 | public void setCallComposerStatus(int subId, int status) { |
| 6985 | enforceModifyPermission(); |
| 6986 | |
| 6987 | final long identity = Binder.clearCallingIdentity(); |
| 6988 | try { |
| 6989 | Phone phone = getPhone(subId); |
| 6990 | if (phone != null) { |
| 6991 | Phone defaultPhone = phone.getImsPhone(); |
| 6992 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6993 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6994 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6995 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6996 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6997 | } |
| 6998 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6999 | } catch (ImsException e) { |
| 7000 | throw new ServiceSpecificException(e.getCode()); |
| 7001 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7002 | Binder.restoreCallingIdentity(identity); |
| 7003 | } |
| 7004 | } |
| 7005 | |
| 7006 | @Override |
| 7007 | public int getCallComposerStatus(int subId) { |
| 7008 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7009 | |
| 7010 | final long identity = Binder.clearCallingIdentity(); |
| 7011 | try { |
| 7012 | Phone phone = getPhone(subId); |
| 7013 | if (phone != null) { |
| 7014 | Phone defaultPhone = phone.getImsPhone(); |
| 7015 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7016 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7017 | return imsPhone.getCallComposerStatus(); |
| 7018 | } |
| 7019 | } |
| 7020 | } finally { |
| 7021 | Binder.restoreCallingIdentity(identity); |
| 7022 | } |
| 7023 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7024 | } |
| 7025 | |
| 7026 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7027 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7028 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7029 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7030 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7031 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7032 | final long identity = Binder.clearCallingIdentity(); |
| 7033 | try { |
| 7034 | final String iccId = getIccId(subId); |
| 7035 | final Phone phone = getPhone(subId); |
| 7036 | if (phone == null) { |
| 7037 | return false; |
| 7038 | } |
| 7039 | final String subscriberId = phone.getSubscriberId(); |
| 7040 | |
| 7041 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7042 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7043 | + subscriberId + " to " + number); |
| 7044 | } |
| 7045 | |
| 7046 | if (TextUtils.isEmpty(iccId)) { |
| 7047 | return false; |
| 7048 | } |
| 7049 | |
| 7050 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7051 | |
| 7052 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7053 | if (alphaTag == null) { |
| 7054 | editor.remove(alphaTagPrefKey); |
| 7055 | } else { |
| 7056 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7057 | } |
| 7058 | |
| 7059 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7060 | // track all merged IMSIs based on line number |
| 7061 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7062 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7063 | if (number == null) { |
| 7064 | editor.remove(numberPrefKey); |
| 7065 | editor.remove(subscriberPrefKey); |
| 7066 | } else { |
| 7067 | editor.putString(numberPrefKey, number); |
| 7068 | editor.putString(subscriberPrefKey, subscriberId); |
| 7069 | } |
| 7070 | |
| 7071 | editor.commit(); |
| 7072 | return true; |
| 7073 | } finally { |
| 7074 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7075 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7076 | } |
| 7077 | |
| 7078 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7079 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7080 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7081 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7082 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7083 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7084 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7085 | return null; |
| 7086 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7087 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7088 | final long identity = Binder.clearCallingIdentity(); |
| 7089 | try { |
| 7090 | String iccId = getIccId(subId); |
| 7091 | if (iccId != null) { |
| 7092 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7093 | if (DBG_MERGE) { |
| 7094 | log("getLine1NumberForDisplay returning " |
| 7095 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7096 | } |
| 7097 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7098 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7099 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7100 | return null; |
| 7101 | } finally { |
| 7102 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7103 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7104 | } |
| 7105 | |
| 7106 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7107 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7108 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7109 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7110 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7111 | return null; |
| 7112 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7113 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7114 | final long identity = Binder.clearCallingIdentity(); |
| 7115 | try { |
| 7116 | String iccId = getIccId(subId); |
| 7117 | if (iccId != null) { |
| 7118 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7119 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7120 | } |
| 7121 | return null; |
| 7122 | } finally { |
| 7123 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7124 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7125 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7126 | |
| 7127 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7128 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7129 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7130 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7131 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7132 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7133 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7134 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7135 | return null; |
| 7136 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7137 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7138 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7139 | // the process, where TelephonyManager was instantiated. |
| 7140 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7141 | final long identity = Binder.clearCallingIdentity(); |
| 7142 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7143 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7144 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7145 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7146 | |
| 7147 | // Figure out what subscribers are currently active |
| 7148 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7149 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7150 | // Only consider subs which match the current subId |
| 7151 | // This logic can be simplified. See b/131189269 for progress. |
| 7152 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7153 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7154 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7155 | |
| 7156 | // First pass, find a number override for an active subscriber |
| 7157 | String mergeNumber = null; |
| 7158 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7159 | for (String key : prefs.keySet()) { |
| 7160 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7161 | final String subscriberId = (String) prefs.get(key); |
| 7162 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7163 | final String iccId = key.substring( |
| 7164 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7165 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7166 | mergeNumber = (String) prefs.get(numberKey); |
| 7167 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7168 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7169 | + " for active subscriber " + subscriberId); |
| 7170 | } |
| 7171 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7172 | break; |
| 7173 | } |
| 7174 | } |
| 7175 | } |
| 7176 | } |
| 7177 | |
| 7178 | // Shortcut when no active merged subscribers |
| 7179 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7180 | return null; |
| 7181 | } |
| 7182 | |
| 7183 | // Second pass, find all subscribers under that line override |
| 7184 | final ArraySet<String> result = new ArraySet<>(); |
| 7185 | for (String key : prefs.keySet()) { |
| 7186 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7187 | final String number = (String) prefs.get(key); |
| 7188 | if (mergeNumber.equals(number)) { |
| 7189 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7190 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7191 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7192 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7193 | result.add(subscriberId); |
| 7194 | } |
| 7195 | } |
| 7196 | } |
| 7197 | } |
| 7198 | |
| 7199 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7200 | Arrays.sort(resultArray); |
| 7201 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7202 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7203 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7204 | } |
| 7205 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7206 | } finally { |
| 7207 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7208 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7209 | } |
| 7210 | |
| 7211 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7212 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7213 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7214 | |
| 7215 | final long identity = Binder.clearCallingIdentity(); |
| 7216 | try { |
| 7217 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7218 | TelephonyManager.class); |
| 7219 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7220 | if (subscriberId == null) { |
| 7221 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7222 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7223 | + subId); |
| 7224 | } |
| 7225 | return null; |
| 7226 | } |
| 7227 | |
| 7228 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 7229 | .getSubscriptionInfo(subId); |
| 7230 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 7231 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7232 | if (groupUuid == null) { |
| 7233 | return new String[]{subscriberId}; |
| 7234 | } |
| 7235 | |
| 7236 | // Get all subscriberIds from the group. |
| 7237 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 7238 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7239 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7240 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7241 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7242 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7243 | if (subscriberId != null) { |
| 7244 | mergedSubscriberIds.add(subscriberId); |
| 7245 | } |
| 7246 | } |
| 7247 | |
| 7248 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7249 | } finally { |
| 7250 | Binder.restoreCallingIdentity(identity); |
| 7251 | |
| 7252 | } |
| 7253 | } |
| 7254 | |
| 7255 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7256 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7257 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7258 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7259 | |
| 7260 | final long identity = Binder.clearCallingIdentity(); |
| 7261 | try { |
| 7262 | final Phone phone = getPhone(subId); |
| 7263 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7264 | } finally { |
| 7265 | Binder.restoreCallingIdentity(identity); |
| 7266 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7267 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7268 | |
| 7269 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7270 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7271 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7272 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7273 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7274 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7275 | |
| 7276 | final long identity = Binder.clearCallingIdentity(); |
| 7277 | try { |
| 7278 | final Phone phone = getPhone(subId); |
| 7279 | if (phone == null) { |
| 7280 | return false; |
| 7281 | } |
| 7282 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7283 | cdmaNonRoamingList); |
| 7284 | } finally { |
| 7285 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7286 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7287 | } |
| 7288 | |
| 7289 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7290 | @Deprecated |
| 7291 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7292 | enforceModifyPermission(); |
| 7293 | |
| 7294 | int returnValue = 0; |
| 7295 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7296 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7297 | if(result.exception == null) { |
| 7298 | if (result.result != null) { |
| 7299 | byte[] responseData = (byte[])(result.result); |
| 7300 | if(responseData.length > oemResp.length) { |
| 7301 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7302 | responseData.length + "bytes. Buffer Size is " + |
| 7303 | oemResp.length + "bytes."); |
| 7304 | } |
| 7305 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7306 | returnValue = responseData.length; |
| 7307 | } |
| 7308 | } else { |
| 7309 | CommandException ex = (CommandException) result.exception; |
| 7310 | returnValue = ex.getCommandError().ordinal(); |
| 7311 | if(returnValue > 0) returnValue *= -1; |
| 7312 | } |
| 7313 | } catch (RuntimeException e) { |
| 7314 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7315 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7316 | if(returnValue > 0) returnValue *= -1; |
| 7317 | } |
| 7318 | |
| 7319 | return returnValue; |
| 7320 | } |
| 7321 | |
| 7322 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7323 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7324 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7325 | try { |
| 7326 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7327 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7328 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7329 | } catch (SecurityException e) { |
| 7330 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7331 | throw e; |
| 7332 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7333 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7334 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7335 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7336 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7337 | final long identity = Binder.clearCallingIdentity(); |
| 7338 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7339 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7340 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7341 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7342 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7343 | } finally { |
| 7344 | Binder.restoreCallingIdentity(identity); |
| 7345 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7346 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7347 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7348 | |
| 7349 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7350 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7351 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7352 | try { |
| 7353 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7354 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7355 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7356 | } |
| 7357 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7358 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7359 | } |
| 7360 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7361 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7362 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7363 | throw new SecurityException("App must be the dialer role holder to" |
| 7364 | + " upload a call composer pic"); |
| 7365 | } |
| 7366 | |
| 7367 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7368 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7369 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7370 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7371 | boolean readUntilEnd = false; |
| 7372 | int totalBytesRead = 0; |
| 7373 | byte[] buffer = new byte[16 * 1024]; |
| 7374 | while (true) { |
| 7375 | int numRead; |
| 7376 | try { |
| 7377 | numRead = input.read(buffer); |
| 7378 | } catch (IOException e) { |
| 7379 | try { |
| 7380 | fd.checkError(); |
| 7381 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7382 | null); |
| 7383 | } catch (IOException e1) { |
| 7384 | // This means that the other side closed explicitly with an error. If this |
| 7385 | // happens, log and ignore. |
| 7386 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7387 | } |
| 7388 | break; |
| 7389 | } |
| 7390 | if (numRead == -1) { |
| 7391 | readUntilEnd = true; |
| 7392 | break; |
| 7393 | } |
| 7394 | totalBytesRead += numRead; |
| 7395 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7396 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7397 | try { |
| 7398 | input.close(); |
| 7399 | } catch (IOException e) { |
| 7400 | // ignore |
| 7401 | } |
| 7402 | break; |
| 7403 | } |
| 7404 | output.write(buffer, 0, numRead); |
| 7405 | } |
| 7406 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7407 | // close is above, where the picture size is too big. |
| 7408 | |
| 7409 | try { |
| 7410 | fd.checkError(); |
| 7411 | } catch (IOException e) { |
| 7412 | loge("Remote end for call composer closed with an error: " + e); |
| 7413 | return; |
| 7414 | } |
| 7415 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7416 | if (!readUntilEnd) { |
| 7417 | loge("Did not finish reading entire image; aborting"); |
| 7418 | return; |
| 7419 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7420 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7421 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7422 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7423 | new CallComposerPictureTransfer.Factory() {}, |
| 7424 | imageData, |
| 7425 | (result) -> { |
| 7426 | if (result.first != null) { |
| 7427 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7428 | Bundle outputResult = new Bundle(); |
| 7429 | outputResult.putParcelable( |
| 7430 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7431 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7432 | outputResult); |
| 7433 | } else { |
| 7434 | callback.send(result.second, null); |
| 7435 | } |
| 7436 | } |
| 7437 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7438 | }); |
| 7439 | } |
| 7440 | |
| 7441 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7442 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7443 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7444 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7445 | |
| 7446 | final long identity = Binder.clearCallingIdentity(); |
| 7447 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7448 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7449 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7450 | } finally { |
| 7451 | Binder.restoreCallingIdentity(identity); |
| 7452 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7453 | } |
| 7454 | |
| 7455 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7456 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7457 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7458 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7459 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7460 | return false; |
| 7461 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7462 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7463 | final long identity = Binder.clearCallingIdentity(); |
| 7464 | try { |
| 7465 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7466 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7467 | // In the long run, we may instead need to check if there exists a connection service |
| 7468 | // which can support video calling. |
| 7469 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7470 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7471 | return imsManager.isVtEnabledByPlatform() |
| 7472 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7473 | && imsManager.isVtEnabledByUser(); |
| 7474 | } finally { |
| 7475 | Binder.restoreCallingIdentity(identity); |
| 7476 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7477 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7478 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7479 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7480 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7481 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7482 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7483 | mApp, subId, callingPackage, callingFeatureId, |
| 7484 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7485 | return false; |
| 7486 | } |
| 7487 | |
| 7488 | final long identity = Binder.clearCallingIdentity(); |
| 7489 | try { |
| 7490 | CarrierConfigManager configManager = |
| 7491 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7492 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7493 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7494 | } finally { |
| 7495 | Binder.restoreCallingIdentity(identity); |
| 7496 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7497 | } |
| 7498 | |
| 7499 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7500 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7501 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7502 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7503 | return false; |
| 7504 | } |
| 7505 | |
| 7506 | final long identity = Binder.clearCallingIdentity(); |
| 7507 | try { |
| 7508 | CarrierConfigManager configManager = |
| 7509 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7510 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7511 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7512 | } finally { |
| 7513 | Binder.restoreCallingIdentity(identity); |
| 7514 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7515 | } |
| 7516 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7517 | @Override |
| 7518 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7519 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7520 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7521 | } |
| 7522 | |
| 7523 | @Override |
| 7524 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7525 | final long identity = Binder.clearCallingIdentity(); |
| 7526 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7527 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7528 | } finally { |
| 7529 | Binder.restoreCallingIdentity(identity); |
| 7530 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7531 | } |
| 7532 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7533 | /** |
| 7534 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7535 | * support for the feature and device firmware support. |
| 7536 | * |
| 7537 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7538 | */ |
| 7539 | @Override |
| 7540 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7541 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7542 | final Phone phone = getPhone(subscriptionId); |
| 7543 | if (phone == null) { |
| 7544 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7545 | return false; |
| 7546 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7547 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7548 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7549 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7550 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7551 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7552 | return isCarrierSupported && isDeviceSupported; |
| 7553 | } finally { |
| 7554 | Binder.restoreCallingIdentity(identity); |
| 7555 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7556 | } |
| 7557 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7558 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7559 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7560 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7561 | * 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] | 7562 | */ |
| 7563 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7564 | final long identity = Binder.clearCallingIdentity(); |
| 7565 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7566 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7567 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7568 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7569 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7570 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7571 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7572 | } finally { |
| 7573 | Binder.restoreCallingIdentity(identity); |
| 7574 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7575 | } |
| 7576 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7577 | @Deprecated |
| 7578 | @Override |
| 7579 | public String getDeviceId(String callingPackage) { |
| 7580 | return getDeviceIdWithFeature(callingPackage, null); |
| 7581 | } |
| 7582 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7583 | /** |
| 7584 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7585 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7586 | * |
| 7587 | * <p>Requires Permission: |
| 7588 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7589 | */ |
| 7590 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7591 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7592 | try { |
| 7593 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7594 | } catch (SecurityException se) { |
| 7595 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7596 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7597 | + Binder.getCallingUid()); |
| 7598 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7599 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7600 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7601 | return null; |
| 7602 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7603 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7604 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7605 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7606 | return null; |
| 7607 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7608 | |
| 7609 | final long identity = Binder.clearCallingIdentity(); |
| 7610 | try { |
| 7611 | return phone.getDeviceId(); |
| 7612 | } finally { |
| 7613 | Binder.restoreCallingIdentity(identity); |
| 7614 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7615 | } |
| 7616 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7617 | /** |
| 7618 | * {@hide} |
| 7619 | * Returns the IMS Registration Status on a particular subid |
| 7620 | * |
| 7621 | * @param subId |
| 7622 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7623 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7624 | Phone phone = getPhone(subId); |
| 7625 | if (phone != null) { |
| 7626 | return phone.isImsRegistered(); |
| 7627 | } else { |
| 7628 | return false; |
| 7629 | } |
| 7630 | } |
| 7631 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7632 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7633 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7634 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7635 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7636 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7637 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7638 | } |
| 7639 | final long identity = Binder.clearCallingIdentity(); |
| 7640 | try { |
| 7641 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7642 | } finally { |
| 7643 | Binder.restoreCallingIdentity(identity); |
| 7644 | } |
| 7645 | } |
| 7646 | |
| 7647 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7648 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7649 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7650 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7651 | mApp, |
| 7652 | subscriptionId, |
| 7653 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7654 | final long identity = Binder.clearCallingIdentity(); |
| 7655 | try { |
| 7656 | Phone phone = getPhone(subscriptionId); |
| 7657 | if (phone == null) { |
| 7658 | return null; |
| 7659 | } |
| 7660 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7661 | } finally { |
| 7662 | Binder.restoreCallingIdentity(identity); |
| 7663 | } |
| 7664 | } |
| 7665 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7666 | /** |
| 7667 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7668 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7669 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7670 | final long identity = Binder.clearCallingIdentity(); |
| 7671 | try { |
| 7672 | Phone phone = getPhone(subId); |
| 7673 | if (phone != null) { |
| 7674 | return phone.isWifiCallingEnabled(); |
| 7675 | } else { |
| 7676 | return false; |
| 7677 | } |
| 7678 | } finally { |
| 7679 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7680 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7681 | } |
| 7682 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7683 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7684 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7685 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7686 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7687 | final long identity = Binder.clearCallingIdentity(); |
| 7688 | try { |
| 7689 | Phone phone = getPhone(subId); |
| 7690 | if (phone != null) { |
| 7691 | return phone.isVideoEnabled(); |
| 7692 | } else { |
| 7693 | return false; |
| 7694 | } |
| 7695 | } finally { |
| 7696 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7697 | } |
| 7698 | } |
| 7699 | |
| 7700 | /** |
| 7701 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7702 | * defined in {@link ImsRegistrationImplBase}. |
| 7703 | */ |
| 7704 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7705 | final long identity = Binder.clearCallingIdentity(); |
| 7706 | try { |
| 7707 | Phone phone = getPhone(subId); |
| 7708 | if (phone != null) { |
| 7709 | return phone.getImsRegistrationTech(); |
| 7710 | } else { |
| 7711 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7712 | } |
| 7713 | } finally { |
| 7714 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7715 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7716 | } |
| 7717 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7718 | @Override |
| 7719 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7720 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7721 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7722 | return; |
| 7723 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7724 | Phone defaultPhone = getDefaultPhone(); |
| 7725 | if (defaultPhone != null) { |
| 7726 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7727 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7728 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7729 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7730 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7731 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7732 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7733 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7734 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7735 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7736 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7737 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7738 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7739 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7740 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7741 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7742 | // There has been issues when Sms raw table somehow stores orphan |
| 7743 | // fragments. They lead to garbled message when new fragments come |
| 7744 | // in and combined with those stale ones. In case this happens again, |
| 7745 | // user can reset all network settings which will clean up this table. |
| 7746 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7747 | // Clean up IMS settings as well here. |
| 7748 | int slotId = getSlotIndex(subId); |
| 7749 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7750 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7751 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7752 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7753 | if (defaultPhone == null) { |
| 7754 | return; |
| 7755 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7756 | // Erase modem config if erase modem on network setting is enabled. |
| 7757 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7758 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7759 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7760 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7761 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7762 | |
| 7763 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7764 | } finally { |
| 7765 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7766 | } |
| 7767 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7768 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7769 | @VisibleForTesting |
| 7770 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7771 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7772 | return; |
| 7773 | } |
| 7774 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7775 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7776 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7777 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7778 | "user=" + defaultNetworkType); |
| 7779 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7780 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7781 | defaultNetworkType, null); |
| 7782 | } |
| 7783 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7784 | private void cleanUpSmsRawTable(Context context) { |
| 7785 | ContentResolver resolver = context.getContentResolver(); |
| 7786 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7787 | resolver.delete(uri, null, null); |
| 7788 | } |
| 7789 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7790 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7791 | public String getSimLocaleForSubscriber(int subId) { |
| 7792 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7793 | final Phone phone = getPhone(subId); |
| 7794 | if (phone == null) { |
| 7795 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7796 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7797 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7798 | final long identity = Binder.clearCallingIdentity(); |
| 7799 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7800 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7801 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7802 | if (info == null) { |
| 7803 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7804 | return null; |
| 7805 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7806 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7807 | // preferences (EF-PL and EF-LI)... |
| 7808 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7809 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7810 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7811 | if (localeFromDefaultSim != null) { |
| 7812 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7813 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7814 | + localeFromDefaultSim); |
| 7815 | return localeFromDefaultSim.toLanguageTag(); |
| 7816 | } else { |
| 7817 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7818 | } |
| 7819 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7820 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7821 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7822 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7823 | // the SIM and carrier preferences does not include a country we add the country |
| 7824 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7825 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7826 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7827 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7828 | return mccLocale.toLanguageTag(); |
| 7829 | } |
| 7830 | |
| 7831 | if (DBG) log("No locale found - returning null"); |
| 7832 | return null; |
| 7833 | } finally { |
| 7834 | Binder.restoreCallingIdentity(identity); |
| 7835 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7836 | } |
| 7837 | |
| 7838 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7839 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7840 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7841 | } |
| 7842 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7843 | /** |
| 7844 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7845 | */ |
| 7846 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7847 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7848 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7849 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7850 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7851 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7852 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7853 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7854 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7855 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7856 | * representing the state of the modem. |
| 7857 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7858 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7859 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7860 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7861 | */ |
| 7862 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7863 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7864 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7865 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7866 | |
| 7867 | final long identity = Binder.clearCallingIdentity(); |
| 7868 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7869 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7870 | } finally { |
| 7871 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7872 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7873 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7874 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7875 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7876 | // less than total activity duration. |
| 7877 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7878 | if (info == null) { |
| 7879 | return false; |
| 7880 | } |
| 7881 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7882 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7883 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7884 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7885 | return (info.isValid() |
| 7886 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7887 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7888 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7889 | && (totalTxTimeMs <= activityDurationMs)); |
| 7890 | } |
| 7891 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7892 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7893 | * Returns the service state information on specified subscription. |
| 7894 | */ |
| 7895 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7896 | public ServiceState getServiceStateForSubscriber(int subId, |
| 7897 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 7898 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7899 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7900 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7901 | return null; |
| 7902 | } |
| 7903 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7904 | boolean hasFinePermission = false; |
| 7905 | boolean hasCoarsePermission = false; |
| 7906 | if (!renounceFineLocationAccess) { |
| 7907 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7908 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7909 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7910 | .setCallingPackage(callingPackage) |
| 7911 | .setCallingFeatureId(callingFeatureId) |
| 7912 | .setCallingPid(Binder.getCallingPid()) |
| 7913 | .setCallingUid(Binder.getCallingUid()) |
| 7914 | .setMethod("getServiceStateForSubscriber") |
| 7915 | .setLogAsInfo(true) |
| 7916 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7917 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7918 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7919 | .build()); |
| 7920 | hasFinePermission = |
| 7921 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7922 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7923 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7924 | if (!renounceCoarseLocationAccess) { |
| 7925 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7926 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7927 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7928 | .setCallingPackage(callingPackage) |
| 7929 | .setCallingFeatureId(callingFeatureId) |
| 7930 | .setCallingPid(Binder.getCallingPid()) |
| 7931 | .setCallingUid(Binder.getCallingUid()) |
| 7932 | .setMethod("getServiceStateForSubscriber") |
| 7933 | .setLogAsInfo(true) |
| 7934 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7935 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7936 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7937 | .build()); |
| 7938 | hasCoarsePermission = |
| 7939 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7940 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7941 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7942 | final Phone phone = getPhone(subId); |
| 7943 | if (phone == null) { |
| 7944 | return null; |
| 7945 | } |
| 7946 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7947 | final long identity = Binder.clearCallingIdentity(); |
| 7948 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7949 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7950 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7951 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7952 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7953 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7954 | Rlog.d(LOG_TAG, |
| 7955 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7956 | return null; |
| 7957 | } |
| 7958 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7959 | ServiceState ss = phone.getServiceState(); |
| 7960 | |
| 7961 | // Scrub out the location info in ServiceState depending on what level of access |
| 7962 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7963 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7964 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7965 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7966 | } finally { |
| 7967 | Binder.restoreCallingIdentity(identity); |
| 7968 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7969 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7970 | |
| 7971 | /** |
| 7972 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7973 | * |
| 7974 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7975 | * voicemail ringtone. |
| 7976 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7977 | * PhoneAccount. |
| 7978 | */ |
| 7979 | @Override |
| 7980 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7981 | final long identity = Binder.clearCallingIdentity(); |
| 7982 | try { |
| 7983 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7984 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7985 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7986 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7987 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7988 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7989 | } finally { |
| 7990 | Binder.restoreCallingIdentity(identity); |
| 7991 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7992 | } |
| 7993 | |
| 7994 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7995 | * Sets the per-account voicemail ringtone. |
| 7996 | * |
| 7997 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7998 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7999 | * |
| 8000 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8001 | * voicemail ringtone. |
| 8002 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8003 | * PhoneAccount. |
| 8004 | */ |
| 8005 | @Override |
| 8006 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8007 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8008 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8009 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8010 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8011 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8012 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8013 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8014 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8015 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8016 | |
| 8017 | final long identity = Binder.clearCallingIdentity(); |
| 8018 | try { |
| 8019 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8020 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8021 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8022 | } |
| 8023 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8024 | } finally { |
| 8025 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8026 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8027 | } |
| 8028 | |
| 8029 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8030 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8031 | * |
| 8032 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8033 | * voicemail vibration setting. |
| 8034 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8035 | */ |
| 8036 | @Override |
| 8037 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8038 | final long identity = Binder.clearCallingIdentity(); |
| 8039 | try { |
| 8040 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8041 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8042 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8043 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8044 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8045 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8046 | } finally { |
| 8047 | Binder.restoreCallingIdentity(identity); |
| 8048 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8049 | } |
| 8050 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8051 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8052 | * Sets the per-account voicemail vibration. |
| 8053 | * |
| 8054 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8055 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8056 | * |
| 8057 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8058 | * voicemail vibration setting. |
| 8059 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8060 | * specific PhoneAccount. |
| 8061 | */ |
| 8062 | @Override |
| 8063 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8064 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8065 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8066 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8067 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8068 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8069 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8070 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8071 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8072 | } |
| 8073 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8074 | final long identity = Binder.clearCallingIdentity(); |
| 8075 | try { |
| 8076 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8077 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8078 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8079 | } |
| 8080 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8081 | } finally { |
| 8082 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8083 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8084 | } |
| 8085 | |
| 8086 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8087 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8088 | * |
| 8089 | * @throws SecurityException if the caller does not have the required permission |
| 8090 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8091 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8092 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8093 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8094 | } |
| 8095 | |
| 8096 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8097 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8098 | * permission. |
| 8099 | * |
| 8100 | * @throws SecurityException if the caller does not have the required permission |
| 8101 | */ |
| 8102 | private void enforceSendSmsPermission() { |
| 8103 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8104 | } |
| 8105 | |
| 8106 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8107 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8108 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8109 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8110 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8111 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8112 | final long identity = Binder.clearCallingIdentity(); |
| 8113 | try { |
| 8114 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8115 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8116 | if (componentName == null) { |
| 8117 | throw new SecurityException( |
| 8118 | "Caller not current active visual voicemail package[null]"); |
| 8119 | } |
| 8120 | String vvmPackage = componentName.getPackageName(); |
| 8121 | if (!callingPackage.equals(vvmPackage)) { |
| 8122 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 8123 | + vvmPackage + "]"); |
| 8124 | } |
| 8125 | } finally { |
| 8126 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8127 | } |
| 8128 | } |
| 8129 | |
| 8130 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8131 | * Return the application ID for the app type. |
| 8132 | * |
| 8133 | * @param subId the subscription ID that this request applies to. |
| 8134 | * @param appType the uicc app type. |
| 8135 | * @return Application ID for specificied app type, or null if no uicc. |
| 8136 | */ |
| 8137 | @Override |
| 8138 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8139 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8140 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8141 | |
| 8142 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8143 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8144 | if (phone == null) { |
| 8145 | return null; |
| 8146 | } |
| 8147 | String aid = null; |
| 8148 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8149 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8150 | .getApplicationByType(appType).getAid(); |
| 8151 | } catch (Exception e) { |
| 8152 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8153 | } |
| 8154 | return aid; |
| 8155 | } finally { |
| 8156 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8157 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8158 | } |
| 8159 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8160 | /** |
| 8161 | * Return the Electronic Serial Number. |
| 8162 | * |
| 8163 | * @param subId the subscription ID that this request applies to. |
| 8164 | * @return ESN or null if error. |
| 8165 | */ |
| 8166 | @Override |
| 8167 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8168 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8169 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8170 | |
| 8171 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8172 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8173 | if (phone == null) { |
| 8174 | return null; |
| 8175 | } |
| 8176 | String esn = null; |
| 8177 | try { |
| 8178 | esn = phone.getEsn(); |
| 8179 | } catch (Exception e) { |
| 8180 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8181 | } |
| 8182 | return esn; |
| 8183 | } finally { |
| 8184 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8185 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8186 | } |
| 8187 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8188 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8189 | * Return the Preferred Roaming List Version. |
| 8190 | * |
| 8191 | * @param subId the subscription ID that this request applies to. |
| 8192 | * @return PRLVersion or null if error. |
| 8193 | */ |
| 8194 | @Override |
| 8195 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8196 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8197 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8198 | |
| 8199 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8200 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8201 | if (phone == null) { |
| 8202 | return null; |
| 8203 | } |
| 8204 | String cdmaPrlVersion = null; |
| 8205 | try { |
| 8206 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8207 | } catch (Exception e) { |
| 8208 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8209 | } |
| 8210 | return cdmaPrlVersion; |
| 8211 | } finally { |
| 8212 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8213 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8214 | } |
| 8215 | |
| 8216 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8217 | * Get snapshot of Telephony histograms |
| 8218 | * @return List of Telephony histograms |
| 8219 | * @hide |
| 8220 | */ |
| 8221 | @Override |
| 8222 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8223 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8224 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8225 | |
| 8226 | final long identity = Binder.clearCallingIdentity(); |
| 8227 | try { |
| 8228 | return RIL.getTelephonyRILTimingHistograms(); |
| 8229 | } finally { |
| 8230 | Binder.restoreCallingIdentity(identity); |
| 8231 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8232 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8233 | |
| 8234 | /** |
| 8235 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8236 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8237 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8238 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8239 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8240 | * @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] | 8241 | */ |
| 8242 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8243 | @TelephonyManager.SetCarrierRestrictionResult |
| 8244 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8245 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8246 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8247 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8248 | if (carrierRestrictionRules == null) { |
| 8249 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8250 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8251 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8252 | final long identity = Binder.clearCallingIdentity(); |
| 8253 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8254 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8255 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8256 | } finally { |
| 8257 | Binder.restoreCallingIdentity(identity); |
| 8258 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8259 | } |
| 8260 | |
| 8261 | /** |
| 8262 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8263 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8264 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8265 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8266 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8267 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8268 | */ |
| 8269 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8270 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8271 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8272 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8273 | |
| 8274 | final long identity = Binder.clearCallingIdentity(); |
| 8275 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8276 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8277 | if (response instanceof CarrierRestrictionRules) { |
| 8278 | return (CarrierRestrictionRules) response; |
| 8279 | } |
| 8280 | // Response is an Exception of some kind, |
| 8281 | // which is signalled to the user as a NULL retval |
| 8282 | return null; |
| 8283 | } catch (Exception e) { |
| 8284 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8285 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8286 | } finally { |
| 8287 | Binder.restoreCallingIdentity(identity); |
| 8288 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8289 | } |
| 8290 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8291 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8292 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8293 | * @param subId the subscription ID that this action applies to. |
| 8294 | * @param enabled control enable or disable radio. |
| 8295 | * {@hide} |
| 8296 | */ |
| 8297 | @Override |
| 8298 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8299 | enforceModifyPermission(); |
| 8300 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8301 | |
| 8302 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8303 | if (phone == null) { |
| 8304 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8305 | return; |
| 8306 | } |
| 8307 | try { |
| 8308 | phone.carrierActionSetRadioEnabled(enabled); |
| 8309 | } catch (Exception e) { |
| 8310 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8311 | } finally { |
| 8312 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8313 | } |
| 8314 | } |
| 8315 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8316 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8317 | * Enable or disable Voice over NR (VoNR) |
| 8318 | * @param subId the subscription ID that this action applies to. |
| 8319 | * @param enabled enable or disable VoNR. |
| 8320 | * @return operation result. |
| 8321 | */ |
| 8322 | @Override |
| 8323 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8324 | enforceModifyPermission(); |
| 8325 | final Phone phone = getPhone(subId); |
| 8326 | |
| 8327 | final long identity = Binder.clearCallingIdentity(); |
| 8328 | if (phone == null) { |
| 8329 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8330 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8331 | } |
| 8332 | |
| 8333 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8334 | try { |
| 8335 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8336 | workSource); |
| 8337 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8338 | |
| 8339 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8340 | if (DBG) { |
| 8341 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8342 | } |
| 8343 | SubscriptionManager.setSubscriptionProperty( |
| 8344 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8345 | (enabled ? "1" : "0")); |
| 8346 | } |
| 8347 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8348 | return result; |
| 8349 | } finally { |
| 8350 | Binder.restoreCallingIdentity(identity); |
| 8351 | } |
| 8352 | } |
| 8353 | |
| 8354 | /** |
| 8355 | * Is voice over NR enabled |
| 8356 | * @return true if VoNR is enabled else false |
| 8357 | */ |
| 8358 | @Override |
| 8359 | public boolean isVoNrEnabled(int subId) { |
| 8360 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8361 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8362 | final long identity = Binder.clearCallingIdentity(); |
| 8363 | try { |
| 8364 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8365 | null, subId, workSource); |
| 8366 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8367 | return isEnabled; |
| 8368 | } finally { |
| 8369 | Binder.restoreCallingIdentity(identity); |
| 8370 | } |
| 8371 | } |
| 8372 | |
| 8373 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8374 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8375 | * network status based on which carrier apps could apply actions accordingly, |
| 8376 | * enable/disable default url handler for example. |
| 8377 | * |
| 8378 | * @param subId the subscription ID that this action applies to. |
| 8379 | * @param report control start/stop reporting the default network status. |
| 8380 | * {@hide} |
| 8381 | */ |
| 8382 | @Override |
| 8383 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8384 | enforceModifyPermission(); |
| 8385 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8386 | |
| 8387 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8388 | if (phone == null) { |
| 8389 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8390 | return; |
| 8391 | } |
| 8392 | try { |
| 8393 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8394 | } catch (Exception e) { |
| 8395 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8396 | } finally { |
| 8397 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8398 | } |
| 8399 | } |
| 8400 | |
| 8401 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8402 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8403 | * @param subId the subscription ID that this action applies to. |
| 8404 | * {@hide} |
| 8405 | */ |
| 8406 | @Override |
| 8407 | public void carrierActionResetAll(int subId) { |
| 8408 | enforceModifyPermission(); |
| 8409 | final Phone phone = getPhone(subId); |
| 8410 | if (phone == null) { |
| 8411 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8412 | return; |
| 8413 | } |
| 8414 | try { |
| 8415 | phone.carrierActionResetAll(); |
| 8416 | } catch (Exception e) { |
| 8417 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8418 | } |
| 8419 | } |
| 8420 | |
| 8421 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8422 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8423 | * bug report is being generated. |
| 8424 | */ |
| 8425 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8426 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8427 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8428 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8429 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8430 | + Binder.getCallingPid() |
| 8431 | + ", uid=" + Binder.getCallingUid() |
| 8432 | + "without permission " |
| 8433 | + android.Manifest.permission.DUMP); |
| 8434 | return; |
| 8435 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8436 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8437 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8438 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8439 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8440 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8441 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8442 | @NonNull String[] args) { |
| 8443 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8444 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8445 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8446 | } |
| 8447 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8448 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8449 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8450 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8451 | * @param reason the reason the data enable change is taking place |
| 8452 | * @param enabled True if enabling the data, otherwise disabling. |
| 8453 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8454 | */ |
| 8455 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8456 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8457 | boolean enabled) { |
| 8458 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8459 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8460 | try { |
| 8461 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8462 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8463 | } catch (SecurityException se) { |
| 8464 | enforceModifyPermission(); |
| 8465 | } |
| 8466 | } else { |
| 8467 | enforceModifyPermission(); |
| 8468 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8469 | |
| 8470 | final long identity = Binder.clearCallingIdentity(); |
| 8471 | try { |
| 8472 | Phone phone = getPhone(subId); |
| 8473 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8474 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8475 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8476 | } else { |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 8477 | if (phone.isUsingNewDataStack()) { |
| 8478 | phone.getDataSettingsManager().setDataEnabled(reason, enabled); |
| 8479 | } else { |
| 8480 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 8481 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8482 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8483 | } |
| 8484 | } finally { |
| 8485 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8486 | } |
| 8487 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8488 | |
| 8489 | /** |
| 8490 | * Get Client request stats |
| 8491 | * @return List of Client Request Stats |
| 8492 | * @hide |
| 8493 | */ |
| 8494 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8495 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8496 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8497 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8498 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8499 | return null; |
| 8500 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8501 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8502 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8503 | final long identity = Binder.clearCallingIdentity(); |
| 8504 | try { |
| 8505 | if (phone != null) { |
| 8506 | return phone.getClientRequestStats(); |
| 8507 | } |
| 8508 | |
| 8509 | return null; |
| 8510 | } finally { |
| 8511 | Binder.restoreCallingIdentity(identity); |
| 8512 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8513 | } |
| 8514 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8515 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8516 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8517 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8518 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8519 | |
| 8520 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8521 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8522 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8523 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8524 | * @param state State of SIM (power down, power up, pass through) |
| 8525 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8526 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8527 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8528 | * |
| 8529 | **/ |
| 8530 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8531 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8532 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8533 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8534 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8535 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8536 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8537 | final long identity = Binder.clearCallingIdentity(); |
| 8538 | try { |
| 8539 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8540 | phone.setSimPowerState(state, null, workSource); |
| 8541 | } |
| 8542 | } finally { |
| 8543 | Binder.restoreCallingIdentity(identity); |
| 8544 | } |
| 8545 | } |
| 8546 | |
| 8547 | /** |
| 8548 | * Set SIM card power state. |
| 8549 | * |
| 8550 | * @param slotIndex SIM slot id. |
| 8551 | * @param state State of SIM (power down, power up, pass through) |
| 8552 | * @param callback callback to trigger after success or failure |
| 8553 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8554 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8555 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8556 | * |
| 8557 | **/ |
| 8558 | @Override |
| 8559 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8560 | IIntegerConsumer callback) { |
| 8561 | enforceModifyPermission(); |
| 8562 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8563 | |
| 8564 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8565 | |
| 8566 | final long identity = Binder.clearCallingIdentity(); |
| 8567 | try { |
| 8568 | if (phone != null) { |
| 8569 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8570 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8571 | } |
| 8572 | } finally { |
| 8573 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8574 | } |
| 8575 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8576 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8577 | private boolean isUssdApiAllowed(int subId) { |
| 8578 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8579 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8580 | if (configManager == null) { |
| 8581 | return false; |
| 8582 | } |
| 8583 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8584 | if (pb == null) { |
| 8585 | return false; |
| 8586 | } |
| 8587 | return pb.getBoolean( |
| 8588 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8589 | } |
| 8590 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8591 | /** |
| 8592 | * Check if phone is in emergency callback mode |
| 8593 | * @return true if phone is in emergency callback mode |
| 8594 | * @param subId sub id |
| 8595 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8596 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8597 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8598 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8599 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8600 | |
| 8601 | final long identity = Binder.clearCallingIdentity(); |
| 8602 | try { |
| 8603 | if (phone != null) { |
| 8604 | return phone.isInEcm(); |
| 8605 | } else { |
| 8606 | return false; |
| 8607 | } |
| 8608 | } finally { |
| 8609 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8610 | } |
| 8611 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8612 | |
| 8613 | /** |
| 8614 | * Get the current signal strength information for the given subscription. |
| 8615 | * Because this information is not updated when the device is in a low power state |
| 8616 | * it should not be relied-upon to be current. |
| 8617 | * @param subId Subscription index |
| 8618 | * @return the most recent cached signal strength info from the modem |
| 8619 | */ |
| 8620 | @Override |
| 8621 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8622 | final long identity = Binder.clearCallingIdentity(); |
| 8623 | try { |
| 8624 | Phone p = getPhone(subId); |
| 8625 | if (p == null) { |
| 8626 | return null; |
| 8627 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8628 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8629 | return p.getSignalStrength(); |
| 8630 | } finally { |
| 8631 | Binder.restoreCallingIdentity(identity); |
| 8632 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8633 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8634 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8635 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8636 | * Get the current modem radio state for the given slot. |
| 8637 | * @param slotIndex slot index. |
| 8638 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8639 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8640 | * @return the current radio power state from the modem |
| 8641 | */ |
| 8642 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8643 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8644 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8645 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8646 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8647 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8648 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8649 | } |
| 8650 | |
| 8651 | final long identity = Binder.clearCallingIdentity(); |
| 8652 | try { |
| 8653 | return phone.getRadioPowerState(); |
| 8654 | } finally { |
| 8655 | Binder.restoreCallingIdentity(identity); |
| 8656 | } |
| 8657 | } |
| 8658 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8659 | } |
| 8660 | |
| 8661 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8662 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8663 | * |
| 8664 | * <p>Requires one of the following permissions: |
| 8665 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8666 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8667 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8668 | * privileges. |
| 8669 | * |
| 8670 | * @param subId subscription id |
| 8671 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8672 | * {@code false}. |
| 8673 | */ |
| 8674 | @Override |
| 8675 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8676 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8677 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8678 | try { |
| 8679 | mApp.enforceCallingOrSelfPermission( |
| 8680 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8681 | functionName); |
| 8682 | } catch (Exception e) { |
| 8683 | mApp.enforceCallingOrSelfPermission( |
| 8684 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 8685 | } |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8686 | } catch (Exception e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8687 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8688 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8689 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8690 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8691 | boolean isEnabled = false; |
| 8692 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8693 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8694 | Phone phone = getPhone(subId); |
| 8695 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8696 | } finally { |
| 8697 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8698 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8699 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8700 | } |
| 8701 | |
| 8702 | |
| 8703 | /** |
| 8704 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8705 | * |
| 8706 | * <p> Requires permission: |
| 8707 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8708 | * privileges. |
| 8709 | * |
| 8710 | * @param subId subscription id |
| 8711 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8712 | */ |
| 8713 | @Override |
| 8714 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8715 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8716 | mApp, subId, "setDataRoamingEnabled"); |
| 8717 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8718 | final long identity = Binder.clearCallingIdentity(); |
| 8719 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8720 | Phone phone = getPhone(subId); |
| 8721 | if (phone != null) { |
| 8722 | phone.setDataRoamingEnabled(isEnabled); |
| 8723 | } |
| 8724 | } finally { |
| 8725 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8726 | } |
| 8727 | } |
| 8728 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8729 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8730 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8731 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8732 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8733 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8734 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8735 | boolean isAllowed = true; |
| 8736 | final long identity = Binder.clearCallingIdentity(); |
| 8737 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8738 | Phone phone = getPhone(subId); |
| 8739 | if (phone != null) { |
| 8740 | isAllowed = phone.isCspPlmnEnabled(); |
| 8741 | } |
| 8742 | } finally { |
| 8743 | Binder.restoreCallingIdentity(identity); |
| 8744 | } |
| 8745 | return isAllowed; |
| 8746 | } |
| 8747 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8748 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 8749 | UiccProfile profile = port.getUiccProfile(); |
| 8750 | if (profile == null || |
| 8751 | profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8752 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8753 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8754 | } |
| 8755 | return true; |
| 8756 | } |
| 8757 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8758 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8759 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8760 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8761 | mApp.getSystemService(AppOpsManager.class) |
| 8762 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8763 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8764 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8765 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8766 | try { |
| 8767 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8768 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8769 | } catch (SecurityException e) { |
| 8770 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8771 | // has carrier privileges on an active UICC |
| 8772 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8773 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8774 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8775 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8776 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8777 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8778 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8779 | Binder.getCallingUid())) { |
| 8780 | isIccIdAccessRestricted = true; |
| 8781 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8782 | final long identity = Binder.clearCallingIdentity(); |
| 8783 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8784 | UiccController uiccController = UiccController.getInstance(); |
| 8785 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8786 | if (hasReadPermission) { |
| 8787 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8788 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8789 | |
| 8790 | // Remove private info if the caller doesn't have access |
| 8791 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8792 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8793 | //setting the value after compatibility check |
| 8794 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8795 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8796 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8797 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8798 | if (card == null) { |
| 8799 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8800 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8801 | continue; |
| 8802 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8803 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 8804 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8805 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8806 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8807 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8808 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 8809 | for (UiccPortInfo portInfo : portInfos) { |
| 8810 | UiccPort port = uiccController.getUiccPortForSlot( |
| 8811 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 8812 | if (port == null) { |
| 8813 | // assume no access if port is null |
| 8814 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8815 | continue; |
| 8816 | } |
| 8817 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 8818 | uiccPortInfos.add(portInfo); |
| 8819 | } else { |
| 8820 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8821 | } |
| 8822 | } |
| 8823 | filteredInfos.add(new UiccCardInfo( |
| 8824 | cardInfo.isEuicc(), |
| 8825 | cardInfo.getCardId(), |
| 8826 | null, |
| 8827 | cardInfo.getPhysicalSlotIndex(), |
| 8828 | cardInfo.isRemovable(), |
| 8829 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8830 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8831 | } |
| 8832 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8833 | } finally { |
| 8834 | Binder.restoreCallingIdentity(identity); |
| 8835 | } |
| 8836 | } |
| 8837 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8838 | /** |
| 8839 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 8840 | * generally private and require carrier privileges to view. |
| 8841 | * |
| 8842 | * @hide |
| 8843 | */ |
| 8844 | @NonNull |
| 8845 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 8846 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 8847 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 8848 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 8849 | } |
| 8850 | return new UiccCardInfo( |
| 8851 | cardInfo.isEuicc(), |
| 8852 | cardInfo.getCardId(), |
| 8853 | null, |
| 8854 | cardInfo.getPhysicalSlotIndex(), |
| 8855 | cardInfo.isRemovable(), |
| 8856 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8857 | portinfo |
| 8858 | ); |
| 8859 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8860 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8861 | /** |
| 8862 | * @hide |
| 8863 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 8864 | * These values are generally private and require carrier privileges to view. |
| 8865 | */ |
| 8866 | @NonNull |
| 8867 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 8868 | return new UiccPortInfo( |
| 8869 | UiccPortInfo.ICCID_REDACTED, |
| 8870 | portInfo.getPortIndex(), |
| 8871 | portInfo.getLogicalSlotIndex(), |
| 8872 | portInfo.isActive() |
| 8873 | ); |
| 8874 | } |
| 8875 | @Override |
| 8876 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8877 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8878 | mApp.getSystemService(AppOpsManager.class) |
| 8879 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8880 | |
| 8881 | boolean hasReadPermission = false; |
| 8882 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8883 | |
| 8884 | try { |
| 8885 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
| 8886 | hasReadPermission = true; |
| 8887 | } catch (SecurityException e) { |
| 8888 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8889 | // has carrier privileges on an active UICC |
| 8890 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8891 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8892 | hasReadPermission = true; |
| 8893 | } |
| 8894 | } |
| 8895 | |
| 8896 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8897 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8898 | Binder.getCallingUid())) { |
| 8899 | isLogicalSlotAccessRestricted = true; |
| 8900 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8901 | final long identity = Binder.clearCallingIdentity(); |
| 8902 | try { |
| 8903 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8904 | if (slots == null) { |
| 8905 | Rlog.i(LOG_TAG, "slots is null."); |
| 8906 | return null; |
| 8907 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8908 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8909 | for (int i = 0; i < slots.length; i++) { |
| 8910 | UiccSlot slot = slots[i]; |
| 8911 | if (slot == null) { |
| 8912 | continue; |
| 8913 | } |
| 8914 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8915 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8916 | UiccCard card = slot.getUiccCard(); |
| 8917 | if (card != null) { |
| 8918 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8919 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8920 | cardId = slot.getEid(); |
| 8921 | if (TextUtils.isEmpty(cardId)) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8922 | // If cardId is null, use iccId of default port as cardId. Check if has |
| 8923 | // read permission otherwise set to null.(card is null which means no |
| 8924 | // carrier permission) |
| 8925 | cardId = hasReadPermission ? slot.getIccId( |
| 8926 | TelephonyManager.DEFAULT_PORT_INDEX) : null; |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8927 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8928 | } |
| 8929 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8930 | if (cardId != null) { |
| 8931 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8932 | // if cardId is an EID, it's all digits so this is fine |
| 8933 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8934 | } |
| 8935 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8936 | int cardState = 0; |
| 8937 | switch (slot.getCardState()) { |
| 8938 | case CARDSTATE_ABSENT: |
| 8939 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8940 | break; |
| 8941 | case CARDSTATE_PRESENT: |
| 8942 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8943 | break; |
| 8944 | case CARDSTATE_ERROR: |
| 8945 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8946 | break; |
| 8947 | case CARDSTATE_RESTRICTED: |
| 8948 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8949 | break; |
| 8950 | default: |
| 8951 | break; |
| 8952 | |
| 8953 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8954 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 8955 | int[] portIndexes = slot.getPortList(); |
| 8956 | for (int portIdx : portIndexes) { |
| 8957 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
| 8958 | callingPackage, hasReadPermission)); |
| 8959 | if (slot.isPortActive(portIdx)) { |
| 8960 | UiccPort port = slot.getUiccCard().getUiccPort(portIdx); |
| 8961 | portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(), |
| 8962 | port.getPhoneId(), true)); |
| 8963 | } else { |
| 8964 | portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false)); |
| 8965 | } |
| 8966 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8967 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8968 | slot.isEuicc(), |
| 8969 | cardId, |
| 8970 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8971 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8972 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8973 | //setting the value after compatibility check |
| 8974 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8975 | } |
| 8976 | return infos; |
| 8977 | } finally { |
| 8978 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8979 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8980 | } |
| 8981 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8982 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 8983 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 8984 | boolean hasReadPermission) { |
| 8985 | String iccId = slot.getIccId(portIndex); |
| 8986 | if (hasReadPermission) { // if has read permission |
| 8987 | return iccId; |
| 8988 | } else { |
| 8989 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 8990 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 8991 | // if no read permission, checking carrier privilege access |
| 8992 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 8993 | return iccId; |
| 8994 | } |
| 8995 | } |
| 8996 | } |
| 8997 | // No read permission or carrier privilege access. |
| 8998 | return UiccPortInfo.ICCID_REDACTED; |
| 8999 | } |
| 9000 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9001 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9002 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9003 | public boolean switchSlots(int[] physicalSlots) { |
| 9004 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9005 | |
| 9006 | final long identity = Binder.clearCallingIdentity(); |
| 9007 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9008 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9009 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9010 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9011 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9012 | physicalSlots[i], i)); |
| 9013 | } |
| 9014 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9015 | } finally { |
| 9016 | Binder.restoreCallingIdentity(identity); |
| 9017 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9018 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9019 | |
| 9020 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9021 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9022 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9023 | enforceModifyPermission(); |
| 9024 | |
| 9025 | final long identity = Binder.clearCallingIdentity(); |
| 9026 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9027 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9028 | } finally { |
| 9029 | Binder.restoreCallingIdentity(identity); |
| 9030 | } |
| 9031 | } |
| 9032 | |
| 9033 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9034 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9035 | final long identity = Binder.clearCallingIdentity(); |
| 9036 | try { |
| 9037 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9038 | } finally { |
| 9039 | Binder.restoreCallingIdentity(identity); |
| 9040 | } |
| 9041 | } |
| 9042 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9043 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9044 | * A test API to reload the UICC profile. |
| 9045 | * |
| 9046 | * <p>Requires that the calling app has permission |
| 9047 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9048 | * @hide |
| 9049 | */ |
| 9050 | @Override |
| 9051 | public void refreshUiccProfile(int subId) { |
| 9052 | enforceModifyPermission(); |
| 9053 | |
| 9054 | final long identity = Binder.clearCallingIdentity(); |
| 9055 | try { |
| 9056 | Phone phone = getPhone(subId); |
| 9057 | if (phone == null) { |
| 9058 | return; |
| 9059 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9060 | UiccPort uiccPort = phone.getUiccPort(); |
| 9061 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9062 | return; |
| 9063 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9064 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9065 | if (uiccProfile == null) { |
| 9066 | return; |
| 9067 | } |
| 9068 | uiccProfile.refresh(); |
| 9069 | } finally { |
| 9070 | Binder.restoreCallingIdentity(identity); |
| 9071 | } |
| 9072 | } |
| 9073 | |
| 9074 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9075 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9076 | */ |
| 9077 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9078 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9079 | } |
| 9080 | |
| 9081 | /** |
| 9082 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9083 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9084 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9085 | */ |
| 9086 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9087 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9088 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9089 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9090 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9091 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9092 | return isDataRoamingEnabled; |
| 9093 | } |
| 9094 | |
| 9095 | /** |
| 9096 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9097 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9098 | */ |
| 9099 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9100 | List<Integer> list = TelephonyProperties.default_network(); |
| 9101 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 9102 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9103 | return list.get(phoneId); |
| 9104 | } |
| 9105 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9106 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9107 | |
| 9108 | @Override |
| 9109 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9110 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9111 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9112 | |
| 9113 | final long identity = Binder.clearCallingIdentity(); |
| 9114 | try { |
| 9115 | final Phone phone = getPhone(subId); |
| 9116 | if (phone == null) { |
| 9117 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9118 | return; |
| 9119 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9120 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9121 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9122 | if (carrierPrivilegeRules == null) { |
| 9123 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9124 | } else { |
| 9125 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9126 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9127 | } finally { |
| 9128 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9129 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9130 | } |
| 9131 | |
| 9132 | @Override |
| 9133 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9134 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9135 | |
| 9136 | final long identity = Binder.clearCallingIdentity(); |
| 9137 | try { |
| 9138 | final Phone phone = getPhone(subId); |
| 9139 | if (phone == null) { |
| 9140 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9141 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9142 | } |
| 9143 | return phone.getCarrierIdListVersion(); |
| 9144 | } finally { |
| 9145 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9146 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9147 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9148 | |
| 9149 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9150 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9151 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9152 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9153 | mApp, subId, callingPackage, callingFeatureId, |
| 9154 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9155 | return -1; |
| 9156 | } |
| 9157 | |
| 9158 | final long identity = Binder.clearCallingIdentity(); |
| 9159 | try { |
| 9160 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9161 | } finally { |
| 9162 | Binder.restoreCallingIdentity(identity); |
| 9163 | } |
| 9164 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9165 | |
| 9166 | @Override |
| 9167 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9168 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9169 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9170 | mApp, subId, "getCdmaRoamingMode"); |
| 9171 | |
| 9172 | final long identity = Binder.clearCallingIdentity(); |
| 9173 | try { |
| 9174 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9175 | } finally { |
| 9176 | Binder.restoreCallingIdentity(identity); |
| 9177 | } |
| 9178 | } |
| 9179 | |
| 9180 | @Override |
| 9181 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9182 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9183 | mApp, subId, "setCdmaRoamingMode"); |
| 9184 | |
| 9185 | final long identity = Binder.clearCallingIdentity(); |
| 9186 | try { |
| 9187 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9188 | } finally { |
| 9189 | Binder.restoreCallingIdentity(identity); |
| 9190 | } |
| 9191 | } |
| 9192 | |
| 9193 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9194 | public int getCdmaSubscriptionMode(int subId) { |
| 9195 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9196 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9197 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9198 | |
| 9199 | final long identity = Binder.clearCallingIdentity(); |
| 9200 | try { |
| 9201 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9202 | } finally { |
| 9203 | Binder.restoreCallingIdentity(identity); |
| 9204 | } |
| 9205 | } |
| 9206 | |
| 9207 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9208 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9209 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9210 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9211 | |
| 9212 | final long identity = Binder.clearCallingIdentity(); |
| 9213 | try { |
| 9214 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9215 | } finally { |
| 9216 | Binder.restoreCallingIdentity(identity); |
| 9217 | } |
| 9218 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9219 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9220 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9221 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9222 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9223 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9224 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9225 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9226 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9227 | } |
| 9228 | final long identity = Binder.clearCallingIdentity(); |
| 9229 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9230 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9231 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9232 | if (phone.getEmergencyNumberTracker() != null |
| 9233 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9234 | emergencyNumberListInternal.put( |
| 9235 | phone.getSubId(), |
| 9236 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9237 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9238 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9239 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9240 | } finally { |
| 9241 | Binder.restoreCallingIdentity(identity); |
| 9242 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9243 | } |
| 9244 | |
| 9245 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9246 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9247 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9248 | if (!exactMatch) { |
| 9249 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9250 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9251 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9252 | } |
| 9253 | final long identity = Binder.clearCallingIdentity(); |
| 9254 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9255 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9256 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9257 | && phone.getEmergencyNumberTracker() |
| 9258 | .isEmergencyNumber(number, exactMatch)) { |
| 9259 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9260 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9261 | } |
| 9262 | return false; |
| 9263 | } finally { |
| 9264 | Binder.restoreCallingIdentity(identity); |
| 9265 | } |
| 9266 | } |
| 9267 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9268 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9269 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9270 | */ |
| 9271 | @Override |
| 9272 | public void startEmergencyCallbackMode() { |
| 9273 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9274 | "startEmergencyCallbackMode"); |
| 9275 | enforceModifyPermission(); |
| 9276 | final long identity = Binder.clearCallingIdentity(); |
| 9277 | try { |
| 9278 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9279 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9280 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9281 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9282 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9283 | gsmCdmaPhone.obtainMessage( |
| 9284 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9285 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9286 | } |
| 9287 | } |
| 9288 | } finally { |
| 9289 | Binder.restoreCallingIdentity(identity); |
| 9290 | } |
| 9291 | } |
| 9292 | |
| 9293 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9294 | * Update emergency number list for test mode. |
| 9295 | */ |
| 9296 | @Override |
| 9297 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9298 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9299 | "updateEmergencyNumberListTestMode"); |
| 9300 | |
| 9301 | final long identity = Binder.clearCallingIdentity(); |
| 9302 | try { |
| 9303 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9304 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9305 | if (tracker != null) { |
| 9306 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9307 | } |
| 9308 | } |
| 9309 | } finally { |
| 9310 | Binder.restoreCallingIdentity(identity); |
| 9311 | } |
| 9312 | } |
| 9313 | |
| 9314 | /** |
| 9315 | * Get the full emergency number list for test mode. |
| 9316 | */ |
| 9317 | @Override |
| 9318 | public List<String> getEmergencyNumberListTestMode() { |
| 9319 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9320 | "getEmergencyNumberListTestMode"); |
| 9321 | |
| 9322 | final long identity = Binder.clearCallingIdentity(); |
| 9323 | try { |
| 9324 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9325 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9326 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9327 | if (tracker != null) { |
| 9328 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9329 | emergencyNumbers.add(num.getNumber()); |
| 9330 | } |
| 9331 | } |
| 9332 | } |
| 9333 | return new ArrayList<>(emergencyNumbers); |
| 9334 | } finally { |
| 9335 | Binder.restoreCallingIdentity(identity); |
| 9336 | } |
| 9337 | } |
| 9338 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9339 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9340 | public int getEmergencyNumberDbVersion(int subId) { |
| 9341 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9342 | |
| 9343 | final long identity = Binder.clearCallingIdentity(); |
| 9344 | try { |
| 9345 | final Phone phone = getPhone(subId); |
| 9346 | if (phone == null) { |
| 9347 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9348 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9349 | } |
| 9350 | return phone.getEmergencyNumberDbVersion(); |
| 9351 | } finally { |
| 9352 | Binder.restoreCallingIdentity(identity); |
| 9353 | } |
| 9354 | } |
| 9355 | |
| 9356 | @Override |
| 9357 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9358 | enforceModifyPermission(); |
| 9359 | |
| 9360 | final long identity = Binder.clearCallingIdentity(); |
| 9361 | try { |
| 9362 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9363 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9364 | if (tracker != null) { |
| 9365 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9366 | } |
| 9367 | } |
| 9368 | } finally { |
| 9369 | Binder.restoreCallingIdentity(identity); |
| 9370 | } |
| 9371 | } |
| 9372 | |
| 9373 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9374 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9375 | enforceActiveEmergencySessionPermission(); |
| 9376 | |
| 9377 | final long identity = Binder.clearCallingIdentity(); |
| 9378 | try { |
| 9379 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9380 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9381 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9382 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9383 | } |
| 9384 | } |
| 9385 | } finally { |
| 9386 | Binder.restoreCallingIdentity(identity); |
| 9387 | } |
| 9388 | } |
| 9389 | |
| 9390 | @Override |
| 9391 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9392 | enforceActiveEmergencySessionPermission(); |
| 9393 | |
| 9394 | final long identity = Binder.clearCallingIdentity(); |
| 9395 | try { |
| 9396 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9397 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9398 | if (tracker != null) { |
| 9399 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9400 | } |
| 9401 | } |
| 9402 | } finally { |
| 9403 | Binder.restoreCallingIdentity(identity); |
| 9404 | } |
| 9405 | } |
| 9406 | |
| 9407 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9408 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9409 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9410 | Phone phone = getPhone(subId); |
| 9411 | if (phone == null) { |
| 9412 | return null; |
| 9413 | } |
| 9414 | final long identity = Binder.clearCallingIdentity(); |
| 9415 | try { |
| 9416 | UiccProfile profile = UiccController.getInstance() |
| 9417 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9418 | if (profile != null) { |
| 9419 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9420 | } |
| 9421 | } finally { |
| 9422 | Binder.restoreCallingIdentity(identity); |
| 9423 | } |
| 9424 | return null; |
| 9425 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9426 | |
| 9427 | /** |
| 9428 | * Enable or disable a modem stack. |
| 9429 | */ |
| 9430 | @Override |
| 9431 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9432 | enforceModifyPermission(); |
| 9433 | |
| 9434 | final long identity = Binder.clearCallingIdentity(); |
| 9435 | try { |
| 9436 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9437 | if (phone == null) { |
| 9438 | return false; |
| 9439 | } else { |
| 9440 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9441 | } |
| 9442 | } finally { |
| 9443 | Binder.restoreCallingIdentity(identity); |
| 9444 | } |
| 9445 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9446 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9447 | /** |
| 9448 | * Whether a modem stack is enabled or not. |
| 9449 | */ |
| 9450 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9451 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9452 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9453 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9454 | if (phone == null) return false; |
| 9455 | |
| 9456 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9457 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9458 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9459 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9460 | } |
| 9461 | |
| 9462 | final long identity = Binder.clearCallingIdentity(); |
| 9463 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9464 | try { |
| 9465 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9466 | } catch (NoSuchElementException ex) { |
| 9467 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9468 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9469 | } finally { |
| 9470 | Binder.restoreCallingIdentity(identity); |
| 9471 | } |
| 9472 | } |
| 9473 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9474 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9475 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9476 | enforceModifyPermission(); |
| 9477 | |
| 9478 | final long identity = Binder.clearCallingIdentity(); |
| 9479 | try { |
| 9480 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9481 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9482 | .commit(); |
| 9483 | } finally { |
| 9484 | Binder.restoreCallingIdentity(identity); |
| 9485 | } |
| 9486 | } |
| 9487 | |
| 9488 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9489 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9490 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9491 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9492 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9493 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9494 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9495 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9496 | |
| 9497 | final long identity = Binder.clearCallingIdentity(); |
| 9498 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9499 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9500 | } finally { |
| 9501 | Binder.restoreCallingIdentity(identity); |
| 9502 | } |
| 9503 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9504 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9505 | @TelephonyManager.IsMultiSimSupportedResult |
| 9506 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9507 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9508 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9509 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9510 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9511 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9512 | } |
| 9513 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9514 | // supported by the modem, indicate that it is restricted. |
| 9515 | PhoneCapability staticCapability = |
| 9516 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9517 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9518 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9519 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9520 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9521 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9522 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9523 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9524 | } |
| 9525 | // Check if support of multiple SIMs is restricted by carrier |
| 9526 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9527 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9528 | } |
| 9529 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9530 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9531 | } |
| 9532 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9533 | /** |
| 9534 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9535 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9536 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9537 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9538 | * @param numOfSims number of active sims we want to switch to |
| 9539 | */ |
| 9540 | @Override |
| 9541 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9542 | if (numOfSims == 1) { |
| 9543 | enforceModifyPermission(); |
| 9544 | } else { |
| 9545 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9546 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9547 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9548 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9549 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9550 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9551 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9552 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9553 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9554 | return; |
| 9555 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9556 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9557 | } finally { |
| 9558 | Binder.restoreCallingIdentity(identity); |
| 9559 | } |
| 9560 | } |
| 9561 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9562 | @Override |
| 9563 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9564 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9565 | Phone phone = getPhone(subId); |
| 9566 | if (phone == null) { |
| 9567 | return false; |
| 9568 | } |
| 9569 | final long identity = Binder.clearCallingIdentity(); |
| 9570 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9571 | UiccPort uiccPort = phone.getUiccPort(); |
| 9572 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9573 | return false; |
| 9574 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9575 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9576 | if (uiccProfile == null) { |
| 9577 | return false; |
| 9578 | } |
| 9579 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9580 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9581 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9582 | } |
| 9583 | return false; |
| 9584 | } finally { |
| 9585 | Binder.restoreCallingIdentity(identity); |
| 9586 | } |
| 9587 | } |
| 9588 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9589 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9590 | * Get whether making changes to modem configurations will trigger reboot. |
| 9591 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9592 | */ |
| 9593 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9594 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9595 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9596 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9597 | mApp, subId, callingPackage, callingFeatureId, |
| 9598 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9599 | return false; |
| 9600 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9601 | final long identity = Binder.clearCallingIdentity(); |
| 9602 | try { |
| 9603 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9604 | } finally { |
| 9605 | Binder.restoreCallingIdentity(identity); |
| 9606 | } |
| 9607 | } |
| 9608 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9609 | private void updateModemStateMetrics() { |
| 9610 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9611 | // TODO: check the state for each modem if the api is ready. |
| 9612 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9613 | } |
| 9614 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9615 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9616 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9617 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9618 | // Verify that the callingPackage belongs to the calling UID |
| 9619 | mApp.getSystemService(AppOpsManager.class) |
| 9620 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9621 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9622 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9623 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9624 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 9625 | if (slotInfos != null) { |
| 9626 | for (int i = 0; i < slotInfos.length; i++) { |
| 9627 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 9628 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 9629 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 9630 | portInfo.getLogicalSlotIndex())); |
| 9631 | } |
| 9632 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9633 | } |
| 9634 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9635 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9636 | } finally { |
| 9637 | Binder.restoreCallingIdentity(identity); |
| 9638 | } |
| 9639 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9640 | |
| 9641 | /** |
| 9642 | * Get the IRadio HAL Version |
| 9643 | */ |
| 9644 | @Override |
| 9645 | public int getRadioHalVersion() { |
| 9646 | Phone phone = getDefaultPhone(); |
| 9647 | if (phone == null) return -1; |
| 9648 | HalVersion hv = phone.getHalVersion(); |
| 9649 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9650 | return hv.major * 100 + hv.minor; |
| 9651 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9652 | |
| 9653 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9654 | * Get the current calling package name. |
| 9655 | * @return the current calling package name |
| 9656 | */ |
| 9657 | @Override |
| 9658 | public String getCurrentPackageName() { |
| 9659 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9660 | } |
| 9661 | |
| 9662 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9663 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9664 | * corresponding network requests on a subId. |
| 9665 | * |
| 9666 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9667 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9668 | * 2) APN is un-metered for this subscription, or |
| 9669 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9670 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9671 | * |
| 9672 | * @return whether data is allowed for a apn type. |
| 9673 | * |
| 9674 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9675 | */ |
| 9676 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9677 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9678 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9679 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9680 | |
| 9681 | // Now that all security checks passes, perform the operation as ourselves. |
| 9682 | final long identity = Binder.clearCallingIdentity(); |
| 9683 | try { |
| 9684 | Phone phone = getPhone(subId); |
| 9685 | if (phone == null) return false; |
| 9686 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9687 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9688 | boolean isDataEnabled; |
| 9689 | if (phone.isUsingNewDataStack()) { |
| 9690 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
| 9691 | } else { |
| 9692 | isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9693 | } |
| 9694 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9695 | } finally { |
| 9696 | Binder.restoreCallingIdentity(identity); |
| 9697 | } |
| 9698 | } |
| 9699 | |
| 9700 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9701 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9702 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9703 | |
| 9704 | // Now that all security checks passes, perform the operation as ourselves. |
| 9705 | final long identity = Binder.clearCallingIdentity(); |
| 9706 | try { |
| 9707 | Phone phone = getPhone(subId); |
| 9708 | if (phone == null) return true; // By default return true. |
| 9709 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9710 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9711 | } finally { |
| 9712 | Binder.restoreCallingIdentity(identity); |
| 9713 | } |
| 9714 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9715 | |
| 9716 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9717 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9718 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9719 | enforceModifyPermission(); |
| 9720 | long token = Binder.clearCallingIdentity(); |
| 9721 | try { |
| 9722 | Phone phone = getPhone(subscriptionId); |
| 9723 | if (phone == null) { |
| 9724 | try { |
| 9725 | if (resultCallback != null) { |
| 9726 | resultCallback.accept(false); |
| 9727 | } |
| 9728 | } catch (RemoteException e) { |
| 9729 | // ignore |
| 9730 | } |
| 9731 | return; |
| 9732 | } |
| 9733 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9734 | Pair.create(specifiers, (x) -> { |
| 9735 | try { |
| 9736 | if (resultCallback != null) { |
| 9737 | resultCallback.accept(x); |
| 9738 | } |
| 9739 | } catch (RemoteException e) { |
| 9740 | // ignore |
| 9741 | } |
| 9742 | }); |
| 9743 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9744 | } finally { |
| 9745 | Binder.restoreCallingIdentity(token); |
| 9746 | } |
| 9747 | } |
| 9748 | |
| 9749 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9750 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9751 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9752 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9753 | mApp, subId, "getSystemSelectionChannels"); |
| 9754 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9755 | final long identity = Binder.clearCallingIdentity(); |
| 9756 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 9757 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 9758 | if (result instanceof IllegalStateException) { |
| 9759 | throw (IllegalStateException) result; |
| 9760 | } |
| 9761 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9762 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9763 | return specifiers; |
| 9764 | } finally { |
| 9765 | Binder.restoreCallingIdentity(identity); |
| 9766 | } |
| 9767 | } |
| 9768 | |
| 9769 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9770 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9771 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9772 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9773 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9774 | if (iccRecords == null) { |
| 9775 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9776 | return false; |
| 9777 | } |
| 9778 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9779 | } |
| 9780 | |
| 9781 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9782 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9783 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9784 | if (callingPackage == null) { |
| 9785 | callingPackage = getCurrentPackageName(); |
| 9786 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9787 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9788 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9789 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9790 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9791 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9792 | } |
| 9793 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9794 | Intent intent = new Intent(); |
| 9795 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9796 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9797 | // Bring up choose default SMS subscription dialog right now |
| 9798 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9799 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9800 | mApp.startActivity(intent); |
| 9801 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9802 | |
| 9803 | @Override |
| 9804 | public String getMmsUAProfUrl(int subId) { |
| 9805 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9806 | final long identity = Binder.clearCallingIdentity(); |
| 9807 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9808 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9809 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9810 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9811 | return carrierUAProfUrl; |
| 9812 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9813 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9814 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9815 | } finally { |
| 9816 | Binder.restoreCallingIdentity(identity); |
| 9817 | } |
| 9818 | } |
| 9819 | |
| 9820 | @Override |
| 9821 | public String getMmsUserAgent(int subId) { |
| 9822 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9823 | final long identity = Binder.clearCallingIdentity(); |
| 9824 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9825 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9826 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9827 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9828 | return carrierUserAgent; |
| 9829 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9830 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9831 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9832 | } finally { |
| 9833 | Binder.restoreCallingIdentity(identity); |
| 9834 | } |
| 9835 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9836 | |
| 9837 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9838 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9839 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9840 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9841 | final long identity = Binder.clearCallingIdentity(); |
| 9842 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9843 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9844 | if (phone == null) return false; |
| 9845 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9846 | switch (policy) { |
| 9847 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9848 | if (phone.isUsingNewDataStack()) { |
| 9849 | return phone.getDataSettingsManager().isDataAllowedInVoiceCall(); |
| 9850 | } else { |
| 9851 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9852 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9853 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9854 | if (phone.isUsingNewDataStack()) { |
| 9855 | return phone.getDataSettingsManager().isMmsAlwaysAllowed(); |
| 9856 | } else { |
| 9857 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9858 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9859 | default: |
| 9860 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9861 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9862 | } finally { |
| 9863 | Binder.restoreCallingIdentity(identity); |
| 9864 | } |
| 9865 | } |
| 9866 | |
| 9867 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9868 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9869 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9870 | enforceModifyPermission(); |
| 9871 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9872 | final long identity = Binder.clearCallingIdentity(); |
| 9873 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9874 | Phone phone = getPhone(subscriptionId); |
| 9875 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9876 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9877 | switch (policy) { |
| 9878 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9879 | if (phone.isUsingNewDataStack()) { |
| 9880 | phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled); |
| 9881 | } else { |
| 9882 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9883 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9884 | break; |
| 9885 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9886 | if (phone.isUsingNewDataStack()) { |
| 9887 | phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled); |
| 9888 | } else { |
| 9889 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9890 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9891 | break; |
| 9892 | default: |
| 9893 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9894 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9895 | } finally { |
| 9896 | Binder.restoreCallingIdentity(identity); |
| 9897 | } |
| 9898 | } |
| 9899 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9900 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9901 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9902 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9903 | * otherwise. |
| 9904 | */ |
| 9905 | @Override |
| 9906 | public void setCepEnabled(boolean isCepEnabled) { |
| 9907 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9908 | |
| 9909 | final long identity = Binder.clearCallingIdentity(); |
| 9910 | try { |
| 9911 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9912 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9913 | Phone defaultPhone = phone.getImsPhone(); |
| 9914 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9915 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9916 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9917 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9918 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9919 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9920 | + imsPhone.getMsisdn()); |
| 9921 | } |
| 9922 | } |
| 9923 | } finally { |
| 9924 | Binder.restoreCallingIdentity(identity); |
| 9925 | } |
| 9926 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9927 | |
| 9928 | /** |
| 9929 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9930 | * |
| 9931 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9932 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9933 | * before being read. |
| 9934 | */ |
| 9935 | @Override |
| 9936 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9937 | isCompressed) { |
| 9938 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9939 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9940 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9941 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9942 | } |
| 9943 | if (!isImsAvailableOnDevice()) { |
| 9944 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9945 | "IMS not available on device."); |
| 9946 | } |
| 9947 | |
| 9948 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9949 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9950 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9951 | } finally { |
| 9952 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9953 | } |
| 9954 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9955 | |
| 9956 | @Override |
| 9957 | public boolean isIccLockEnabled(int subId) { |
| 9958 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9959 | |
| 9960 | // Now that all security checks passes, perform the operation as ourselves. |
| 9961 | final long identity = Binder.clearCallingIdentity(); |
| 9962 | try { |
| 9963 | Phone phone = getPhone(subId); |
| 9964 | if (phone != null && phone.getIccCard() != null) { |
| 9965 | return phone.getIccCard().getIccLockEnabled(); |
| 9966 | } else { |
| 9967 | return false; |
| 9968 | } |
| 9969 | } finally { |
| 9970 | Binder.restoreCallingIdentity(identity); |
| 9971 | } |
| 9972 | } |
| 9973 | |
| 9974 | /** |
| 9975 | * Set the ICC pin lock enabled or disabled. |
| 9976 | * |
| 9977 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9978 | * three cases: |
| 9979 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9980 | * successfully. |
| 9981 | * - Positive number and zero for remaining password attempts. |
| 9982 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9983 | * |
| 9984 | */ |
| 9985 | @Override |
| 9986 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9987 | enforceModifyPermission(); |
| 9988 | |
| 9989 | Phone phone = getPhone(subId); |
| 9990 | if (phone == null) { |
| 9991 | return 0; |
| 9992 | } |
| 9993 | // Now that all security checks passes, perform the operation as ourselves. |
| 9994 | final long identity = Binder.clearCallingIdentity(); |
| 9995 | try { |
| 9996 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9997 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9998 | return attemptsRemaining; |
| 9999 | |
| 10000 | } catch (Exception e) { |
| 10001 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10002 | } finally { |
| 10003 | Binder.restoreCallingIdentity(identity); |
| 10004 | } |
| 10005 | return 0; |
| 10006 | } |
| 10007 | |
| 10008 | /** |
| 10009 | * Change the ICC password used in ICC pin lock. |
| 10010 | * |
| 10011 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10012 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10013 | * - Positive number and zero for remaining password attempts. |
| 10014 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10015 | * |
| 10016 | */ |
| 10017 | @Override |
| 10018 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10019 | enforceModifyPermission(); |
| 10020 | |
| 10021 | Phone phone = getPhone(subId); |
| 10022 | if (phone == null) { |
| 10023 | return 0; |
| 10024 | } |
| 10025 | // Now that all security checks passes, perform the operation as ourselves. |
| 10026 | final long identity = Binder.clearCallingIdentity(); |
| 10027 | try { |
| 10028 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10029 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10030 | return attemptsRemaining; |
| 10031 | |
| 10032 | } catch (Exception e) { |
| 10033 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10034 | } finally { |
| 10035 | Binder.restoreCallingIdentity(identity); |
| 10036 | } |
| 10037 | return 0; |
| 10038 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10039 | |
| 10040 | /** |
| 10041 | * Request for receiving user activity notification |
| 10042 | */ |
| 10043 | @Override |
| 10044 | public void requestUserActivityNotification() { |
| 10045 | if (!mNotifyUserActivity.get() |
| 10046 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10047 | mNotifyUserActivity.set(true); |
| 10048 | } |
| 10049 | } |
| 10050 | |
| 10051 | /** |
| 10052 | * Called when userActivity is signalled in the power manager. |
| 10053 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10054 | */ |
| 10055 | @Override |
| 10056 | public void userActivity() { |
| 10057 | // *************************************** |
| 10058 | // * Inherited from PhoneWindowManager * |
| 10059 | // *************************************** |
| 10060 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10061 | // WITH ITS LOCKS HELD. |
| 10062 | // |
| 10063 | // This code must be VERY careful about the locks |
| 10064 | // it acquires. |
| 10065 | // In fact, the current code acquires way too many, |
| 10066 | // and probably has lurking deadlocks. |
| 10067 | |
| 10068 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10069 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10070 | } |
| 10071 | |
| 10072 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10073 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10074 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10075 | } |
| 10076 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10077 | |
| 10078 | @Override |
| 10079 | public boolean canConnectTo5GInDsdsMode() { |
| 10080 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10081 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10082 | |
| 10083 | @Override |
| 10084 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10085 | String callingFeatureId) { |
| 10086 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10087 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10088 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10089 | } |
| 10090 | |
| 10091 | Phone phone = getPhone(subId); |
| 10092 | if (phone == null) { |
| 10093 | throw new RuntimeException("phone is not available"); |
| 10094 | } |
| 10095 | // Now that all security checks passes, perform the operation as ourselves. |
| 10096 | final long identity = Binder.clearCallingIdentity(); |
| 10097 | try { |
| 10098 | return phone.getEquivalentHomePlmns(); |
| 10099 | } finally { |
| 10100 | Binder.restoreCallingIdentity(identity); |
| 10101 | } |
| 10102 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10103 | |
| 10104 | @Override |
| 10105 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10106 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10107 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10108 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10109 | if (radioInterfaceCapabilities == null) { |
| 10110 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10111 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10112 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10113 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10114 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10115 | @Override |
| 10116 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10117 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10118 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10119 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10120 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10121 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10122 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10123 | if (DBG) { |
| 10124 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10125 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10126 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10127 | } |
| 10128 | |
| 10129 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10130 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10131 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10132 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10133 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10134 | if (callback != null) { |
| 10135 | try { |
| 10136 | callback.onAuthenticationFailure( |
| 10137 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10138 | } catch (RemoteException exception) { |
| 10139 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10140 | } |
| 10141 | return; |
| 10142 | } |
| 10143 | } |
| 10144 | |
| 10145 | final long token = Binder.clearCallingIdentity(); |
| 10146 | try { |
| 10147 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10148 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 10149 | forceBootStrapping, callback)); |
| 10150 | } finally { |
| 10151 | Binder.restoreCallingIdentity(token); |
| 10152 | } |
| 10153 | } |
| 10154 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10155 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10156 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10157 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10158 | * requested radio power state will actually be set. See {@link |
| 10159 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10160 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10161 | * @param enable {@code true} if trying to turn radio on. |
| 10162 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10163 | * false}. |
| 10164 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10165 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10166 | boolean isPhoneAvailable = false; |
| 10167 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10168 | Phone phone = PhoneFactory.getPhone(i); |
| 10169 | if (phone != null) { |
| 10170 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 10171 | isPhoneAvailable = true; |
| 10172 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10173 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10174 | |
| 10175 | // return true if successfully informed the phone object about the thermal radio power |
| 10176 | // request. |
| 10177 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10178 | } |
| 10179 | |
| 10180 | private int handleDataThrottlingRequest(int subId, |
| 10181 | DataThrottlingRequest dataThrottlingRequest) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10182 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10183 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10184 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10185 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10186 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10187 | } |
| 10188 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10189 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10190 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10191 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10192 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10193 | } |
| 10194 | |
| 10195 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 10196 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10197 | if (isDataThrottlingSupported) { |
| 10198 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10199 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10200 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10201 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10202 | } else if (thermalMitigationResult |
| 10203 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10204 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10205 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10206 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10207 | } |
| 10208 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10209 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10210 | |
| 10211 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10212 | } |
| 10213 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10214 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10215 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10216 | for (String pckg : context.getResources() |
| 10217 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10218 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10219 | } |
| 10220 | } |
| 10221 | |
| 10222 | return sThermalMitigationAllowlistedPackages; |
| 10223 | } |
| 10224 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10225 | private boolean isAnyPhoneInEmergencyState() { |
| 10226 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10227 | if (tm.isInEmergencyCall()) { |
| 10228 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10229 | return true; |
| 10230 | } |
| 10231 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10232 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10233 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10234 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10235 | + phone.isInEcm()); |
| 10236 | return true; |
| 10237 | } |
| 10238 | } |
| 10239 | |
| 10240 | return false; |
| 10241 | } |
| 10242 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10243 | /** |
| 10244 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10245 | * @param packageName name of package to be allowlisted |
| 10246 | * @param context |
| 10247 | */ |
| 10248 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10249 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10250 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10251 | } |
| 10252 | |
| 10253 | /** |
| 10254 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10255 | * @param packageName name of package to remove from allowlist |
| 10256 | * @param context |
| 10257 | */ |
| 10258 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10259 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10260 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10261 | } |
| 10262 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10263 | /** |
| 10264 | * Thermal mitigation request to control functionalities at modem. |
| 10265 | * |
| 10266 | * @param subId the id of the subscription. |
| 10267 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10268 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10269 | * |
| 10270 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10271 | */ |
| 10272 | @Override |
| 10273 | @ThermalMitigationResult |
| 10274 | public int sendThermalMitigationRequest( |
| 10275 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10276 | ThermalMitigationRequest thermalMitigationRequest, |
| 10277 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10278 | enforceModifyPermission(); |
| 10279 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10280 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10281 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10282 | .contains(callingPackage)) { |
| 10283 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10284 | + "calling package: " + callingPackage); |
| 10285 | } |
| 10286 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10287 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10288 | final long identity = Binder.clearCallingIdentity(); |
| 10289 | |
| 10290 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10291 | try { |
| 10292 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10293 | switch (thermalMitigationAction) { |
| 10294 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10295 | thermalMitigationResult = |
| 10296 | handleDataThrottlingRequest(subId, |
| 10297 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 10298 | break; |
| 10299 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10300 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10301 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10302 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10303 | } |
| 10304 | |
| 10305 | // Ensure that radio is on. If not able to power on due to phone being |
| 10306 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10307 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10308 | thermalMitigationResult = |
| 10309 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10310 | break; |
| 10311 | } |
| 10312 | |
| 10313 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 10314 | false); |
| 10315 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10316 | break; |
| 10317 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10318 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10319 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10320 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10321 | } |
| 10322 | |
| 10323 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10324 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10325 | Phone phone = getPhone(subId); |
| 10326 | if (phone == null) { |
| 10327 | thermalMitigationResult = |
| 10328 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10329 | break; |
| 10330 | } |
| 10331 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10332 | TelephonyConnectionService service = |
| 10333 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10334 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10335 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10336 | thermalMitigationResult = |
| 10337 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10338 | break; |
| 10339 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10340 | thermalMitigationResult = |
| 10341 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10342 | break; |
| 10343 | } |
| 10344 | } else { |
| 10345 | thermalMitigationResult = |
| 10346 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10347 | break; |
| 10348 | } |
| 10349 | |
| 10350 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10351 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10352 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10353 | thermalMitigationResult = |
| 10354 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10355 | break; |
| 10356 | } |
| 10357 | thermalMitigationResult = |
| 10358 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10359 | break; |
| 10360 | default: |
| 10361 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10362 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10363 | } |
| 10364 | } catch (IllegalArgumentException e) { |
| 10365 | throw e; |
| 10366 | } catch (Exception e) { |
| 10367 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10368 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10369 | } finally { |
| 10370 | Binder.restoreCallingIdentity(identity); |
| 10371 | } |
| 10372 | |
| 10373 | if (DBG) { |
| 10374 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10375 | + thermalMitigationResult); |
| 10376 | } |
| 10377 | |
| 10378 | return thermalMitigationResult; |
| 10379 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10380 | |
| 10381 | /** |
| 10382 | * Set the GbaService Package Name that Telephony will bind to. |
| 10383 | * |
| 10384 | * @param subId The sim that the GbaService is associated with. |
| 10385 | * @param packageName The name of the package to be replaced with. |
| 10386 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10387 | */ |
| 10388 | @Override |
| 10389 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10390 | enforceModifyPermission(); |
| 10391 | |
| 10392 | final long identity = Binder.clearCallingIdentity(); |
| 10393 | try { |
| 10394 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10395 | } finally { |
| 10396 | Binder.restoreCallingIdentity(identity); |
| 10397 | } |
| 10398 | } |
| 10399 | |
| 10400 | /** |
| 10401 | * Return the package name of the currently bound GbaService. |
| 10402 | * |
| 10403 | * @param subId The sim that the GbaService is associated with. |
| 10404 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10405 | */ |
| 10406 | @Override |
| 10407 | public String getBoundGbaService(int subId) { |
| 10408 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10409 | |
| 10410 | final long identity = Binder.clearCallingIdentity(); |
| 10411 | try { |
| 10412 | return getGbaManager(subId).getServicePackage(); |
| 10413 | } finally { |
| 10414 | Binder.restoreCallingIdentity(identity); |
| 10415 | } |
| 10416 | } |
| 10417 | |
| 10418 | /** |
| 10419 | * Set the release time for telephony to unbind GbaService. |
| 10420 | * |
| 10421 | * @param subId The sim that the GbaService is associated with. |
| 10422 | * @param interval The release time to unbind GbaService by millisecond. |
| 10423 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10424 | */ |
| 10425 | @Override |
| 10426 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10427 | enforceModifyPermission(); |
| 10428 | |
| 10429 | final long identity = Binder.clearCallingIdentity(); |
| 10430 | try { |
| 10431 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10432 | } finally { |
| 10433 | Binder.restoreCallingIdentity(identity); |
| 10434 | } |
| 10435 | } |
| 10436 | |
| 10437 | /** |
| 10438 | * Return the release time for telephony to unbind GbaService. |
| 10439 | * |
| 10440 | * @param subId The sim that the GbaService is associated with. |
| 10441 | * @return The release time to unbind GbaService by millisecond. |
| 10442 | */ |
| 10443 | @Override |
| 10444 | public int getGbaReleaseTime(int subId) { |
| 10445 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10446 | |
| 10447 | final long identity = Binder.clearCallingIdentity(); |
| 10448 | try { |
| 10449 | return getGbaManager(subId).getReleaseTime(); |
| 10450 | } finally { |
| 10451 | Binder.restoreCallingIdentity(identity); |
| 10452 | } |
| 10453 | } |
| 10454 | |
| 10455 | private GbaManager getGbaManager(int subId) { |
| 10456 | GbaManager instance = GbaManager.getInstance(subId); |
| 10457 | if (instance == null) { |
| 10458 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10459 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10460 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10461 | } |
| 10462 | return instance; |
| 10463 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10464 | |
| 10465 | /** |
| 10466 | * indicate whether the device and the carrier can support |
| 10467 | * RCS VoLTE single registration. |
| 10468 | */ |
| 10469 | @Override |
| 10470 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10471 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10472 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10473 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10474 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10475 | |
| 10476 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10477 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10478 | } |
| 10479 | |
| 10480 | final long identity = Binder.clearCallingIdentity(); |
| 10481 | try { |
| 10482 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10483 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10484 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10485 | if (isCapable != null) { |
| 10486 | return isCapable; |
| 10487 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10488 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10489 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10490 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10491 | } finally { |
| 10492 | Binder.restoreCallingIdentity(identity); |
| 10493 | } |
| 10494 | } |
| 10495 | |
| 10496 | /** |
| 10497 | * Register RCS provisioning callback. |
| 10498 | */ |
| 10499 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10500 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10501 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10502 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10503 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10504 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10505 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10506 | |
| 10507 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10508 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10509 | } |
| 10510 | if (!isImsAvailableOnDevice()) { |
| 10511 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10512 | "IMS not available on device."); |
| 10513 | } |
| 10514 | |
| 10515 | final long identity = Binder.clearCallingIdentity(); |
| 10516 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10517 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10518 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10519 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10520 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10521 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10522 | } finally { |
| 10523 | Binder.restoreCallingIdentity(identity); |
| 10524 | } |
| 10525 | } |
| 10526 | |
| 10527 | /** |
| 10528 | * Unregister RCS provisioning callback. |
| 10529 | */ |
| 10530 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10531 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10532 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10533 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10534 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10535 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10536 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10537 | |
| 10538 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10539 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10540 | } |
| 10541 | if (!isImsAvailableOnDevice()) { |
| 10542 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10543 | "IMS not available on device."); |
| 10544 | } |
| 10545 | |
| 10546 | final long identity = Binder.clearCallingIdentity(); |
| 10547 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10548 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10549 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10550 | } finally { |
| 10551 | Binder.restoreCallingIdentity(identity); |
| 10552 | } |
| 10553 | } |
| 10554 | |
| 10555 | /** |
| 10556 | * trigger RCS reconfiguration. |
| 10557 | */ |
| 10558 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10559 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10560 | "triggerRcsReconfiguration", |
| 10561 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10562 | |
| 10563 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10564 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10565 | } |
| 10566 | if (!isImsAvailableOnDevice()) { |
| 10567 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10568 | "IMS not available on device."); |
| 10569 | } |
| 10570 | |
| 10571 | final long identity = Binder.clearCallingIdentity(); |
| 10572 | try { |
| 10573 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10574 | } finally { |
| 10575 | Binder.restoreCallingIdentity(identity); |
| 10576 | } |
| 10577 | } |
| 10578 | |
| 10579 | /** |
| 10580 | * Provide the client configuration parameters of the RCS application. |
| 10581 | */ |
| 10582 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10583 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10584 | "setRcsClientConfiguration", |
| 10585 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10586 | |
| 10587 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10588 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10589 | } |
| 10590 | if (!isImsAvailableOnDevice()) { |
| 10591 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10592 | "IMS not available on device."); |
| 10593 | } |
| 10594 | |
| 10595 | final long identity = Binder.clearCallingIdentity(); |
| 10596 | |
| 10597 | try { |
| 10598 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10599 | if (configBinder == null) { |
| 10600 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10601 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10602 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10603 | } else { |
| 10604 | configBinder.setRcsClientConfiguration(rcc); |
| 10605 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 10606 | |
| 10607 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 10608 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10609 | } catch (RemoteException e) { |
| 10610 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10611 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10612 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10613 | } finally { |
| 10614 | Binder.restoreCallingIdentity(identity); |
| 10615 | } |
| 10616 | } |
| 10617 | |
| 10618 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10619 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10620 | */ |
| 10621 | @Override |
| 10622 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10623 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10624 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10625 | |
| 10626 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10627 | } |
| 10628 | |
| 10629 | /** |
| 10630 | * Gets the test mode for RCS VoLTE single registration. |
| 10631 | */ |
| 10632 | @Override |
| 10633 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10634 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10635 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10636 | |
| 10637 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10638 | } |
| 10639 | |
| 10640 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10641 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10642 | */ |
| 10643 | @Override |
| 10644 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10645 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10646 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10647 | enforceModifyPermission(); |
| 10648 | |
| 10649 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10650 | : Boolean.parseBoolean(enabledStr); |
| 10651 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10652 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10653 | } |
| 10654 | |
| 10655 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10656 | * Sends a device to device communication message. Only usable via shell. |
| 10657 | * @param message message to send. |
| 10658 | * @param value message value. |
| 10659 | */ |
| 10660 | @Override |
| 10661 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10662 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10663 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10664 | enforceModifyPermission(); |
| 10665 | |
| 10666 | final long identity = Binder.clearCallingIdentity(); |
| 10667 | try { |
| 10668 | TelephonyConnectionService service = |
| 10669 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10670 | if (service == null) { |
| 10671 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10672 | return; |
| 10673 | } |
| 10674 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10675 | } finally { |
| 10676 | Binder.restoreCallingIdentity(identity); |
| 10677 | } |
| 10678 | } |
| 10679 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10680 | /** |
| 10681 | * Sets the specified device to device transport active. |
| 10682 | * @param transport The transport to set active. |
| 10683 | */ |
| 10684 | @Override |
| 10685 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10686 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10687 | "setActiveDeviceToDeviceTransport"); |
| 10688 | enforceModifyPermission(); |
| 10689 | |
| 10690 | final long identity = Binder.clearCallingIdentity(); |
| 10691 | try { |
| 10692 | TelephonyConnectionService service = |
| 10693 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10694 | if (service == null) { |
| 10695 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10696 | return; |
| 10697 | } |
| 10698 | service.setActiveDeviceToDeviceTransport(transport); |
| 10699 | } finally { |
| 10700 | Binder.restoreCallingIdentity(identity); |
| 10701 | } |
| 10702 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10703 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10704 | @Override |
| 10705 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10706 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10707 | "setDeviceToDeviceForceEnabled"); |
| 10708 | |
| 10709 | final long identity = Binder.clearCallingIdentity(); |
| 10710 | try { |
| 10711 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10712 | p -> { |
| 10713 | Phone thePhone = p.getImsPhone(); |
| 10714 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10715 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10716 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10717 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10718 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10719 | (ImsPhoneCallTracker) tracker; |
| 10720 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10721 | } |
| 10722 | } |
| 10723 | } |
| 10724 | ); |
| 10725 | } finally { |
| 10726 | Binder.restoreCallingIdentity(identity); |
| 10727 | } |
| 10728 | } |
| 10729 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10730 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10731 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10732 | */ |
| 10733 | @Override |
| 10734 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10735 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10736 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10737 | } |
| 10738 | |
| 10739 | /** |
| 10740 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10741 | */ |
| 10742 | @Override |
| 10743 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10744 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10745 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10746 | enforceModifyPermission(); |
| 10747 | |
| 10748 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10749 | : Boolean.parseBoolean(enabledStr); |
| 10750 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10751 | subId, enabled); |
| 10752 | } |
| 10753 | |
| 10754 | /** |
| 10755 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10756 | */ |
| 10757 | @Override |
| 10758 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10759 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10760 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10761 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10762 | |
| 10763 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 10764 | * Overrides the ims feature validation result |
| 10765 | */ |
| 10766 | @Override |
| 10767 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 10768 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10769 | "setImsFeatureValidationOverride"); |
| 10770 | |
| 10771 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10772 | : Boolean.parseBoolean(enabledStr); |
| 10773 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 10774 | subId, enabled); |
| 10775 | } |
| 10776 | |
| 10777 | /** |
| 10778 | * Gets the ims feature validation override value |
| 10779 | */ |
| 10780 | @Override |
| 10781 | public boolean getImsFeatureValidationOverride(int subId) { |
| 10782 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10783 | "getImsFeatureValidationOverride"); |
| 10784 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 10785 | } |
| 10786 | |
| 10787 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10788 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10789 | * their mobile plan. |
| 10790 | */ |
| 10791 | @Override |
| 10792 | public String getMobileProvisioningUrl() { |
| 10793 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10794 | final long identity = Binder.clearCallingIdentity(); |
| 10795 | try { |
| 10796 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10797 | } finally { |
| 10798 | Binder.restoreCallingIdentity(identity); |
| 10799 | } |
| 10800 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10801 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10802 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10803 | * Get the EAB contact from the EAB database. |
| 10804 | */ |
| 10805 | @Override |
| 10806 | public String getContactFromEab(String contact) { |
| 10807 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10808 | enforceModifyPermission(); |
| 10809 | final long identity = Binder.clearCallingIdentity(); |
| 10810 | try { |
| 10811 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10812 | } finally { |
| 10813 | Binder.restoreCallingIdentity(identity); |
| 10814 | } |
| 10815 | } |
| 10816 | |
| 10817 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 10818 | * Get the EAB capability from the EAB database. |
| 10819 | */ |
| 10820 | @Override |
| 10821 | public String getCapabilityFromEab(String contact) { |
| 10822 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 10823 | enforceModifyPermission(); |
| 10824 | final long identity = Binder.clearCallingIdentity(); |
| 10825 | try { |
| 10826 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 10827 | } finally { |
| 10828 | Binder.restoreCallingIdentity(identity); |
| 10829 | } |
| 10830 | } |
| 10831 | |
| 10832 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10833 | * Remove the EAB contacts from the EAB database. |
| 10834 | */ |
| 10835 | @Override |
| 10836 | public int removeContactFromEab(int subId, String contacts) { |
| 10837 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10838 | enforceModifyPermission(); |
| 10839 | final long identity = Binder.clearCallingIdentity(); |
| 10840 | try { |
| 10841 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10842 | } finally { |
| 10843 | Binder.restoreCallingIdentity(identity); |
| 10844 | } |
| 10845 | } |
| 10846 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10847 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10848 | public boolean getDeviceUceEnabled() { |
| 10849 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10850 | final long identity = Binder.clearCallingIdentity(); |
| 10851 | try { |
| 10852 | return mApp.getDeviceUceEnabled(); |
| 10853 | } finally { |
| 10854 | Binder.restoreCallingIdentity(identity); |
| 10855 | } |
| 10856 | } |
| 10857 | |
| 10858 | @Override |
| 10859 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10860 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10861 | final long identity = Binder.clearCallingIdentity(); |
| 10862 | try { |
| 10863 | mApp.setDeviceUceEnabled(isEnabled); |
| 10864 | } finally { |
| 10865 | Binder.restoreCallingIdentity(identity); |
| 10866 | } |
| 10867 | } |
| 10868 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10869 | /** |
| 10870 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10871 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10872 | */ |
| 10873 | // Used for SHELL command only right now. |
| 10874 | @Override |
| 10875 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 10876 | List<String> featureTags) { |
| 10877 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10878 | "addUceRegistrationOverrideShell"); |
| 10879 | final long identity = Binder.clearCallingIdentity(); |
| 10880 | try { |
| 10881 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 10882 | new ArraySet<>(featureTags)); |
| 10883 | } catch (ImsException e) { |
| 10884 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10885 | } finally { |
| 10886 | Binder.restoreCallingIdentity(identity); |
| 10887 | } |
| 10888 | } |
| 10889 | |
| 10890 | /** |
| 10891 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10892 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10893 | */ |
| 10894 | // Used for SHELL command only right now. |
| 10895 | @Override |
| 10896 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 10897 | List<String> featureTags) { |
| 10898 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10899 | "removeUceRegistrationOverrideShell"); |
| 10900 | final long identity = Binder.clearCallingIdentity(); |
| 10901 | try { |
| 10902 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 10903 | new ArraySet<>(featureTags)); |
| 10904 | } catch (ImsException e) { |
| 10905 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10906 | } finally { |
| 10907 | Binder.restoreCallingIdentity(identity); |
| 10908 | } |
| 10909 | } |
| 10910 | |
| 10911 | /** |
| 10912 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 10913 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10914 | */ |
| 10915 | // Used for SHELL command only right now. |
| 10916 | @Override |
| 10917 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 10918 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10919 | "clearUceRegistrationOverrideShell"); |
| 10920 | final long identity = Binder.clearCallingIdentity(); |
| 10921 | try { |
| 10922 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 10923 | } catch (ImsException e) { |
| 10924 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10925 | } finally { |
| 10926 | Binder.restoreCallingIdentity(identity); |
| 10927 | } |
| 10928 | } |
| 10929 | |
| 10930 | /** |
| 10931 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10932 | */ |
| 10933 | // Used for SHELL command only right now. |
| 10934 | @Override |
| 10935 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 10936 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10937 | "getLatestRcsContactUceCapabilityShell"); |
| 10938 | final long identity = Binder.clearCallingIdentity(); |
| 10939 | try { |
| 10940 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 10941 | } catch (ImsException e) { |
| 10942 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10943 | } finally { |
| 10944 | Binder.restoreCallingIdentity(identity); |
| 10945 | } |
| 10946 | } |
| 10947 | |
| 10948 | /** |
| 10949 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 10950 | * device does not have an active PUBLISH. |
| 10951 | */ |
| 10952 | // Used for SHELL command only right now. |
| 10953 | @Override |
| 10954 | public String getLastUcePidfXmlShell(int subId) { |
| 10955 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 10956 | final long identity = Binder.clearCallingIdentity(); |
| 10957 | try { |
| 10958 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 10959 | } catch (ImsException e) { |
| 10960 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10961 | } finally { |
| 10962 | Binder.restoreCallingIdentity(identity); |
| 10963 | } |
| 10964 | } |
| 10965 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 10966 | /** |
| 10967 | * Remove UCE requests cannot be sent to the network status. |
| 10968 | */ |
| 10969 | // Used for SHELL command only right now. |
| 10970 | @Override |
| 10971 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 10972 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 10973 | final long identity = Binder.clearCallingIdentity(); |
| 10974 | try { |
| 10975 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 10976 | } catch (ImsException e) { |
| 10977 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10978 | } finally { |
| 10979 | Binder.restoreCallingIdentity(identity); |
| 10980 | } |
| 10981 | } |
| 10982 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 10983 | /** |
| 10984 | * Remove UCE requests cannot be sent to the network status. |
| 10985 | */ |
| 10986 | // Used for SHELL command only. |
| 10987 | @Override |
| 10988 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 10989 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 10990 | final long identity = Binder.clearCallingIdentity(); |
| 10991 | try { |
| 10992 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 10993 | } catch (ImsException e) { |
| 10994 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10995 | } finally { |
| 10996 | Binder.restoreCallingIdentity(identity); |
| 10997 | } |
| 10998 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10999 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11000 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11001 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11002 | String callingPackage) { |
| 11003 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11004 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11005 | |
| 11006 | final int callingUid = Binder.getCallingUid(); |
| 11007 | // Verify that tha callingPackage belongs to the calling UID |
| 11008 | mApp.getSystemService(AppOpsManager.class) |
| 11009 | .checkPackage(callingUid, callingPackage); |
| 11010 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11011 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11012 | |
| 11013 | final long identity = Binder.clearCallingIdentity(); |
| 11014 | try { |
| 11015 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11016 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11017 | |
| 11018 | if (result instanceof IllegalStateException) { |
| 11019 | throw (IllegalStateException) result; |
| 11020 | } |
| 11021 | } finally { |
| 11022 | Binder.restoreCallingIdentity(identity); |
| 11023 | } |
| 11024 | } |
| 11025 | |
| 11026 | @Override |
| 11027 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11028 | String callingPackage) { |
| 11029 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11030 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11031 | |
| 11032 | final int callingUid = Binder.getCallingUid(); |
| 11033 | // Verify that tha callingPackage belongs to the calling UID |
| 11034 | mApp.getSystemService(AppOpsManager.class) |
| 11035 | .checkPackage(callingUid, callingPackage); |
| 11036 | |
| 11037 | final long identity = Binder.clearCallingIdentity(); |
| 11038 | try { |
| 11039 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11040 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11041 | |
| 11042 | if (result instanceof IllegalStateException) { |
| 11043 | throw (IllegalStateException) result; |
| 11044 | } |
| 11045 | } finally { |
| 11046 | Binder.restoreCallingIdentity(identity); |
| 11047 | } |
| 11048 | } |
| 11049 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11050 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11051 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11052 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11053 | // phone/system process do not have further restriction on request |
| 11054 | return; |
| 11055 | } |
| 11056 | |
| 11057 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11058 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11059 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11060 | context.enforceCallingOrSelfPermission( |
| 11061 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11062 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11063 | } |
| 11064 | |
| 11065 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 11066 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 11067 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 11068 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 11069 | || info.isEnabled()) { |
| 11070 | throw new IllegalArgumentException( |
| 11071 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11072 | } |
| 11073 | |
| 11074 | // Thresholds length for each RAN need in range. This has been validated in |
| 11075 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11076 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11077 | final int[] thresholds = info.getThresholds(); |
| 11078 | Objects.requireNonNull(thresholds); |
| 11079 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11080 | || thresholds.length |
| 11081 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11082 | throw new IllegalArgumentException( |
| 11083 | "thresholds length is out of range: " + thresholds.length); |
| 11084 | } |
| 11085 | } |
| 11086 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11087 | |
| 11088 | /** |
| 11089 | * Gets the current phone capability. |
| 11090 | * |
| 11091 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11092 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11093 | * It's used to evaluate possible phone config change, for example from single |
| 11094 | * SIM device to multi-SIM device. |
| 11095 | */ |
| 11096 | @Override |
| 11097 | public PhoneCapability getPhoneCapability() { |
| 11098 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11099 | final long identity = Binder.clearCallingIdentity(); |
| 11100 | try { |
| 11101 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11102 | } finally { |
| 11103 | Binder.restoreCallingIdentity(identity); |
| 11104 | } |
| 11105 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11106 | |
| 11107 | /** |
| 11108 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11109 | * required to be done shortly after the API is invoked. |
| 11110 | */ |
| 11111 | @Override |
| 11112 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11113 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11114 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11115 | enforceRebootPermission(); |
| 11116 | |
| 11117 | final long identity = Binder.clearCallingIdentity(); |
| 11118 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11119 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11120 | } finally { |
| 11121 | Binder.restoreCallingIdentity(identity); |
| 11122 | } |
| 11123 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11124 | |
| 11125 | /** |
| 11126 | * Request to get the current slicing configuration including URSP rules and |
| 11127 | * NSSAIs (configured, allowed and rejected). |
| 11128 | * |
| 11129 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11130 | */ |
| 11131 | @Override |
| 11132 | public void getSlicingConfig(ResultReceiver callback) { |
| 11133 | enforceReadPrivilegedPermission("getSlicingConfig"); |
| 11134 | |
| 11135 | final long identity = Binder.clearCallingIdentity(); |
| 11136 | try { |
| 11137 | Phone phone = getDefaultPhone(); |
| 11138 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11139 | } finally { |
| 11140 | Binder.restoreCallingIdentity(identity); |
| 11141 | } |
| 11142 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11143 | |
| 11144 | /** |
| 11145 | * Register an IMS connection state callback |
| 11146 | */ |
| 11147 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11148 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11149 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11150 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11151 | // ImsMmTelManager |
| 11152 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11153 | TelephonyPermissions |
| 11154 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11155 | mApp, subId, "registerImsStateCallback"); |
| 11156 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11157 | // ImsRcsManager or SipDelegateManager |
| 11158 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11159 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11160 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11161 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11162 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11163 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11164 | } |
| 11165 | |
| 11166 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11167 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11168 | "IMS not available on device."); |
| 11169 | } |
| 11170 | |
| 11171 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11172 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11173 | } |
| 11174 | |
| 11175 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11176 | if (controller == null) { |
| 11177 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11178 | "IMS not available on device."); |
| 11179 | } |
| 11180 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11181 | if (callingPackage == null) { |
| 11182 | callingPackage = getCurrentPackageName(); |
| 11183 | } |
| 11184 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11185 | final long token = Binder.clearCallingIdentity(); |
| 11186 | try { |
| 11187 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11188 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11189 | } catch (ImsException e) { |
| 11190 | throw new ServiceSpecificException(e.getCode()); |
| 11191 | } finally { |
| 11192 | Binder.restoreCallingIdentity(token); |
| 11193 | } |
| 11194 | } |
| 11195 | |
| 11196 | /** |
| 11197 | * Unregister an IMS connection state callback |
| 11198 | */ |
| 11199 | @Override |
| 11200 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11201 | final long token = Binder.clearCallingIdentity(); |
| 11202 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11203 | if (controller == null) { |
| 11204 | return; |
| 11205 | } |
| 11206 | try { |
| 11207 | controller.unregisterImsStateCallback(cb); |
| 11208 | } finally { |
| 11209 | Binder.restoreCallingIdentity(token); |
| 11210 | } |
| 11211 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11212 | |
| 11213 | /** |
| 11214 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11215 | * |
| 11216 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11217 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11218 | * SecurityException. |
| 11219 | * If there is current registered network this value will be same as the registered cell |
| 11220 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11221 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11222 | * it will be cleared and null will be returned. |
| 11223 | * |
| 11224 | */ |
| 11225 | @Override |
| 11226 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11227 | String callingFeatureId) { |
| 11228 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11229 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11230 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11231 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11232 | .setCallingPackage(callingPackage) |
| 11233 | .setCallingFeatureId(callingFeatureId) |
| 11234 | .setCallingPid(Binder.getCallingPid()) |
| 11235 | .setCallingUid(Binder.getCallingUid()) |
| 11236 | .setMethod("getLastKnownCellIdentity") |
| 11237 | .setLogAsInfo(true) |
| 11238 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11239 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11240 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11241 | .build()); |
| 11242 | |
| 11243 | boolean hasFinePermission = |
| 11244 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11245 | if (!hasFinePermission |
| 11246 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11247 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
| 11248 | + "and BIND_CONNECTION_SERVICE permission."); |
| 11249 | } |
| 11250 | |
| 11251 | final long identity = Binder.clearCallingIdentity(); |
| 11252 | try { |
| 11253 | Phone phone = getPhone(subId); |
| 11254 | if (phone == null) return null; |
| 11255 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 11256 | if (sst == null) return null; |
| 11257 | return sst.getLastKnownCellIdentity(); |
| 11258 | } finally { |
| 11259 | Binder.restoreCallingIdentity(identity); |
| 11260 | } |
| 11261 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11262 | |
| 11263 | @Override |
| 11264 | public boolean isUsingNewDataStack() { |
| 11265 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack"); |
| 11266 | return getDefaultPhone().isUsingNewDataStack(); |
| 11267 | } |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11268 | |
| 11269 | /** |
| 11270 | * Sets the modem service class Name that Telephony will bind to. |
| 11271 | * |
| 11272 | * @param serviceName The class name of the modem service. |
| 11273 | * @return true if the operation is succeed, otherwise false. |
| 11274 | */ |
| 11275 | public boolean setModemService(String serviceName) { |
| 11276 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11277 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11278 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 11279 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11280 | "setModemService"); |
| 11281 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11282 | } |
| 11283 | |
| 11284 | /** |
| 11285 | * Return the class name of the currently bounded modem service. |
| 11286 | * |
| 11287 | * @return the class name of the modem service. |
| 11288 | */ |
| 11289 | public String getModemService() { |
| 11290 | String result; |
| 11291 | Log.d(LOG_TAG, "getModemService"); |
| 11292 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11293 | TelephonyPermissions |
| 11294 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11295 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11296 | "getModemService"); |
| 11297 | result = mPhoneConfigurationManager.getModemService(); |
| 11298 | Log.d(LOG_TAG, "result = " + result); |
| 11299 | return result; |
| 11300 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 11301 | } |