Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| 20 | |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 22 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 23 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 24 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 25 | import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 26 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 27 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 28 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 29 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 30 | import android.annotation.Nullable; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 31 | import android.annotation.RequiresPermission; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 32 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 33 | import android.app.PendingIntent; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 34 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 35 | import android.app.role.RoleManager; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 36 | import android.compat.annotation.ChangeId; |
| 37 | import android.compat.annotation.EnabledSince; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 38 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 39 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 40 | import android.content.Context; |
| 41 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 42 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 43 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 44 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 45 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 46 | import android.net.Uri; |
| 47 | import android.os.AsyncResult; |
| 48 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 49 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 50 | import android.os.Bundle; |
| 51 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 52 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import android.os.Looper; |
| 54 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 55 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 56 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 57 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 58 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 59 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 60 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 61 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 62 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 63 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 64 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 65 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 66 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 67 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 68 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 69 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 70 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 71 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 72 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 73 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 74 | import android.telecom.TelecomManager; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 75 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 76 | import android.telephony.Annotation.ThermalMitigationResult; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 77 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 78 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 79 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 80 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 81 | import android.telephony.CellIdentityCdma; |
| 82 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 83 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 84 | import android.telephony.CellInfoGsm; |
| 85 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 86 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 87 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 88 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 89 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 90 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 91 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 92 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 93 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 94 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 95 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 96 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 97 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 98 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 99 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 100 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 101 | import android.telephony.SignalStrengthUpdateRequest; |
| 102 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 103 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 104 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 105 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 106 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 107 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 108 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 109 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 110 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 111 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 112 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 113 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 114 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 115 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 116 | import android.telephony.data.ApnSetting; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 117 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 118 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 119 | import android.telephony.gba.GbaAuthRequest; |
| 120 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 121 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 122 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 123 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 124 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 125 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 126 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 127 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 128 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 129 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 130 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 131 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 132 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 133 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 134 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 135 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 136 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 137 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 138 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 139 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 140 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 141 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 142 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 143 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 144 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 145 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 146 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 147 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.CallTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 157 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 161 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 163 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 165 | import com.android.internal.telephony.IccCard; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 172 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 177 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 178 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 179 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 181 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 182 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 183 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 184 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 185 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 186 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 187 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 188 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 189 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 190 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 191 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 192 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 193 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 194 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 195 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 196 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 197 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 198 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 199 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 200 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 201 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 202 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 203 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 204 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 205 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 206 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 207 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 208 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 209 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 210 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 211 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 212 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 213 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 214 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 215 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 216 | import com.android.services.telephony.TelecomAccountRegistry; |
| 217 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 218 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 219 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 220 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 221 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 222 | import java.io.IOException; |
| 223 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 224 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 225 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 226 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 227 | import java.util.Collection; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 228 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 229 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 230 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 231 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 232 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 233 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 234 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 235 | import java.util.Set; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 236 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 237 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 238 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 239 | |
| 240 | /** |
| 241 | * Implementation of the ITelephony interface. |
| 242 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 243 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 244 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 245 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 246 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 247 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 248 | |
| 249 | // Message codes used with mMainThreadHandler |
| 250 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 251 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 252 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 253 | private static final int CMD_OPEN_CHANNEL = 9; |
| 254 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 255 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 256 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 257 | private static final int CMD_NV_READ_ITEM = 13; |
| 258 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 259 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 260 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 261 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 262 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 263 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 264 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 265 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 266 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 267 | private static final int CMD_SEND_ENVELOPE = 25; |
| 268 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 269 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 270 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 271 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 272 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 273 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 274 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 275 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 276 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 277 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 278 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 279 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 280 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 281 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 282 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 283 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 284 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 285 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 286 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 287 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 288 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 289 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 290 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 291 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 292 | private static final int CMD_SWITCH_SLOTS = 50; |
| 293 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 294 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 295 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 296 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 297 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 298 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 299 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 300 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 301 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 302 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 303 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 304 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 305 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 306 | private static final int CMD_MODEM_REBOOT = 64; |
| 307 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 308 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 309 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 310 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 311 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 312 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 313 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 314 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 315 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 316 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 317 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 318 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 319 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 320 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 321 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 322 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 323 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 324 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 325 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 326 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 327 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 328 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 329 | private static final int CMD_GET_CALL_WAITING = 87; |
| 330 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 331 | private static final int CMD_SET_CALL_WAITING = 89; |
| 332 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 333 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 334 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 335 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 336 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 337 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 338 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 339 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 340 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 341 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 342 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 343 | private static final int CMD_SET_SIM_POWER = 101; |
| 344 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 345 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 346 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 347 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 348 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 349 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 350 | 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] | 351 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 352 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 353 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 354 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 355 | private static final int CMD_ENABLE_VONR = 113; |
| 356 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 357 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 358 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 359 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 360 | // Parameters of select command. |
| 361 | private static final int SELECT_COMMAND = 0xA4; |
| 362 | private static final int SELECT_P1 = 0x04; |
| 363 | private static final int SELECT_P2 = 0; |
| 364 | private static final int SELECT_P3 = 0x10; |
| 365 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 366 | /** The singleton instance. */ |
| 367 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 368 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 369 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 370 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 371 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 372 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 373 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 374 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 375 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 376 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 377 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 378 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 379 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 380 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 381 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 382 | /** User Activity */ |
| 383 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 384 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 385 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 386 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 387 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 388 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 389 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 390 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 391 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 392 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 393 | // String to store multi SIM allowed |
| 394 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 395 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 396 | // The AID of ISD-R. |
| 397 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 398 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 399 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 400 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 401 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 402 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 403 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 404 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 405 | 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] | 406 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 407 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 408 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 409 | */ |
| 410 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 411 | "reset_network_erase_modem_config_enabled"; |
| 412 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 413 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 414 | /** |
| 415 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 416 | * one ICCID active at the same time. |
| 417 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 418 | * |
| 419 | * @hide |
| 420 | */ |
| 421 | @ChangeId |
| 422 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 423 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 424 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 425 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 426 | * A request object to use for transmitting data to an ICC. |
| 427 | */ |
| 428 | private static final class IccAPDUArgument { |
| 429 | public int channel, cla, command, p1, p2, p3; |
| 430 | public String data; |
| 431 | |
| 432 | public IccAPDUArgument(int channel, int cla, int command, |
| 433 | int p1, int p2, int p3, String data) { |
| 434 | this.channel = channel; |
| 435 | this.cla = cla; |
| 436 | this.command = command; |
| 437 | this.p1 = p1; |
| 438 | this.p2 = p2; |
| 439 | this.p3 = p3; |
| 440 | this.data = data; |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 445 | * A request object to use for transmitting data to an ICC. |
| 446 | */ |
| 447 | private static final class ManualNetworkSelectionArgument { |
| 448 | public OperatorInfo operatorInfo; |
| 449 | public boolean persistSelection; |
| 450 | |
| 451 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 452 | this.operatorInfo = operatorInfo; |
| 453 | this.persistSelection = persistSelection; |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 458 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 459 | * request after sending. The main thread will notify the request when it is complete. |
| 460 | */ |
| 461 | private static final class MainThreadRequest { |
| 462 | /** The argument to use for the request */ |
| 463 | public Object argument; |
| 464 | /** The result of the request that is run on the main thread */ |
| 465 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 466 | // The subscriber id that this request applies to. Defaults to |
| 467 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 468 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 469 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 470 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 471 | public Phone phone; |
| 472 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 473 | public WorkSource workSource; |
| 474 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 475 | public MainThreadRequest(Object argument) { |
| 476 | this.argument = argument; |
| 477 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 478 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 479 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 480 | this.argument = argument; |
| 481 | if (phone != null) { |
| 482 | this.phone = phone; |
| 483 | } |
| 484 | this.workSource = workSource; |
| 485 | } |
| 486 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 487 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 488 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 489 | if (subId != null) { |
| 490 | this.subId = subId; |
| 491 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 492 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 493 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 496 | private static final class IncomingThirdPartyCallArgs { |
| 497 | public final ComponentName component; |
| 498 | public final String callId; |
| 499 | public final String callerDisplayName; |
| 500 | |
| 501 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 502 | String callerDisplayName) { |
| 503 | this.component = component; |
| 504 | this.callId = callId; |
| 505 | this.callerDisplayName = callerDisplayName; |
| 506 | } |
| 507 | } |
| 508 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 509 | /** |
| 510 | * A handler that processes messages on the main thread in the phone process. Since many |
| 511 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 512 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 513 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 514 | * on, which will be notified when the operation completes and will contain the result of the |
| 515 | * request. |
| 516 | * |
| 517 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 518 | * note that request.result must be set to something non-null for the calling thread to |
| 519 | * unblock. |
| 520 | */ |
| 521 | private final class MainThreadHandler extends Handler { |
| 522 | @Override |
| 523 | public void handleMessage(Message msg) { |
| 524 | MainThreadRequest request; |
| 525 | Message onCompleted; |
| 526 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 527 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 528 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 529 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 530 | |
| 531 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 532 | case CMD_HANDLE_USSD_REQUEST: { |
| 533 | request = (MainThreadRequest) msg.obj; |
| 534 | final Phone phone = getPhoneFromRequest(request); |
| 535 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 536 | String ussdRequest = ussdObject.first; |
| 537 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 538 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 539 | if (!isUssdApiAllowed(request.subId)) { |
| 540 | // Carrier does not support use of this API, return failure. |
| 541 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 542 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 543 | Bundle returnData = new Bundle(); |
| 544 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 545 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 546 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 547 | request.result = true; |
| 548 | notifyRequester(request); |
| 549 | return; |
| 550 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 551 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 552 | try { |
| 553 | request.result = phone != null |
| 554 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 555 | } catch (CallStateException cse) { |
| 556 | request.result = false; |
| 557 | } |
| 558 | // Wake up the requesting thread |
| 559 | notifyRequester(request); |
| 560 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 561 | } |
| 562 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 563 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 564 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 565 | final Phone phone = getPhoneFromRequest(request); |
| 566 | request.result = phone != null ? |
| 567 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 568 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 569 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 570 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 571 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 572 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 573 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 574 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 575 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 576 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 577 | uiccPort = getUiccPortFromRequest(request); |
| 578 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 579 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 580 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 581 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 582 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 583 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 584 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 585 | uiccPort.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 586 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 587 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 588 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 589 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 590 | break; |
| 591 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 592 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 593 | ar = (AsyncResult) msg.obj; |
| 594 | request = (MainThreadRequest) ar.userObj; |
| 595 | if (ar.exception == null && ar.result != null) { |
| 596 | request.result = ar.result; |
| 597 | } else { |
| 598 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 599 | if (ar.result == null) { |
| 600 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 601 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 602 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 603 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 604 | } else { |
| 605 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 606 | } |
| 607 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 608 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 609 | break; |
| 610 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 611 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 612 | request = (MainThreadRequest) msg.obj; |
| 613 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 614 | uiccPort = getUiccPortFromRequest(request); |
| 615 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 616 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 617 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 618 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 619 | } else { |
| 620 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 621 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 622 | uiccPort.iccTransmitApduBasicChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 623 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 624 | iccArgument.p3, iccArgument.data, onCompleted); |
| 625 | } |
| 626 | break; |
| 627 | |
| 628 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 629 | ar = (AsyncResult) msg.obj; |
| 630 | request = (MainThreadRequest) ar.userObj; |
| 631 | if (ar.exception == null && ar.result != null) { |
| 632 | request.result = ar.result; |
| 633 | } else { |
| 634 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 635 | if (ar.result == null) { |
| 636 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 637 | } else if (ar.exception instanceof CommandException) { |
| 638 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 639 | ar.exception); |
| 640 | } else { |
| 641 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 642 | } |
| 643 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 644 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 645 | break; |
| 646 | |
| 647 | case CMD_EXCHANGE_SIM_IO: |
| 648 | request = (MainThreadRequest) msg.obj; |
| 649 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 650 | uiccPort = getUiccPortFromRequest(request); |
| 651 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 652 | loge("iccExchangeSimIO: No UICC"); |
| 653 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 654 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 655 | } else { |
| 656 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 657 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 658 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 659 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 660 | iccArgument.data, onCompleted); |
| 661 | } |
| 662 | break; |
| 663 | |
| 664 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 665 | ar = (AsyncResult) msg.obj; |
| 666 | request = (MainThreadRequest) ar.userObj; |
| 667 | if (ar.exception == null && ar.result != null) { |
| 668 | request.result = ar.result; |
| 669 | } else { |
| 670 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 671 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 672 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 673 | break; |
| 674 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 675 | case CMD_SEND_ENVELOPE: |
| 676 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 677 | uiccPort = getUiccPortFromRequest(request); |
| 678 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 679 | loge("sendEnvelopeWithStatus: No UICC"); |
| 680 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 681 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 682 | } else { |
| 683 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 684 | uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 685 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 686 | break; |
| 687 | |
| 688 | case EVENT_SEND_ENVELOPE_DONE: |
| 689 | ar = (AsyncResult) msg.obj; |
| 690 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 691 | if (ar.exception == null && ar.result != null) { |
| 692 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 693 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 694 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 695 | if (ar.result == null) { |
| 696 | loge("sendEnvelopeWithStatus: Empty response"); |
| 697 | } else if (ar.exception instanceof CommandException) { |
| 698 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 699 | ar.exception); |
| 700 | } else { |
| 701 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 702 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 703 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 704 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 705 | break; |
| 706 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 707 | case CMD_OPEN_CHANNEL: |
| 708 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 709 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 710 | IccLogicalChannelRequest openChannelRequest = |
| 711 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 712 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 713 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 714 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 715 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 716 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 717 | } else { |
| 718 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 719 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 720 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 721 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 722 | break; |
| 723 | |
| 724 | case EVENT_OPEN_CHANNEL_DONE: |
| 725 | ar = (AsyncResult) msg.obj; |
| 726 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 727 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 728 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 729 | int[] result = (int[]) ar.result; |
| 730 | int channelId = result[0]; |
| 731 | byte[] selectResponse = null; |
| 732 | if (result.length > 1) { |
| 733 | selectResponse = new byte[result.length - 1]; |
| 734 | for (int i = 1; i < result.length; ++i) { |
| 735 | selectResponse[i - 1] = (byte) result[i]; |
| 736 | } |
| 737 | } |
| 738 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 739 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 740 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 741 | if (ar.result == null) { |
| 742 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 743 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 744 | if (ar.exception != null) { |
| 745 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 746 | } |
| 747 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 748 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 749 | if (ar.exception instanceof CommandException) { |
| 750 | CommandException.Error error = |
| 751 | ((CommandException) (ar.exception)).getCommandError(); |
| 752 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 753 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 754 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 755 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 756 | } |
| 757 | } |
| 758 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 759 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 760 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 761 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 762 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 763 | break; |
| 764 | |
| 765 | case CMD_CLOSE_CHANNEL: |
| 766 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 767 | uiccPort = getUiccPortFromRequest(request); |
| 768 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 769 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 770 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 771 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 772 | } else { |
| 773 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 774 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 775 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 776 | break; |
| 777 | |
| 778 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 779 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 780 | break; |
| 781 | |
| 782 | case CMD_NV_READ_ITEM: |
| 783 | request = (MainThreadRequest) msg.obj; |
| 784 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 785 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 786 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 787 | break; |
| 788 | |
| 789 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 790 | ar = (AsyncResult) msg.obj; |
| 791 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 792 | if (ar.exception == null && ar.result != null) { |
| 793 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 794 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 795 | request.result = ""; |
| 796 | if (ar.result == null) { |
| 797 | loge("nvReadItem: Empty response"); |
| 798 | } else if (ar.exception instanceof CommandException) { |
| 799 | loge("nvReadItem: CommandException: " + |
| 800 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 801 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 802 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 803 | } |
| 804 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 805 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 806 | break; |
| 807 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 808 | case CMD_NV_WRITE_ITEM: |
| 809 | request = (MainThreadRequest) msg.obj; |
| 810 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 811 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 812 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 813 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 814 | break; |
| 815 | |
| 816 | case EVENT_NV_WRITE_ITEM_DONE: |
| 817 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 818 | break; |
| 819 | |
| 820 | case CMD_NV_WRITE_CDMA_PRL: |
| 821 | request = (MainThreadRequest) msg.obj; |
| 822 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 823 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 824 | break; |
| 825 | |
| 826 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 827 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 828 | break; |
| 829 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 830 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 831 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 832 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 833 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 834 | break; |
| 835 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 836 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 837 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 838 | break; |
| 839 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 840 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 841 | request = (MainThreadRequest) msg.obj; |
| 842 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 843 | request); |
| 844 | Phone phone = getPhoneFromRequest(request); |
| 845 | if (phone != null) { |
| 846 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 847 | } else { |
| 848 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 849 | request.result = false; |
| 850 | notifyRequester(request); |
| 851 | } |
| 852 | break; |
| 853 | } |
| 854 | |
| 855 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 856 | ar = (AsyncResult) msg.obj; |
| 857 | request = (MainThreadRequest) ar.userObj; |
| 858 | if (ar.exception == null && ar.result != null) { |
| 859 | request.result = ar.result; |
| 860 | } else { |
| 861 | // request.result must be set to something non-null |
| 862 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 863 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 864 | request.result = ar.result; |
| 865 | } else { |
| 866 | request.result = false; |
| 867 | } |
| 868 | if (ar.result == null) { |
| 869 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 870 | } else if (ar.exception instanceof CommandException) { |
| 871 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 872 | + ar.exception); |
| 873 | } else { |
| 874 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 875 | } |
| 876 | } |
| 877 | notifyRequester(request); |
| 878 | break; |
| 879 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 880 | case CMD_IS_VONR_ENABLED: { |
| 881 | request = (MainThreadRequest) msg.obj; |
| 882 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 883 | request); |
| 884 | Phone phone = getPhoneFromRequest(request); |
| 885 | if (phone != null) { |
| 886 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 887 | } else { |
| 888 | loge("isVoNrEnabled: No phone object"); |
| 889 | request.result = false; |
| 890 | notifyRequester(request); |
| 891 | } |
| 892 | break; |
| 893 | } |
| 894 | |
| 895 | case EVENT_IS_VONR_ENABLED_DONE: |
| 896 | ar = (AsyncResult) msg.obj; |
| 897 | request = (MainThreadRequest) ar.userObj; |
| 898 | if (ar.exception == null && ar.result != null) { |
| 899 | request.result = ar.result; |
| 900 | } else { |
| 901 | // request.result must be set to something non-null |
| 902 | // for the calling thread to unblock |
| 903 | if (ar.result != null) { |
| 904 | request.result = ar.result; |
| 905 | } else { |
| 906 | request.result = false; |
| 907 | } |
| 908 | if (ar.result == null) { |
| 909 | loge("isVoNrEnabled: Empty response"); |
| 910 | } else if (ar.exception instanceof CommandException) { |
| 911 | loge("isVoNrEnabled: CommandException: " |
| 912 | + ar.exception); |
| 913 | } else { |
| 914 | loge("isVoNrEnabled: Unknown exception"); |
| 915 | } |
| 916 | } |
| 917 | notifyRequester(request); |
| 918 | break; |
| 919 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 920 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 921 | request = (MainThreadRequest) msg.obj; |
| 922 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 923 | Phone phone = getPhoneFromRequest(request); |
| 924 | if (phone != null) { |
| 925 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 926 | request.workSource); |
| 927 | } else { |
| 928 | loge("enableNrDualConnectivity: No phone object"); |
| 929 | request.result = |
| 930 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 931 | notifyRequester(request); |
| 932 | } |
| 933 | break; |
| 934 | } |
| 935 | |
| 936 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 937 | ar = (AsyncResult) msg.obj; |
| 938 | request = (MainThreadRequest) ar.userObj; |
| 939 | if (ar.exception == null) { |
| 940 | request.result = |
| 941 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 942 | } else { |
| 943 | request.result = |
| 944 | TelephonyManager |
| 945 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 946 | if (ar.exception instanceof CommandException) { |
| 947 | CommandException.Error error = |
| 948 | ((CommandException) (ar.exception)).getCommandError(); |
| 949 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 950 | request.result = |
| 951 | TelephonyManager |
| 952 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 953 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 954 | request.result = |
| 955 | TelephonyManager |
| 956 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 957 | } |
| 958 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 959 | + ar.exception); |
| 960 | } else { |
| 961 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 962 | } |
| 963 | } |
| 964 | notifyRequester(request); |
| 965 | break; |
| 966 | } |
| 967 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 968 | case CMD_ENABLE_VONR: { |
| 969 | request = (MainThreadRequest) msg.obj; |
| 970 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 971 | Phone phone = getPhoneFromRequest(request); |
| 972 | if (phone != null) { |
| 973 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 974 | request.workSource); |
| 975 | } else { |
| 976 | loge("setVoNrEnabled: No phone object"); |
| 977 | request.result = |
| 978 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 979 | notifyRequester(request); |
| 980 | } |
| 981 | break; |
| 982 | } |
| 983 | |
| 984 | case EVENT_ENABLE_VONR_DONE: { |
| 985 | ar = (AsyncResult) msg.obj; |
| 986 | request = (MainThreadRequest) ar.userObj; |
| 987 | if (ar.exception == null) { |
| 988 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 989 | } else { |
| 990 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 991 | if (ar.exception instanceof CommandException) { |
| 992 | CommandException.Error error = |
| 993 | ((CommandException) (ar.exception)).getCommandError(); |
| 994 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 995 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 996 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 997 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 998 | } else { |
| 999 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1000 | } |
| 1001 | loge("setVoNrEnabled" + ": CommandException: " |
| 1002 | + ar.exception); |
| 1003 | } else { |
| 1004 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1005 | } |
| 1006 | } |
| 1007 | notifyRequester(request); |
| 1008 | break; |
| 1009 | } |
| 1010 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1011 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1012 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1013 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1014 | request); |
| 1015 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1016 | break; |
| 1017 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1018 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1019 | ar = (AsyncResult) msg.obj; |
| 1020 | request = (MainThreadRequest) ar.userObj; |
| 1021 | if (ar.exception == null && ar.result != null) { |
| 1022 | request.result = ar.result; // Integer |
| 1023 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1024 | // request.result must be set to something non-null |
| 1025 | // for the calling thread to unblock |
| 1026 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1027 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1028 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1029 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1030 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1031 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1032 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1033 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1034 | } |
| 1035 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1036 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1037 | break; |
| 1038 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1039 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1040 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1041 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1042 | request); |
| 1043 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1044 | (Pair<Integer, Long>) request.argument; |
| 1045 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1046 | reasonWithNetworkTypes.first, |
| 1047 | reasonWithNetworkTypes.second, |
| 1048 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1049 | break; |
| 1050 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1051 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1052 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1053 | break; |
| 1054 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1055 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1056 | request = (MainThreadRequest)msg.obj; |
| 1057 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1058 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1059 | break; |
| 1060 | |
| 1061 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1062 | ar = (AsyncResult)msg.obj; |
| 1063 | request = (MainThreadRequest)ar.userObj; |
| 1064 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1065 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1066 | break; |
| 1067 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1068 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1069 | request = (MainThreadRequest) msg.obj; |
| 1070 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1071 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1072 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1073 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1074 | break; |
| 1075 | |
| 1076 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1077 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1078 | break; |
| 1079 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1080 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1081 | request = (MainThreadRequest) msg.obj; |
| 1082 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1083 | request); |
| 1084 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1085 | break; |
| 1086 | |
| 1087 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1088 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1089 | break; |
| 1090 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1091 | case CMD_PERFORM_NETWORK_SCAN: |
| 1092 | request = (MainThreadRequest) msg.obj; |
| 1093 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1094 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1095 | break; |
| 1096 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1097 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1098 | request = (MainThreadRequest) msg.obj; |
| 1099 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1100 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1101 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1102 | request.argument; |
| 1103 | int callForwardingReason = args.first; |
| 1104 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1105 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1106 | } |
| 1107 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1108 | ar = (AsyncResult) msg.obj; |
| 1109 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1110 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1111 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1112 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1113 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1114 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1115 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1116 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1117 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1118 | // any service for voice call. |
| 1119 | if ((callForwardInfo.serviceClass |
| 1120 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1121 | callForwardingInfo = new CallForwardingInfo( |
| 1122 | callForwardInfo.status |
| 1123 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1124 | callForwardInfo.reason, |
| 1125 | callForwardInfo.number, |
| 1126 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1127 | break; |
| 1128 | } |
| 1129 | } |
| 1130 | // Didn't find a call forward info for voice call. |
| 1131 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1132 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1133 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1134 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1135 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1136 | } else { |
| 1137 | if (ar.result == null) { |
| 1138 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1139 | } |
| 1140 | if (ar.exception != null) { |
| 1141 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1142 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1143 | int errorCode = TelephonyManager |
| 1144 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1145 | if (ar.exception instanceof CommandException) { |
| 1146 | CommandException.Error error = |
| 1147 | ((CommandException) (ar.exception)).getCommandError(); |
| 1148 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1149 | errorCode = TelephonyManager |
| 1150 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1151 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1152 | errorCode = TelephonyManager |
| 1153 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1154 | } |
| 1155 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1156 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1157 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1158 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1159 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1160 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1161 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1162 | request = (MainThreadRequest) msg.obj; |
| 1163 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1164 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1165 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1166 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1167 | request.argument).first; |
| 1168 | request.phone.setCallForwardingOption( |
| 1169 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1170 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1171 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1172 | callForwardingInfoToSet.getReason(), |
| 1173 | callForwardingInfoToSet.getNumber(), |
| 1174 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1175 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1176 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1177 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1178 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1179 | ar = (AsyncResult) msg.obj; |
| 1180 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1181 | Consumer<Integer> callback = |
| 1182 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1183 | request.argument).second; |
| 1184 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1185 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1186 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1187 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1188 | if (ar.exception instanceof CommandException) { |
| 1189 | CommandException.Error error = |
| 1190 | ((CommandException) (ar.exception)).getCommandError(); |
| 1191 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1192 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1193 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1194 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1195 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1196 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1197 | } |
| 1198 | } |
| 1199 | callback.accept(errorCode); |
| 1200 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1201 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1202 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1203 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1204 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1205 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1206 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1207 | request = (MainThreadRequest) msg.obj; |
| 1208 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1209 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1210 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1211 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1212 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1213 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1214 | ar = (AsyncResult) msg.obj; |
| 1215 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1216 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1217 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1218 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1219 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1220 | // Service Class is a bit mask per 3gpp 27.007. |
| 1221 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1222 | if (callForwardResults.length > 1 |
| 1223 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1224 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1225 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1226 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1227 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1228 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1229 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1230 | } |
| 1231 | } else { |
| 1232 | if (ar.result == null) { |
| 1233 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1234 | } |
| 1235 | if (ar.exception != null) { |
| 1236 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1237 | } |
| 1238 | if (ar.exception instanceof CommandException) { |
| 1239 | CommandException.Error error = |
| 1240 | ((CommandException) (ar.exception)).getCommandError(); |
| 1241 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1242 | callForwardingStatus = |
| 1243 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1244 | } |
| 1245 | } |
| 1246 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1247 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1248 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1249 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1250 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1251 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1252 | request = (MainThreadRequest) msg.obj; |
| 1253 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1254 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1255 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1256 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1257 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1258 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1259 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1260 | ar = (AsyncResult) msg.obj; |
| 1261 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1262 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1263 | Consumer<Integer> callback = |
| 1264 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1265 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1266 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1267 | if (ar.exception instanceof CommandException) { |
| 1268 | CommandException.Error error = |
| 1269 | ((CommandException) (ar.exception)).getCommandError(); |
| 1270 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1271 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1272 | } else { |
| 1273 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1274 | } |
| 1275 | } else { |
| 1276 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1277 | } |
| 1278 | } else { |
| 1279 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1280 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1281 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1282 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1283 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1284 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1285 | ar = (AsyncResult) msg.obj; |
| 1286 | request = (MainThreadRequest) ar.userObj; |
| 1287 | CellNetworkScanResult cellScanResult; |
| 1288 | if (ar.exception == null && ar.result != null) { |
| 1289 | cellScanResult = new CellNetworkScanResult( |
| 1290 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1291 | (List<OperatorInfo>) ar.result); |
| 1292 | } else { |
| 1293 | if (ar.result == null) { |
| 1294 | loge("getCellNetworkScanResults: Empty response"); |
| 1295 | } |
| 1296 | if (ar.exception != null) { |
| 1297 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1298 | } |
| 1299 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1300 | if (ar.exception instanceof CommandException) { |
| 1301 | CommandException.Error error = |
| 1302 | ((CommandException) (ar.exception)).getCommandError(); |
| 1303 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1304 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1305 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1306 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1307 | } |
| 1308 | } |
| 1309 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1310 | } |
| 1311 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1312 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1313 | break; |
| 1314 | |
| 1315 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1316 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1317 | ManualNetworkSelectionArgument selArg = |
| 1318 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1319 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1320 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1321 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1322 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1323 | break; |
| 1324 | |
| 1325 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1326 | ar = (AsyncResult) msg.obj; |
| 1327 | request = (MainThreadRequest) ar.userObj; |
| 1328 | if (ar.exception == null) { |
| 1329 | request.result = true; |
| 1330 | } else { |
| 1331 | request.result = false; |
| 1332 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1333 | } |
| 1334 | notifyRequester(request); |
| 1335 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1336 | break; |
| 1337 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1338 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1339 | request = (MainThreadRequest) msg.obj; |
| 1340 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1341 | if (defaultPhone != null) { |
| 1342 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1343 | } else { |
| 1344 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1345 | Bundle bundle = new Bundle(); |
| 1346 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1347 | new ModemActivityInfo(0, 0, 0, |
| 1348 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1349 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1350 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1351 | break; |
| 1352 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1353 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1354 | ar = (AsyncResult) msg.obj; |
| 1355 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1356 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1357 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1358 | ModemActivityInfo ret = null; |
| 1359 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1360 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1361 | // Update the last modem activity info and the result of the request. |
| 1362 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1363 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1364 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1365 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1366 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1367 | .getTransmitTimeMillis(); |
| 1368 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1369 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1370 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1371 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1372 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1373 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1374 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1375 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1376 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1377 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1378 | info.getReceiveTimeMillis() |
| 1379 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1380 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1381 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1382 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1383 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1384 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1385 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1386 | } else { |
| 1387 | if (ar.result == null) { |
| 1388 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1389 | error = TelephonyManager.ModemActivityInfoException |
| 1390 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1391 | } else if (ar.exception instanceof CommandException) { |
| 1392 | loge("queryModemActivityInfo: CommandException: " + |
| 1393 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1394 | error = TelephonyManager.ModemActivityInfoException |
| 1395 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1396 | } else { |
| 1397 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1398 | error = TelephonyManager.ModemActivityInfoException |
| 1399 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1400 | } |
| 1401 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1402 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1403 | if (ret != null) { |
| 1404 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1405 | } else { |
| 1406 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1407 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1408 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1409 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1410 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1411 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1412 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1413 | case CMD_SET_ALLOWED_CARRIERS: |
| 1414 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1415 | CarrierRestrictionRules argument = |
| 1416 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1417 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1418 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1419 | break; |
| 1420 | |
| 1421 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1422 | ar = (AsyncResult) msg.obj; |
| 1423 | request = (MainThreadRequest) ar.userObj; |
| 1424 | if (ar.exception == null && ar.result != null) { |
| 1425 | request.result = ar.result; |
| 1426 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1427 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1428 | if (ar.exception instanceof CommandException) { |
| 1429 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1430 | CommandException.Error error = |
| 1431 | ((CommandException) (ar.exception)).getCommandError(); |
| 1432 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1433 | request.result = |
| 1434 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1435 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1436 | } else { |
| 1437 | loge("setAllowedCarriers: Unknown exception"); |
| 1438 | } |
| 1439 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1440 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1441 | break; |
| 1442 | |
| 1443 | case CMD_GET_ALLOWED_CARRIERS: |
| 1444 | request = (MainThreadRequest) msg.obj; |
| 1445 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1446 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1447 | break; |
| 1448 | |
| 1449 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1450 | ar = (AsyncResult) msg.obj; |
| 1451 | request = (MainThreadRequest) ar.userObj; |
| 1452 | if (ar.exception == null && ar.result != null) { |
| 1453 | request.result = ar.result; |
| 1454 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1455 | request.result = new IllegalStateException( |
| 1456 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1457 | if (ar.result == null) { |
| 1458 | loge("getAllowedCarriers: Empty response"); |
| 1459 | } else if (ar.exception instanceof CommandException) { |
| 1460 | loge("getAllowedCarriers: CommandException: " + |
| 1461 | ar.exception); |
| 1462 | } else { |
| 1463 | loge("getAllowedCarriers: Unknown exception"); |
| 1464 | } |
| 1465 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1466 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1467 | break; |
| 1468 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1469 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1470 | ar = (AsyncResult) msg.obj; |
| 1471 | request = (MainThreadRequest) ar.userObj; |
| 1472 | if (ar.exception == null && ar.result != null) { |
| 1473 | request.result = ar.result; |
| 1474 | } else { |
| 1475 | request.result = new IllegalArgumentException( |
| 1476 | "Failed to retrieve Forbidden Plmns"); |
| 1477 | if (ar.result == null) { |
| 1478 | loge("getForbiddenPlmns: Empty response"); |
| 1479 | } else { |
| 1480 | loge("getForbiddenPlmns: Unknown exception"); |
| 1481 | } |
| 1482 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1483 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1484 | break; |
| 1485 | |
| 1486 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1487 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1488 | uiccPort = getUiccPortFromRequest(request); |
| 1489 | if (uiccPort == null) { |
| 1490 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1491 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1492 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1493 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1494 | break; |
| 1495 | } |
| 1496 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1497 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1498 | if (uiccApp == null) { |
| 1499 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1500 | + appType); |
| 1501 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1502 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1503 | break; |
| 1504 | } else { |
| 1505 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1506 | + " specified type -- " + appType); |
| 1507 | } |
| 1508 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1509 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1510 | onCompleted); |
| 1511 | break; |
| 1512 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1513 | case CMD_SWITCH_SLOTS: |
| 1514 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1515 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1516 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1517 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1518 | break; |
| 1519 | |
| 1520 | case EVENT_SWITCH_SLOTS_DONE: |
| 1521 | ar = (AsyncResult) msg.obj; |
| 1522 | request = (MainThreadRequest) ar.userObj; |
| 1523 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1524 | notifyRequester(request); |
| 1525 | break; |
| 1526 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1527 | request = (MainThreadRequest) msg.obj; |
| 1528 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1529 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1530 | break; |
| 1531 | |
| 1532 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1533 | ar = (AsyncResult) msg.obj; |
| 1534 | request = (MainThreadRequest) ar.userObj; |
| 1535 | if (ar.exception != null) { |
| 1536 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1537 | } else { |
| 1538 | int mode = ((int[]) ar.result)[0]; |
| 1539 | if (mode == 0) { |
| 1540 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1541 | } else { |
| 1542 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1543 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1544 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1545 | notifyRequester(request); |
| 1546 | break; |
| 1547 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1548 | request = (MainThreadRequest) msg.obj; |
| 1549 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1550 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1551 | break; |
| 1552 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1553 | ar = (AsyncResult) msg.obj; |
| 1554 | request = (MainThreadRequest) ar.userObj; |
| 1555 | if (ar.exception != null) { |
| 1556 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1557 | } else { |
| 1558 | request.result = ((int[]) ar.result)[0]; |
| 1559 | } |
| 1560 | notifyRequester(request); |
| 1561 | break; |
| 1562 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1563 | request = (MainThreadRequest) msg.obj; |
| 1564 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1565 | int mode = (int) request.argument; |
| 1566 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1567 | break; |
| 1568 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1569 | ar = (AsyncResult) msg.obj; |
| 1570 | request = (MainThreadRequest) ar.userObj; |
| 1571 | request.result = ar.exception == null; |
| 1572 | notifyRequester(request); |
| 1573 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1574 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1575 | request = (MainThreadRequest) msg.obj; |
| 1576 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1577 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1578 | break; |
| 1579 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1580 | ar = (AsyncResult) msg.obj; |
| 1581 | request = (MainThreadRequest) ar.userObj; |
| 1582 | if (ar.exception != null) { |
| 1583 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1584 | } else { |
| 1585 | request.result = ((int[]) ar.result)[0]; |
| 1586 | } |
| 1587 | notifyRequester(request); |
| 1588 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1589 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1590 | request = (MainThreadRequest) msg.obj; |
| 1591 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1592 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1593 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1594 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1595 | break; |
| 1596 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1597 | ar = (AsyncResult) msg.obj; |
| 1598 | request = (MainThreadRequest) ar.userObj; |
| 1599 | request.result = ar.exception == null; |
| 1600 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1601 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1602 | case CMD_GET_ALL_CELL_INFO: |
| 1603 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1604 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1605 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1606 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1607 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1608 | ar = (AsyncResult) msg.obj; |
| 1609 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1610 | // If a timeout occurs, the response will be null |
| 1611 | request.result = (ar.exception == null && ar.result != null) |
| 1612 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1613 | synchronized (request) { |
| 1614 | request.notifyAll(); |
| 1615 | } |
| 1616 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1617 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1618 | request = (MainThreadRequest) msg.obj; |
| 1619 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1620 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1621 | break; |
| 1622 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1623 | ar = (AsyncResult) msg.obj; |
| 1624 | request = (MainThreadRequest) ar.userObj; |
| 1625 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1626 | try { |
| 1627 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1628 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1629 | cb.onError( |
| 1630 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1631 | ar.exception.getClass().getName(), |
| 1632 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1633 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1634 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1635 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1636 | } else { |
| 1637 | // use the result as returned |
| 1638 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1639 | } |
| 1640 | } catch (RemoteException re) { |
| 1641 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1642 | } |
| 1643 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1644 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1645 | request = (MainThreadRequest) msg.obj; |
| 1646 | WorkSource ws = (WorkSource) request.argument; |
| 1647 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1648 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1649 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1650 | } |
| 1651 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1652 | ar = (AsyncResult) msg.obj; |
| 1653 | request = (MainThreadRequest) ar.userObj; |
| 1654 | if (ar.exception == null) { |
| 1655 | request.result = ar.result; |
| 1656 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1657 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1658 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1659 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | synchronized (request) { |
| 1663 | request.notifyAll(); |
| 1664 | } |
| 1665 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1666 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1667 | case CMD_MODEM_REBOOT: |
| 1668 | request = (MainThreadRequest) msg.obj; |
| 1669 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1670 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1671 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1672 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1673 | handleNullReturnEvent(msg, "rebootModem"); |
| 1674 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1675 | case CMD_REQUEST_ENABLE_MODEM: |
| 1676 | request = (MainThreadRequest) msg.obj; |
| 1677 | boolean enable = (boolean) request.argument; |
| 1678 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1679 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1680 | PhoneConfigurationManager.getInstance() |
| 1681 | .enablePhone(request.phone, enable, onCompleted); |
| 1682 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1683 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1684 | ar = (AsyncResult) msg.obj; |
| 1685 | request = (MainThreadRequest) ar.userObj; |
| 1686 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1687 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1688 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1689 | if ((boolean) request.result) { |
| 1690 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1691 | updateModemStateMetrics(); |
| 1692 | } else { |
| 1693 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1694 | + ar.exception); |
| 1695 | } |
| 1696 | notifyRequester(request); |
| 1697 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1698 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1699 | case CMD_GET_MODEM_STATUS: |
| 1700 | request = (MainThreadRequest) msg.obj; |
| 1701 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1702 | PhoneConfigurationManager.getInstance() |
| 1703 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1704 | break; |
| 1705 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1706 | ar = (AsyncResult) msg.obj; |
| 1707 | request = (MainThreadRequest) ar.userObj; |
| 1708 | int id = request.phone.getPhoneId(); |
| 1709 | if (ar.exception == null && ar.result != null) { |
| 1710 | request.result = ar.result; |
| 1711 | //update the cache as modem status has changed |
| 1712 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1713 | (boolean) request.result); |
| 1714 | } else { |
| 1715 | // Return true if modem status cannot be retrieved. For most cases, |
| 1716 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1717 | // and disable modem are not supported. Modem is always on. |
| 1718 | // TODO: this should be fixed in R to support a third |
| 1719 | // status UNKNOWN b/131631629 |
| 1720 | request.result = true; |
| 1721 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1722 | + ar.exception); |
| 1723 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1724 | notifyRequester(request); |
| 1725 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1726 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1727 | request = (MainThreadRequest) msg.obj; |
| 1728 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1729 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1730 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1731 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1732 | break; |
| 1733 | } |
| 1734 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1735 | ar = (AsyncResult) msg.obj; |
| 1736 | request = (MainThreadRequest) ar.userObj; |
| 1737 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1738 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1739 | args.second.accept(ar.exception == null); |
| 1740 | notifyRequester(request); |
| 1741 | break; |
| 1742 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1743 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1744 | request = (MainThreadRequest) msg.obj; |
| 1745 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1746 | Phone phone = getPhoneFromRequest(request); |
| 1747 | if (phone != null) { |
| 1748 | phone.getSystemSelectionChannels(onCompleted); |
| 1749 | } else { |
| 1750 | loge("getSystemSelectionChannels: No phone object"); |
| 1751 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1752 | notifyRequester(request); |
| 1753 | } |
| 1754 | break; |
| 1755 | } |
| 1756 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1757 | ar = (AsyncResult) msg.obj; |
| 1758 | request = (MainThreadRequest) ar.userObj; |
| 1759 | if (ar.exception == null && ar.result != null) { |
| 1760 | request.result = ar.result; |
| 1761 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1762 | request.result = new IllegalStateException( |
| 1763 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1764 | if (ar.result == null) { |
| 1765 | loge("getSystemSelectionChannels: Empty response"); |
| 1766 | } else { |
| 1767 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1768 | } |
| 1769 | } |
| 1770 | notifyRequester(request); |
| 1771 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1772 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1773 | ar = (AsyncResult) msg.obj; |
| 1774 | request = (MainThreadRequest) ar.userObj; |
| 1775 | if (ar.exception == null && ar.result != null) { |
| 1776 | request.result = ar.result; |
| 1777 | } else { |
| 1778 | request.result = -1; |
| 1779 | loge("Failed to set Forbidden Plmns"); |
| 1780 | if (ar.result == null) { |
| 1781 | loge("setForbidenPlmns: Empty response"); |
| 1782 | } else if (ar.exception != null) { |
| 1783 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1784 | request.result = -1; |
| 1785 | } else { |
| 1786 | loge("setForbiddenPlmns: Unknown exception"); |
| 1787 | } |
| 1788 | } |
| 1789 | notifyRequester(request); |
| 1790 | break; |
| 1791 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1792 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1793 | uiccPort = getUiccPortFromRequest(request); |
| 1794 | if (uiccPort == null) { |
| 1795 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1796 | request.result = -1; |
| 1797 | notifyRequester(request); |
| 1798 | break; |
| 1799 | } |
| 1800 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1801 | (Pair<Integer, List<String>>) request.argument; |
| 1802 | appType = setFplmnsArgs.first; |
| 1803 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1804 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1805 | if (uiccApp == null) { |
| 1806 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1807 | request.result = -1; |
| 1808 | loge("Failed to get UICC App"); |
| 1809 | notifyRequester(request); |
| 1810 | } else { |
| 1811 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1812 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1813 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1814 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1815 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1816 | case CMD_ERASE_MODEM_CONFIG: |
| 1817 | request = (MainThreadRequest) msg.obj; |
| 1818 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1819 | defaultPhone.eraseModemConfig(onCompleted); |
| 1820 | break; |
| 1821 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1822 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1823 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1824 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1825 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1826 | request = (MainThreadRequest) msg.obj; |
| 1827 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1828 | notifyRequester(request); |
| 1829 | break; |
| 1830 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1831 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1832 | request = (MainThreadRequest) msg.obj; |
| 1833 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1834 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1835 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1836 | changed.first, changed.second, onCompleted); |
| 1837 | break; |
| 1838 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1839 | ar = (AsyncResult) msg.obj; |
| 1840 | request = (MainThreadRequest) ar.userObj; |
| 1841 | if (ar.exception == null) { |
| 1842 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1843 | // If the operation is successful, update the PIN storage |
| 1844 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1845 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1846 | UiccController.getInstance().getPinStorage() |
| 1847 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1848 | } else { |
| 1849 | request.result = msg.arg1; |
| 1850 | } |
| 1851 | notifyRequester(request); |
| 1852 | break; |
| 1853 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1854 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1855 | request = (MainThreadRequest) msg.obj; |
| 1856 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1857 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1858 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1859 | enabled.first, enabled.second, onCompleted); |
| 1860 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1861 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1862 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1863 | ar = (AsyncResult) msg.obj; |
| 1864 | request = (MainThreadRequest) ar.userObj; |
| 1865 | if (ar.exception == null) { |
| 1866 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1867 | // If the operation is successful, update the PIN storage |
| 1868 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1869 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1870 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1871 | UiccController.getInstance().getPinStorage() |
| 1872 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1873 | } else { |
| 1874 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1875 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1876 | } else { |
| 1877 | request.result = msg.arg1; |
| 1878 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1879 | |
| 1880 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1881 | notifyRequester(request); |
| 1882 | break; |
| 1883 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1884 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1885 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1886 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1887 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1888 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1889 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1890 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1891 | |
| 1892 | case CMD_SET_DATA_THROTTLING: { |
| 1893 | request = (MainThreadRequest) msg.obj; |
| 1894 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1895 | DataThrottlingRequest dataThrottlingRequest = |
| 1896 | (DataThrottlingRequest) request.argument; |
| 1897 | Phone phone = getPhoneFromRequest(request); |
| 1898 | if (phone != null) { |
| 1899 | phone.setDataThrottling(onCompleted, |
| 1900 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1901 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1902 | } else { |
| 1903 | loge("setDataThrottling: No phone object"); |
| 1904 | request.result = |
| 1905 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1906 | notifyRequester(request); |
| 1907 | } |
| 1908 | |
| 1909 | break; |
| 1910 | } |
| 1911 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1912 | ar = (AsyncResult) msg.obj; |
| 1913 | request = (MainThreadRequest) ar.userObj; |
| 1914 | |
| 1915 | if (ar.exception == null) { |
| 1916 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1917 | } else if (ar.exception instanceof CommandException) { |
| 1918 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1919 | CommandException.Error error = |
| 1920 | ((CommandException) (ar.exception)).getCommandError(); |
| 1921 | |
| 1922 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1923 | request.result = TelephonyManager |
| 1924 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1925 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1926 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 1927 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1928 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1929 | } else { |
| 1930 | request.result = |
| 1931 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1932 | } |
| 1933 | } else { |
| 1934 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1935 | } |
| 1936 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1937 | notifyRequester(request); |
| 1938 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1939 | |
| 1940 | case CMD_SET_SIM_POWER: { |
| 1941 | request = (MainThreadRequest) msg.obj; |
| 1942 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1943 | request = (MainThreadRequest) msg.obj; |
| 1944 | int stateToSet = |
| 1945 | ((Pair<Integer, IIntegerConsumer>) |
| 1946 | request.argument).first; |
| 1947 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1948 | break; |
| 1949 | } |
| 1950 | case EVENT_SET_SIM_POWER_DONE: { |
| 1951 | ar = (AsyncResult) msg.obj; |
| 1952 | request = (MainThreadRequest) ar.userObj; |
| 1953 | IIntegerConsumer callback = |
| 1954 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1955 | if (ar.exception != null) { |
| 1956 | loge("setSimPower exception: " + ar.exception); |
| 1957 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1958 | .RESULT_ERROR_UNKNOWN; |
| 1959 | if (ar.exception instanceof CommandException) { |
| 1960 | CommandException.Error error = |
| 1961 | ((CommandException) (ar.exception)).getCommandError(); |
| 1962 | if (error == CommandException.Error.SIM_ERR) { |
| 1963 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1964 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1965 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1966 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1967 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1968 | } else { |
| 1969 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1970 | } |
| 1971 | } |
| 1972 | try { |
| 1973 | callback.accept(errorCode); |
| 1974 | } catch (RemoteException e) { |
| 1975 | // Ignore if the remote process is no longer available to call back. |
| 1976 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1977 | } |
| 1978 | } else { |
| 1979 | try { |
| 1980 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1981 | } catch (RemoteException e) { |
| 1982 | // Ignore if the remote process is no longer available to call back. |
| 1983 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1984 | } |
| 1985 | } |
| 1986 | break; |
| 1987 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1988 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1989 | request = (MainThreadRequest) msg.obj; |
| 1990 | |
| 1991 | final Phone phone = getPhoneFromRequest(request); |
| 1992 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1993 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1994 | notifyRequester(request); |
| 1995 | break; |
| 1996 | } |
| 1997 | |
| 1998 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1999 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2000 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2001 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2002 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2003 | request.subId, pair.first /*callingUid*/, |
| 2004 | pair.second /*request*/, onCompleted); |
| 2005 | break; |
| 2006 | } |
| 2007 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2008 | ar = (AsyncResult) msg.obj; |
| 2009 | request = (MainThreadRequest) ar.userObj; |
| 2010 | // request.result will be the exception of ar if present, true otherwise. |
| 2011 | // Be cautious not to leave result null which will wait() forever |
| 2012 | request.result = ar.exception != null ? ar.exception : true; |
| 2013 | notifyRequester(request); |
| 2014 | break; |
| 2015 | } |
| 2016 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2017 | request = (MainThreadRequest) msg.obj; |
| 2018 | |
| 2019 | Phone phone = getPhoneFromRequest(request); |
| 2020 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2021 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2022 | notifyRequester(request); |
| 2023 | break; |
| 2024 | } |
| 2025 | |
| 2026 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2027 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2028 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2029 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2030 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2031 | request.subId, pair.first /*callingUid*/, |
| 2032 | pair.second /*request*/, onCompleted); |
| 2033 | break; |
| 2034 | } |
| 2035 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2036 | ar = (AsyncResult) msg.obj; |
| 2037 | request = (MainThreadRequest) ar.userObj; |
| 2038 | request.result = ar.exception != null ? ar.exception : true; |
| 2039 | notifyRequester(request); |
| 2040 | break; |
| 2041 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2042 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2043 | case CMD_GET_SLICING_CONFIG: { |
| 2044 | request = (MainThreadRequest) msg.obj; |
| 2045 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2046 | request.phone.getSlicingConfig(onCompleted); |
| 2047 | break; |
| 2048 | } |
| 2049 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2050 | ar = (AsyncResult) msg.obj; |
| 2051 | request = (MainThreadRequest) ar.userObj; |
| 2052 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2053 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2054 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2055 | Bundle bundle = new Bundle(); |
| 2056 | int resultCode = 0; |
| 2057 | if (ar.exception != null) { |
| 2058 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2059 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2060 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2061 | } else if (ar.result == null) { |
| 2062 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2063 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2064 | } else { |
| 2065 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2066 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2067 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2068 | } |
| 2069 | |
| 2070 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2071 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2072 | } |
| 2073 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2074 | result.send(resultCode, bundle); |
| 2075 | notifyRequester(request); |
| 2076 | break; |
| 2077 | } |
| 2078 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2079 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2080 | request = (MainThreadRequest) msg.obj; |
| 2081 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2082 | UiccController.getInstance().getPinStorage() |
| 2083 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2084 | notifyRequester(request); |
| 2085 | break; |
| 2086 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2087 | default: |
| 2088 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2089 | break; |
| 2090 | } |
| 2091 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2092 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2093 | private void notifyRequester(MainThreadRequest request) { |
| 2094 | synchronized (request) { |
| 2095 | request.notifyAll(); |
| 2096 | } |
| 2097 | } |
| 2098 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2099 | private void handleNullReturnEvent(Message msg, String command) { |
| 2100 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2101 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2102 | if (ar.exception == null) { |
| 2103 | request.result = true; |
| 2104 | } else { |
| 2105 | request.result = false; |
| 2106 | if (ar.exception instanceof CommandException) { |
| 2107 | loge(command + ": CommandException: " + ar.exception); |
| 2108 | } else { |
| 2109 | loge(command + ": Unknown exception"); |
| 2110 | } |
| 2111 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2112 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2113 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2114 | } |
| 2115 | |
| 2116 | /** |
| 2117 | * Posts the specified command to be executed on the main thread, |
| 2118 | * waits for the request to complete, and returns the result. |
| 2119 | * @see #sendRequestAsync |
| 2120 | */ |
| 2121 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2122 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2123 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2124 | } |
| 2125 | |
| 2126 | /** |
| 2127 | * Posts the specified command to be executed on the main thread, |
| 2128 | * waits for the request to complete, and returns the result. |
| 2129 | * @see #sendRequestAsync |
| 2130 | */ |
| 2131 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2132 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2133 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2134 | } |
| 2135 | |
| 2136 | /** |
| 2137 | * Posts the specified command to be executed on the main thread, |
| 2138 | * waits for the request to complete, and returns the result. |
| 2139 | * @see #sendRequestAsync |
| 2140 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2141 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2142 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2143 | } |
| 2144 | |
| 2145 | /** |
| 2146 | * Posts the specified command to be executed on the main thread, |
| 2147 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2148 | * if not timeout or null otherwise. |
| 2149 | * @see #sendRequestAsync |
| 2150 | */ |
| 2151 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2152 | long timeoutInMs) { |
| 2153 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2154 | } |
| 2155 | |
| 2156 | /** |
| 2157 | * Posts the specified command to be executed on the main thread, |
| 2158 | * waits for the request to complete, and returns the result. |
| 2159 | * @see #sendRequestAsync |
| 2160 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2161 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2162 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2163 | } |
| 2164 | |
| 2165 | /** |
| 2166 | * Posts the specified command to be executed on the main thread, |
| 2167 | * waits for the request to complete, and returns the result. |
| 2168 | * @see #sendRequestAsync |
| 2169 | */ |
| 2170 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2171 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2172 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2173 | } |
| 2174 | |
| 2175 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2176 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2177 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2178 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2179 | * @see #sendRequestAsync |
| 2180 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2181 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2182 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2183 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2184 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2185 | } |
| 2186 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2187 | MainThreadRequest request = null; |
| 2188 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2189 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2190 | } else if (phone != null) { |
| 2191 | request = new MainThreadRequest(argument, phone, workSource); |
| 2192 | } else { |
| 2193 | request = new MainThreadRequest(argument, subId, workSource); |
| 2194 | } |
| 2195 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2196 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2197 | msg.sendToTarget(); |
| 2198 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2199 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2200 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2201 | if (timeoutInMs >= 0) { |
| 2202 | // Wait for at least timeoutInMs before returning null request result |
| 2203 | long now = SystemClock.elapsedRealtime(); |
| 2204 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2205 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2206 | try { |
| 2207 | request.wait(deadline - now); |
| 2208 | } catch (InterruptedException e) { |
| 2209 | // Do nothing, go back and check if request is completed or timeout |
| 2210 | } finally { |
| 2211 | now = SystemClock.elapsedRealtime(); |
| 2212 | } |
| 2213 | } |
| 2214 | } else { |
| 2215 | // Wait for the request to complete |
| 2216 | while (request.result == null) { |
| 2217 | try { |
| 2218 | request.wait(); |
| 2219 | } catch (InterruptedException e) { |
| 2220 | // Do nothing, go back and wait until the request is complete |
| 2221 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2222 | } |
| 2223 | } |
| 2224 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2225 | if (request.result == null) { |
| 2226 | Log.wtf(LOG_TAG, |
| 2227 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2228 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2229 | return request.result; |
| 2230 | } |
| 2231 | |
| 2232 | /** |
| 2233 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2234 | * Posts the specified command to be executed on the main thread, and |
| 2235 | * returns immediately. |
| 2236 | * @see #sendRequest |
| 2237 | */ |
| 2238 | private void sendRequestAsync(int command) { |
| 2239 | mMainThreadHandler.sendEmptyMessage(command); |
| 2240 | } |
| 2241 | |
| 2242 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2243 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2244 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2245 | */ |
| 2246 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2247 | sendRequestAsync(command, argument, null, null); |
| 2248 | } |
| 2249 | |
| 2250 | /** |
| 2251 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2252 | * @see {@link #sendRequest(int,Object)} |
| 2253 | */ |
| 2254 | private void sendRequestAsync( |
| 2255 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2256 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2257 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2258 | msg.sendToTarget(); |
| 2259 | } |
| 2260 | |
| 2261 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2262 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2263 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2264 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2265 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2266 | synchronized (PhoneInterfaceManager.class) { |
| 2267 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2268 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2269 | } else { |
| 2270 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2271 | } |
| 2272 | return sInstance; |
| 2273 | } |
| 2274 | } |
| 2275 | |
| 2276 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2277 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2278 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2279 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2280 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2281 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2282 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2283 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2284 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2285 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2286 | mTelephonySharedPreferences = |
| 2287 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2288 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2289 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2290 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2291 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2292 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2293 | publish(); |
| 2294 | } |
| 2295 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2296 | private Phone getDefaultPhone() { |
| 2297 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2298 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2299 | } |
| 2300 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2301 | private void publish() { |
| 2302 | if (DBG) log("publish: " + this); |
| 2303 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2304 | TelephonyFrameworkInitializer |
| 2305 | .getTelephonyServiceManager() |
| 2306 | .getTelephonyServiceRegisterer() |
| 2307 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2308 | } |
| 2309 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2310 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2311 | if (request.phone != null) { |
| 2312 | return request.phone; |
| 2313 | } else { |
| 2314 | return getPhoneFromSubId(request.subId); |
| 2315 | } |
| 2316 | } |
| 2317 | |
| 2318 | private Phone getPhoneFromSubId(int subId) { |
| 2319 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2320 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2321 | } |
| 2322 | |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2323 | private UiccPort getUiccPortFromRequest(MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2324 | Phone phone = getPhoneFromRequest(request); |
| 2325 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2326 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2327 | } |
| 2328 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2329 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2330 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2331 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2332 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2333 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2334 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2335 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2336 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2337 | } |
| 2338 | |
| 2339 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2340 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2341 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2342 | } |
| 2343 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2344 | private boolean isImsAvailableOnDevice() { |
| 2345 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2346 | if (pm == null) { |
| 2347 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2348 | // so do not throw error and allow. |
| 2349 | return true; |
| 2350 | } |
| 2351 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2352 | } |
| 2353 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2354 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2355 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2356 | } |
| 2357 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2358 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2359 | if (DBG) log("dial: " + number); |
| 2360 | // No permission check needed here: This is just a wrapper around the |
| 2361 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2362 | // the UI before it does anything. |
| 2363 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2364 | final long identity = Binder.clearCallingIdentity(); |
| 2365 | try { |
| 2366 | String url = createTelUrl(number); |
| 2367 | if (url == null) { |
| 2368 | return; |
| 2369 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2370 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2371 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2372 | PhoneConstants.State state = mCM.getState(subId); |
| 2373 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2374 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2375 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2376 | mApp.startActivity(intent); |
| 2377 | } |
| 2378 | } finally { |
| 2379 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2380 | } |
| 2381 | } |
| 2382 | |
| 2383 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2384 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2385 | } |
| 2386 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2387 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2388 | if (DBG) log("call: " + number); |
| 2389 | |
| 2390 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2391 | // need to do a permission check since we're calling startActivity() |
| 2392 | // from the context of the phone app. |
| 2393 | enforceCallPermission(); |
| 2394 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2395 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2396 | != AppOpsManager.MODE_ALLOWED) { |
| 2397 | return; |
| 2398 | } |
| 2399 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2400 | final long identity = Binder.clearCallingIdentity(); |
| 2401 | try { |
| 2402 | String url = createTelUrl(number); |
| 2403 | if (url == null) { |
| 2404 | return; |
| 2405 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2406 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2407 | boolean isValid = false; |
| 2408 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2409 | if (slist != null) { |
| 2410 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2411 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2412 | isValid = true; |
| 2413 | break; |
| 2414 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2415 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2416 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2417 | if (!isValid) { |
| 2418 | return; |
| 2419 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2420 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2421 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2422 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2423 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2424 | mApp.startActivity(intent); |
| 2425 | } finally { |
| 2426 | Binder.restoreCallingIdentity(identity); |
| 2427 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2428 | } |
| 2429 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2430 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2431 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2432 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2433 | } |
| 2434 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2435 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2436 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2437 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2438 | } |
| 2439 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2440 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2441 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2442 | |
| 2443 | final long identity = Binder.clearCallingIdentity(); |
| 2444 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2445 | Phone phone = getPhone(subId); |
| 2446 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2447 | checkSimPin.start(); |
| 2448 | return checkSimPin.unlockSim(null, pin); |
| 2449 | } finally { |
| 2450 | Binder.restoreCallingIdentity(identity); |
| 2451 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2452 | } |
| 2453 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2454 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2455 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2456 | |
| 2457 | final long identity = Binder.clearCallingIdentity(); |
| 2458 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2459 | Phone phone = getPhone(subId); |
| 2460 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2461 | checkSimPuk.start(); |
| 2462 | return checkSimPuk.unlockSim(puk, pin); |
| 2463 | } finally { |
| 2464 | Binder.restoreCallingIdentity(identity); |
| 2465 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2466 | } |
| 2467 | |
| 2468 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2469 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2470 | * a synchronous one. |
| 2471 | */ |
| 2472 | private static class UnlockSim extends Thread { |
| 2473 | |
| 2474 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2475 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2476 | |
| 2477 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2478 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2479 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2480 | |
| 2481 | // For replies from SimCard interface |
| 2482 | private Handler mHandler; |
| 2483 | |
| 2484 | // For async handler to identify request type |
| 2485 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2486 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2487 | UnlockSim(int phoneId, IccCard simCard) { |
| 2488 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2489 | mSimCard = simCard; |
| 2490 | } |
| 2491 | |
| 2492 | @Override |
| 2493 | public void run() { |
| 2494 | Looper.prepare(); |
| 2495 | synchronized (UnlockSim.this) { |
| 2496 | mHandler = new Handler() { |
| 2497 | @Override |
| 2498 | public void handleMessage(Message msg) { |
| 2499 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2500 | switch (msg.what) { |
| 2501 | case SUPPLY_PIN_COMPLETE: |
| 2502 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2503 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2504 | mRetryCount = msg.arg1; |
| 2505 | if (ar.exception != null) { |
| 2506 | if (ar.exception instanceof CommandException && |
| 2507 | ((CommandException)(ar.exception)).getCommandError() |
| 2508 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2509 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2510 | } //When UiccCardApp dispose,handle message and return exception |
| 2511 | else if (ar.exception instanceof CommandException && |
| 2512 | ((CommandException) (ar.exception)).getCommandError() |
| 2513 | == CommandException.Error.ABORTED) { |
| 2514 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2515 | } else { |
| 2516 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2517 | } |
| 2518 | } else { |
| 2519 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2520 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2521 | mDone = true; |
| 2522 | UnlockSim.this.notifyAll(); |
| 2523 | } |
| 2524 | break; |
| 2525 | } |
| 2526 | } |
| 2527 | }; |
| 2528 | UnlockSim.this.notifyAll(); |
| 2529 | } |
| 2530 | Looper.loop(); |
| 2531 | } |
| 2532 | |
| 2533 | /* |
| 2534 | * Use PIN or PUK to unlock SIM card |
| 2535 | * |
| 2536 | * If PUK is null, unlock SIM card with PIN |
| 2537 | * |
| 2538 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2539 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2540 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2541 | |
| 2542 | while (mHandler == null) { |
| 2543 | try { |
| 2544 | wait(); |
| 2545 | } catch (InterruptedException e) { |
| 2546 | Thread.currentThread().interrupt(); |
| 2547 | } |
| 2548 | } |
| 2549 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2550 | |
| 2551 | if (puk == null) { |
| 2552 | mSimCard.supplyPin(pin, callback); |
| 2553 | } else { |
| 2554 | mSimCard.supplyPuk(puk, pin, callback); |
| 2555 | } |
| 2556 | |
| 2557 | while (!mDone) { |
| 2558 | try { |
| 2559 | Log.d(LOG_TAG, "wait for done"); |
| 2560 | wait(); |
| 2561 | } catch (InterruptedException e) { |
| 2562 | // Restore the interrupted status |
| 2563 | Thread.currentThread().interrupt(); |
| 2564 | } |
| 2565 | } |
| 2566 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2567 | int[] resultArray = new int[2]; |
| 2568 | resultArray[0] = mResult; |
| 2569 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2570 | |
| 2571 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2572 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2573 | } |
| 2574 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2575 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2576 | } |
| 2577 | } |
| 2578 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2579 | /** |
| 2580 | * This method has been removed due to privacy and stability concerns. |
| 2581 | */ |
| 2582 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2583 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2584 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2585 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2586 | } |
| 2587 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2588 | @Override |
| 2589 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2590 | mApp.getSystemService(AppOpsManager.class) |
| 2591 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2592 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2593 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2594 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2595 | // Callers targeting S have no business invoking this method. |
| 2596 | return; |
| 2597 | } |
| 2598 | |
| 2599 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2600 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2601 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2602 | .setCallingPackage(callingPackage) |
| 2603 | .setCallingFeatureId(null) |
| 2604 | .setCallingPid(Binder.getCallingPid()) |
| 2605 | .setCallingUid(Binder.getCallingUid()) |
| 2606 | .setMethod("updateServiceLocation") |
| 2607 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2608 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2609 | .build()); |
| 2610 | // Apps that lack location permission have no business calling this method; |
| 2611 | // however, because no permission was declared in the public API, denials must |
| 2612 | // all be "soft". |
| 2613 | switch (locationResult) { |
| 2614 | case DENIED_HARD: /* fall through */ |
| 2615 | case DENIED_SOFT: |
| 2616 | return; |
| 2617 | } |
| 2618 | |
| 2619 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2620 | final long identity = Binder.clearCallingIdentity(); |
| 2621 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2622 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2623 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2624 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2625 | } |
| 2626 | } finally { |
| 2627 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2628 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2629 | } |
| 2630 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2631 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2632 | @Override |
| 2633 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2634 | return isRadioOnWithFeature(callingPackage, null); |
| 2635 | } |
| 2636 | |
| 2637 | |
| 2638 | @Override |
| 2639 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2640 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2641 | callingFeatureId); |
| 2642 | } |
| 2643 | |
| 2644 | @Deprecated |
| 2645 | @Override |
| 2646 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2647 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2648 | } |
| 2649 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2650 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2651 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2652 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2653 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2654 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2655 | return false; |
| 2656 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2657 | |
| 2658 | final long identity = Binder.clearCallingIdentity(); |
| 2659 | try { |
| 2660 | return isRadioOnForSubscriber(subId); |
| 2661 | } finally { |
| 2662 | Binder.restoreCallingIdentity(identity); |
| 2663 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2664 | } |
| 2665 | |
| 2666 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2667 | final long identity = Binder.clearCallingIdentity(); |
| 2668 | try { |
| 2669 | final Phone phone = getPhone(subId); |
| 2670 | if (phone != null) { |
| 2671 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2672 | } else { |
| 2673 | return false; |
| 2674 | } |
| 2675 | } finally { |
| 2676 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2677 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2678 | } |
| 2679 | |
| 2680 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2681 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2682 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2683 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2684 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2685 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2686 | |
| 2687 | final long identity = Binder.clearCallingIdentity(); |
| 2688 | try { |
| 2689 | final Phone phone = getPhone(subId); |
| 2690 | if (phone != null) { |
| 2691 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2692 | } |
| 2693 | } finally { |
| 2694 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2695 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2696 | } |
| 2697 | |
| 2698 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2699 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2700 | } |
| 2701 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2702 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2703 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2704 | |
| 2705 | final long identity = Binder.clearCallingIdentity(); |
| 2706 | try { |
| 2707 | final Phone phone = getPhone(subId); |
| 2708 | if (phone == null) { |
| 2709 | return false; |
| 2710 | } |
| 2711 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2712 | toggleRadioOnOffForSubscriber(subId); |
| 2713 | } |
| 2714 | return true; |
| 2715 | } finally { |
| 2716 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2717 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2718 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2719 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2720 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2721 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2722 | /* |
| 2723 | * If any of the Radios are available, it will need to be |
| 2724 | * shutdown. So return true if any Radio is available. |
| 2725 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2726 | final long identity = Binder.clearCallingIdentity(); |
| 2727 | try { |
| 2728 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2729 | Phone phone = PhoneFactory.getPhone(i); |
| 2730 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2731 | } |
| 2732 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2733 | return false; |
| 2734 | } finally { |
| 2735 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2736 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2737 | } |
| 2738 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2739 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2740 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2741 | enforceModifyPermission(); |
| 2742 | |
| 2743 | final long identity = Binder.clearCallingIdentity(); |
| 2744 | try { |
| 2745 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2746 | logv("Shutting down Phone " + i); |
| 2747 | shutdownRadioUsingPhoneId(i); |
| 2748 | } |
| 2749 | } finally { |
| 2750 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2751 | } |
| 2752 | } |
| 2753 | |
| 2754 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2755 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2756 | if (phone != null && phone.isRadioAvailable()) { |
| 2757 | phone.shutdownRadio(); |
| 2758 | } |
| 2759 | } |
| 2760 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2761 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2762 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2763 | |
| 2764 | final long identity = Binder.clearCallingIdentity(); |
| 2765 | try { |
| 2766 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2767 | if (defaultPhone != null) { |
| 2768 | defaultPhone.setRadioPower(turnOn); |
| 2769 | return true; |
| 2770 | } else { |
| 2771 | loge("There's no default phone."); |
| 2772 | return false; |
| 2773 | } |
| 2774 | } finally { |
| 2775 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2776 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2777 | } |
| 2778 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2779 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2780 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2781 | |
| 2782 | final long identity = Binder.clearCallingIdentity(); |
| 2783 | try { |
| 2784 | final Phone phone = getPhone(subId); |
| 2785 | if (phone != null) { |
| 2786 | phone.setRadioPower(turnOn); |
| 2787 | return true; |
| 2788 | } else { |
| 2789 | return false; |
| 2790 | } |
| 2791 | } finally { |
| 2792 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2793 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2794 | } |
| 2795 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2796 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2797 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2798 | public boolean enableDataConnectivity() { |
| 2799 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2800 | |
| 2801 | final long identity = Binder.clearCallingIdentity(); |
| 2802 | try { |
| 2803 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2804 | final Phone phone = getPhone(subId); |
| 2805 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2806 | phone.getDataEnabledSettings().setDataEnabled( |
| 2807 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2808 | return true; |
| 2809 | } else { |
| 2810 | return false; |
| 2811 | } |
| 2812 | } finally { |
| 2813 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2814 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2815 | } |
| 2816 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2817 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2818 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2819 | public boolean disableDataConnectivity() { |
| 2820 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2821 | |
| 2822 | final long identity = Binder.clearCallingIdentity(); |
| 2823 | try { |
| 2824 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2825 | final Phone phone = getPhone(subId); |
| 2826 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2827 | phone.getDataEnabledSettings().setDataEnabled( |
| 2828 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2829 | return true; |
| 2830 | } else { |
| 2831 | return false; |
| 2832 | } |
| 2833 | } finally { |
| 2834 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2835 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2836 | } |
| 2837 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2838 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2839 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2840 | final long identity = Binder.clearCallingIdentity(); |
| 2841 | try { |
| 2842 | final Phone phone = getPhone(subId); |
| 2843 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2844 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2845 | } else { |
| 2846 | return false; |
| 2847 | } |
| 2848 | } finally { |
| 2849 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2850 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2851 | } |
| 2852 | |
| 2853 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2854 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2855 | } |
| 2856 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2857 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2858 | enforceCallPermission(); |
| 2859 | |
| 2860 | final long identity = Binder.clearCallingIdentity(); |
| 2861 | try { |
| 2862 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2863 | return; |
| 2864 | } |
| 2865 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2866 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2867 | } finally { |
| 2868 | Binder.restoreCallingIdentity(identity); |
| 2869 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2870 | }; |
| 2871 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2872 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2873 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2874 | |
| 2875 | final long identity = Binder.clearCallingIdentity(); |
| 2876 | try { |
| 2877 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2878 | return false; |
| 2879 | } |
| 2880 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2881 | } finally { |
| 2882 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2883 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2884 | } |
| 2885 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2886 | /** |
| 2887 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 2888 | * tag on getCallState Binder call. |
| 2889 | */ |
| 2890 | @Deprecated |
| 2891 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2892 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2893 | if (CompatChanges.isChangeEnabled( |
| 2894 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2895 | Binder.getCallingUid())) { |
| 2896 | // Do not allow this API to be called on API version 31+, it should only be |
| 2897 | // called on old apps using this Binder call directly. |
| 2898 | throw new SecurityException("This method can only be used for applications " |
| 2899 | + "targeting API version 30 or less."); |
| 2900 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2901 | final long identity = Binder.clearCallingIdentity(); |
| 2902 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2903 | Phone phone = getPhone(getDefaultSubscription()); |
| 2904 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2905 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2906 | } finally { |
| 2907 | Binder.restoreCallingIdentity(identity); |
| 2908 | } |
| 2909 | } |
| 2910 | |
| 2911 | @Override |
| 2912 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 2913 | if (CompatChanges.isChangeEnabled( |
| 2914 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2915 | Binder.getCallingUid())) { |
| 2916 | // Check READ_PHONE_STATE for API version 31+ |
| 2917 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2918 | featureId, "getCallStateForSubscription")) { |
| 2919 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 2920 | + "targeting API level 31+."); |
| 2921 | } |
| 2922 | } |
| 2923 | final long identity = Binder.clearCallingIdentity(); |
| 2924 | try { |
| 2925 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2926 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2927 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2928 | } finally { |
| 2929 | Binder.restoreCallingIdentity(identity); |
| 2930 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2931 | } |
| 2932 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2933 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2934 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2935 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2936 | } |
| 2937 | |
| 2938 | @Override |
| 2939 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2940 | final long identity = Binder.clearCallingIdentity(); |
| 2941 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2942 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2943 | if (phone != null) { |
Jack Yu | 2c45095 | 2021-11-29 11:36:17 -0800 | [diff] [blame] | 2944 | if (phone.isUsingNewDataStack()) { |
| 2945 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
| 2946 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2947 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2948 | } else { |
| 2949 | return PhoneConstantConversions.convertDataState( |
| 2950 | PhoneConstants.DataState.DISCONNECTED); |
| 2951 | } |
| 2952 | } finally { |
| 2953 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2954 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2955 | } |
| 2956 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2957 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2958 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2959 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2960 | } |
| 2961 | |
| 2962 | @Override |
| 2963 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2964 | final long identity = Binder.clearCallingIdentity(); |
| 2965 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2966 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2967 | if (phone != null) { |
| 2968 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2969 | } else { |
| 2970 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2971 | } |
| 2972 | } finally { |
| 2973 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2974 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2975 | } |
| 2976 | |
| 2977 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2978 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2979 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2980 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2981 | |
| 2982 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2983 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2984 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2985 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2986 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2987 | .setCallingPid(Binder.getCallingPid()) |
| 2988 | .setCallingUid(Binder.getCallingUid()) |
| 2989 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2990 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2991 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2992 | .build()); |
| 2993 | switch (locationResult) { |
| 2994 | case DENIED_HARD: |
| 2995 | throw new SecurityException("Not allowed to access cell location"); |
| 2996 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2997 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2998 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2999 | } |
| 3000 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3001 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3002 | final long identity = Binder.clearCallingIdentity(); |
| 3003 | try { |
| 3004 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3005 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3006 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3007 | } finally { |
| 3008 | Binder.restoreCallingIdentity(identity); |
| 3009 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3010 | } |
| 3011 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3012 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3013 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3014 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3015 | // registered cell info, so return a NULL country instead. |
| 3016 | final long identity = Binder.clearCallingIdentity(); |
| 3017 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3018 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3019 | // Get default phone in this case. |
| 3020 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3021 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3022 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3023 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3024 | if (phone == null) return ""; |
| 3025 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3026 | if (sst == null) return ""; |
| 3027 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3028 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3029 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3030 | } finally { |
| 3031 | Binder.restoreCallingIdentity(identity); |
| 3032 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3033 | } |
| 3034 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3035 | /** |
| 3036 | * This method was removed due to potential issues caused by performing partial |
| 3037 | * updates of service state, and lack of a credible use case. |
| 3038 | * |
| 3039 | * This has the ability to break the telephony implementation by disabling notification of |
| 3040 | * changes in device connectivity. DO NOT USE THIS! |
| 3041 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3042 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3043 | public void enableLocationUpdates() { |
| 3044 | mApp.enforceCallingOrSelfPermission( |
| 3045 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3046 | } |
| 3047 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3048 | /** |
| 3049 | * This method was removed due to potential issues caused by performing partial |
| 3050 | * updates of service state, and lack of a credible use case. |
| 3051 | * |
| 3052 | * This has the ability to break the telephony implementation by disabling notification of |
| 3053 | * changes in device connectivity. DO NOT USE THIS! |
| 3054 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3055 | @Override |
| 3056 | public void disableLocationUpdates() { |
| 3057 | mApp.enforceCallingOrSelfPermission( |
| 3058 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3059 | } |
| 3060 | |
| 3061 | @Override |
| 3062 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3063 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3064 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3065 | try { |
| 3066 | mApp.getSystemService(AppOpsManager.class) |
| 3067 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3068 | } catch (SecurityException e) { |
| 3069 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3070 | throw e; |
| 3071 | } |
| 3072 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3073 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3074 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3075 | throw new SecurityException( |
| 3076 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3077 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3078 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3079 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3080 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3081 | return null; |
| 3082 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3083 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3084 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3085 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3086 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3087 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3088 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3089 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3090 | for (CellInfo ci : info) { |
| 3091 | if (ci instanceof CellInfoGsm) { |
| 3092 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3093 | } else if (ci instanceof CellInfoWcdma) { |
| 3094 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3095 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3096 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3097 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3098 | } |
| 3099 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3100 | private List<CellInfo> getCachedCellInfo() { |
| 3101 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3102 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3103 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3104 | if (info != null) cellInfos.addAll(info); |
| 3105 | } |
| 3106 | return cellInfos; |
| 3107 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3108 | |
| 3109 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3110 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3111 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3112 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3113 | |
| 3114 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3115 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3116 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3117 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3118 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3119 | .setCallingPid(Binder.getCallingPid()) |
| 3120 | .setCallingUid(Binder.getCallingUid()) |
| 3121 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3122 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3123 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3124 | .build()); |
| 3125 | switch (locationResult) { |
| 3126 | case DENIED_HARD: |
| 3127 | throw new SecurityException("Not allowed to access cell info"); |
| 3128 | case DENIED_SOFT: |
| 3129 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3130 | } |
| 3131 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3132 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3133 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3134 | return getCachedCellInfo(); |
| 3135 | } |
| 3136 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3137 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3138 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3139 | final long identity = Binder.clearCallingIdentity(); |
| 3140 | try { |
| 3141 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3142 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3143 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3144 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3145 | if (info != null) cellInfos.addAll(info); |
| 3146 | } |
| 3147 | return cellInfos; |
| 3148 | } finally { |
| 3149 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3150 | } |
| 3151 | } |
| 3152 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3153 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3154 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3155 | String callingFeatureId) { |
| 3156 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3157 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3158 | } |
| 3159 | |
| 3160 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3161 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3162 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3163 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3164 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3165 | } |
| 3166 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3167 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3168 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3169 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3170 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3171 | |
| 3172 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3173 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3174 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3175 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3176 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3177 | .setCallingPid(Binder.getCallingPid()) |
| 3178 | .setCallingUid(Binder.getCallingUid()) |
| 3179 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3180 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3181 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3182 | .build()); |
| 3183 | switch (locationResult) { |
| 3184 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3185 | if (TelephonyPermissions |
| 3186 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3187 | // Safetynet logging for b/154934934 |
| 3188 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3189 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3190 | throw new SecurityException("Not allowed to access cell info"); |
| 3191 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3192 | if (TelephonyPermissions |
| 3193 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3194 | // Safetynet logging for b/154934934 |
| 3195 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3196 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3197 | try { |
| 3198 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3199 | } catch (RemoteException re) { |
| 3200 | // Drop without consequences |
| 3201 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3202 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3203 | } |
| 3204 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3205 | |
| 3206 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3207 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3208 | |
| 3209 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3210 | } |
| 3211 | |
| 3212 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3213 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3214 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3215 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3216 | |
| 3217 | final long identity = Binder.clearCallingIdentity(); |
| 3218 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3219 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3220 | } finally { |
| 3221 | Binder.restoreCallingIdentity(identity); |
| 3222 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3223 | } |
| 3224 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3225 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3226 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3227 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3228 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3229 | return null; |
| 3230 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3231 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3232 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3233 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3234 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3235 | return null; |
| 3236 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3237 | |
| 3238 | final long identity = Binder.clearCallingIdentity(); |
| 3239 | try { |
| 3240 | return phone.getImei(); |
| 3241 | } finally { |
| 3242 | Binder.restoreCallingIdentity(identity); |
| 3243 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3244 | } |
| 3245 | |
| 3246 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3247 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3248 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3249 | String tac = null; |
| 3250 | if (phone != null) { |
| 3251 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3252 | try { |
| 3253 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3254 | } catch (IndexOutOfBoundsException e) { |
| 3255 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3256 | return null; |
| 3257 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3258 | } |
| 3259 | return tac; |
| 3260 | } |
| 3261 | |
| 3262 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3263 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3264 | try { |
| 3265 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3266 | } catch (SecurityException se) { |
| 3267 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3268 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3269 | + Binder.getCallingUid()); |
| 3270 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3271 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3272 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3273 | return null; |
| 3274 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3275 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3276 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3277 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3278 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3279 | return null; |
| 3280 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3281 | |
| 3282 | final long identity = Binder.clearCallingIdentity(); |
| 3283 | try { |
| 3284 | return phone.getMeid(); |
| 3285 | } finally { |
| 3286 | Binder.restoreCallingIdentity(identity); |
| 3287 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3288 | } |
| 3289 | |
| 3290 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3291 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3292 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3293 | String manufacturerCode = null; |
| 3294 | if (phone != null) { |
| 3295 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3296 | try { |
| 3297 | manufacturerCode = |
| 3298 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3299 | } catch (IndexOutOfBoundsException e) { |
| 3300 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3301 | return null; |
| 3302 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3303 | } |
| 3304 | return manufacturerCode; |
| 3305 | } |
| 3306 | |
| 3307 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3308 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3309 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3310 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3311 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3312 | return null; |
| 3313 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3314 | int subId = phone.getSubId(); |
| 3315 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3316 | mApp, subId, callingPackage, callingFeatureId, |
| 3317 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3318 | return null; |
| 3319 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3320 | |
| 3321 | final long identity = Binder.clearCallingIdentity(); |
| 3322 | try { |
| 3323 | return phone.getDeviceSvn(); |
| 3324 | } finally { |
| 3325 | Binder.restoreCallingIdentity(identity); |
| 3326 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3327 | } |
| 3328 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3329 | @Override |
| 3330 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3331 | final long identity = Binder.clearCallingIdentity(); |
| 3332 | try { |
| 3333 | final Phone phone = getPhone(subId); |
| 3334 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3335 | } finally { |
| 3336 | Binder.restoreCallingIdentity(identity); |
| 3337 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3338 | } |
| 3339 | |
| 3340 | @Override |
| 3341 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3342 | final long identity = Binder.clearCallingIdentity(); |
| 3343 | try { |
| 3344 | final Phone phone = getPhone(subId); |
| 3345 | return phone == null ? null : phone.getCarrierName(); |
| 3346 | } finally { |
| 3347 | Binder.restoreCallingIdentity(identity); |
| 3348 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3349 | } |
| 3350 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3351 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3352 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3353 | final long identity = Binder.clearCallingIdentity(); |
| 3354 | try { |
| 3355 | final Phone phone = getPhone(subId); |
| 3356 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3357 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3358 | } finally { |
| 3359 | Binder.restoreCallingIdentity(identity); |
| 3360 | } |
| 3361 | } |
| 3362 | |
| 3363 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3364 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3365 | final long identity = Binder.clearCallingIdentity(); |
| 3366 | try { |
| 3367 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3368 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3369 | } finally { |
| 3370 | Binder.restoreCallingIdentity(identity); |
| 3371 | } |
| 3372 | } |
| 3373 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3374 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3375 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3376 | if (!isSubscriptionMccMnc) { |
| 3377 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3378 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3379 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3380 | if (phone == null) { |
| 3381 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3382 | } |
| 3383 | final long identity = Binder.clearCallingIdentity(); |
| 3384 | try { |
| 3385 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3386 | } finally { |
| 3387 | Binder.restoreCallingIdentity(identity); |
| 3388 | } |
| 3389 | } |
| 3390 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3391 | // |
| 3392 | // Internal helper methods. |
| 3393 | // |
| 3394 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3395 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3396 | * Make sure the caller is the calling package itself |
| 3397 | * |
| 3398 | * @throws SecurityException if the caller is not the calling package |
| 3399 | */ |
| 3400 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3401 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3402 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3403 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3404 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3405 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3406 | } catch (PackageManager.NameNotFoundException e) { |
| 3407 | // packageUid is -1 |
| 3408 | } |
| 3409 | if (packageUid != callingUid) { |
| 3410 | throw new SecurityException(message + ": Package " + callingPackage |
| 3411 | + " does not belong to " + callingUid); |
| 3412 | } |
| 3413 | } |
| 3414 | |
| 3415 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3416 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3417 | * |
| 3418 | * @throws SecurityException if the caller does not have the required permission |
| 3419 | */ |
| 3420 | private void enforceModifyPermission() { |
| 3421 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3422 | } |
| 3423 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3424 | private void enforceActiveEmergencySessionPermission() { |
| 3425 | mApp.enforceCallingOrSelfPermission( |
| 3426 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3427 | } |
| 3428 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3429 | /** |
| 3430 | * Make sure the caller has the CALL_PHONE permission. |
| 3431 | * |
| 3432 | * @throws SecurityException if the caller does not have the required permission |
| 3433 | */ |
| 3434 | private void enforceCallPermission() { |
| 3435 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3436 | } |
| 3437 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3438 | private void enforceSettingsPermission() { |
| 3439 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3440 | } |
| 3441 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3442 | private void enforceRebootPermission() { |
| 3443 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3444 | } |
| 3445 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3446 | private String createTelUrl(String number) { |
| 3447 | if (TextUtils.isEmpty(number)) { |
| 3448 | return null; |
| 3449 | } |
| 3450 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3451 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3452 | } |
| 3453 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3454 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3455 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3456 | } |
| 3457 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3458 | private static void logv(String msg) { |
| 3459 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3460 | } |
| 3461 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3462 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3463 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3464 | } |
| 3465 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3466 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3467 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3468 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3469 | } |
| 3470 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3471 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3472 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3473 | final long identity = Binder.clearCallingIdentity(); |
| 3474 | try { |
| 3475 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3476 | if (phone == null) { |
| 3477 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3478 | } else { |
| 3479 | return phone.getPhoneType(); |
| 3480 | } |
| 3481 | } finally { |
| 3482 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3483 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3484 | } |
| 3485 | |
| 3486 | /** |
| 3487 | * Returns the CDMA ERI icon index to display |
| 3488 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3489 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3490 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3491 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3492 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3493 | } |
| 3494 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3495 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3496 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3497 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3498 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3499 | mApp, subId, callingPackage, callingFeatureId, |
| 3500 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3501 | return -1; |
| 3502 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3503 | |
| 3504 | final long identity = Binder.clearCallingIdentity(); |
| 3505 | try { |
| 3506 | final Phone phone = getPhone(subId); |
| 3507 | if (phone != null) { |
| 3508 | return phone.getCdmaEriIconIndex(); |
| 3509 | } else { |
| 3510 | return -1; |
| 3511 | } |
| 3512 | } finally { |
| 3513 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3514 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3515 | } |
| 3516 | |
| 3517 | /** |
| 3518 | * Returns the CDMA ERI icon mode, |
| 3519 | * 0 - ON |
| 3520 | * 1 - FLASHING |
| 3521 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3522 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3523 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3524 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3525 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3526 | } |
| 3527 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3528 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3529 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3530 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3531 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3532 | mApp, subId, callingPackage, callingFeatureId, |
| 3533 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3534 | return -1; |
| 3535 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3536 | |
| 3537 | final long identity = Binder.clearCallingIdentity(); |
| 3538 | try { |
| 3539 | final Phone phone = getPhone(subId); |
| 3540 | if (phone != null) { |
| 3541 | return phone.getCdmaEriIconMode(); |
| 3542 | } else { |
| 3543 | return -1; |
| 3544 | } |
| 3545 | } finally { |
| 3546 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3547 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3548 | } |
| 3549 | |
| 3550 | /** |
| 3551 | * Returns the CDMA ERI text, |
| 3552 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3553 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3554 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3555 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3556 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3557 | } |
| 3558 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3559 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3560 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3561 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3562 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3563 | mApp, subId, callingPackage, callingFeatureId, |
| 3564 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3565 | return null; |
| 3566 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3567 | |
| 3568 | final long identity = Binder.clearCallingIdentity(); |
| 3569 | try { |
| 3570 | final Phone phone = getPhone(subId); |
| 3571 | if (phone != null) { |
| 3572 | return phone.getCdmaEriText(); |
| 3573 | } else { |
| 3574 | return null; |
| 3575 | } |
| 3576 | } finally { |
| 3577 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3578 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3579 | } |
| 3580 | |
| 3581 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3582 | * Returns the CDMA MDN. |
| 3583 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3584 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3585 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3586 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3587 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3588 | |
| 3589 | final long identity = Binder.clearCallingIdentity(); |
| 3590 | try { |
| 3591 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3592 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3593 | return phone.getLine1Number(); |
| 3594 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3595 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3596 | return null; |
| 3597 | } |
| 3598 | } finally { |
| 3599 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3600 | } |
| 3601 | } |
| 3602 | |
| 3603 | /** |
| 3604 | * Returns the CDMA MIN. |
| 3605 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3606 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3607 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3608 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3609 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3610 | |
| 3611 | final long identity = Binder.clearCallingIdentity(); |
| 3612 | try { |
| 3613 | final Phone phone = getPhone(subId); |
| 3614 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3615 | return phone.getCdmaMin(); |
| 3616 | } else { |
| 3617 | return null; |
| 3618 | } |
| 3619 | } finally { |
| 3620 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3621 | } |
| 3622 | } |
| 3623 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3624 | @Override |
| 3625 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3626 | INumberVerificationCallback callback, String callingPackage) { |
| 3627 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3628 | != PERMISSION_GRANTED) { |
| 3629 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3630 | } |
| 3631 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3632 | |
| 3633 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3634 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3635 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3636 | + "calling package: " + callingPackage |
| 3637 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3638 | } |
| 3639 | |
| 3640 | if (range == null) { |
| 3641 | throw new NullPointerException("Range must be non-null"); |
| 3642 | } |
| 3643 | |
| 3644 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3645 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3646 | |
| 3647 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3648 | } |
| 3649 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3650 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3651 | * Returns true if CDMA provisioning needs to run. |
| 3652 | */ |
| 3653 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3654 | final long identity = Binder.clearCallingIdentity(); |
| 3655 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3656 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3657 | } finally { |
| 3658 | Binder.restoreCallingIdentity(identity); |
| 3659 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3660 | } |
| 3661 | |
| 3662 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3663 | * Sets the voice mail number of a given subId. |
| 3664 | */ |
| 3665 | @Override |
| 3666 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3667 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3668 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3669 | |
| 3670 | final long identity = Binder.clearCallingIdentity(); |
| 3671 | try { |
| 3672 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3673 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3674 | return success; |
| 3675 | } finally { |
| 3676 | Binder.restoreCallingIdentity(identity); |
| 3677 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3678 | } |
| 3679 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3680 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3681 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3682 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3683 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3684 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3685 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3686 | throw new SecurityException("caller must be system dialer"); |
| 3687 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3688 | |
| 3689 | final long identity = Binder.clearCallingIdentity(); |
| 3690 | try { |
| 3691 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3692 | if (phoneAccountHandle == null) { |
| 3693 | return null; |
| 3694 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3695 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3696 | } finally { |
| 3697 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3698 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3699 | } |
| 3700 | |
| 3701 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3702 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3703 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3704 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3705 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3706 | mApp, subId, callingPackage, callingFeatureId, |
| 3707 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3708 | return null; |
| 3709 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3710 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3711 | final long identity = Binder.clearCallingIdentity(); |
| 3712 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3713 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3714 | } finally { |
| 3715 | Binder.restoreCallingIdentity(identity); |
| 3716 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3717 | } |
| 3718 | |
| 3719 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3720 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3721 | VisualVoicemailSmsFilterSettings settings) { |
| 3722 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3723 | |
| 3724 | final long identity = Binder.clearCallingIdentity(); |
| 3725 | try { |
| 3726 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3727 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3728 | } finally { |
| 3729 | Binder.restoreCallingIdentity(identity); |
| 3730 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3731 | } |
| 3732 | |
| 3733 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3734 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3735 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3736 | |
| 3737 | final long identity = Binder.clearCallingIdentity(); |
| 3738 | try { |
| 3739 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3740 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3741 | } finally { |
| 3742 | Binder.restoreCallingIdentity(identity); |
| 3743 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3744 | } |
| 3745 | |
| 3746 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3747 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3748 | String callingPackage, int subId) { |
| 3749 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3750 | |
| 3751 | final long identity = Binder.clearCallingIdentity(); |
| 3752 | try { |
| 3753 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3754 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3755 | } finally { |
| 3756 | Binder.restoreCallingIdentity(identity); |
| 3757 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3758 | } |
| 3759 | |
| 3760 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3761 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3762 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3763 | |
| 3764 | final long identity = Binder.clearCallingIdentity(); |
| 3765 | try { |
| 3766 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3767 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3768 | } finally { |
| 3769 | Binder.restoreCallingIdentity(identity); |
| 3770 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3771 | } |
| 3772 | |
| 3773 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3774 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3775 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3776 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3777 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3778 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3779 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3780 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3781 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3782 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3783 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3784 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3785 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3786 | * Sets the voice activation state of a given subId. |
| 3787 | */ |
| 3788 | @Override |
| 3789 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3790 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3791 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3792 | |
| 3793 | final long identity = Binder.clearCallingIdentity(); |
| 3794 | try { |
| 3795 | final Phone phone = getPhone(subId); |
| 3796 | if (phone != null) { |
| 3797 | phone.setVoiceActivationState(activationState); |
| 3798 | } else { |
| 3799 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3800 | } |
| 3801 | } finally { |
| 3802 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3803 | } |
| 3804 | } |
| 3805 | |
| 3806 | /** |
| 3807 | * Sets the data activation state of a given subId. |
| 3808 | */ |
| 3809 | @Override |
| 3810 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3811 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3812 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3813 | |
| 3814 | final long identity = Binder.clearCallingIdentity(); |
| 3815 | try { |
| 3816 | final Phone phone = getPhone(subId); |
| 3817 | if (phone != null) { |
| 3818 | phone.setDataActivationState(activationState); |
| 3819 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3820 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3821 | } |
| 3822 | } finally { |
| 3823 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3824 | } |
| 3825 | } |
| 3826 | |
| 3827 | /** |
| 3828 | * Returns the voice activation state of a given subId. |
| 3829 | */ |
| 3830 | @Override |
| 3831 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3832 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3833 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3834 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3835 | final long identity = Binder.clearCallingIdentity(); |
| 3836 | try { |
| 3837 | if (phone != null) { |
| 3838 | return phone.getVoiceActivationState(); |
| 3839 | } else { |
| 3840 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3841 | } |
| 3842 | } finally { |
| 3843 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3844 | } |
| 3845 | } |
| 3846 | |
| 3847 | /** |
| 3848 | * Returns the data activation state of a given subId. |
| 3849 | */ |
| 3850 | @Override |
| 3851 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3852 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3853 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3854 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3855 | final long identity = Binder.clearCallingIdentity(); |
| 3856 | try { |
| 3857 | if (phone != null) { |
| 3858 | return phone.getDataActivationState(); |
| 3859 | } else { |
| 3860 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3861 | } |
| 3862 | } finally { |
| 3863 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3864 | } |
| 3865 | } |
| 3866 | |
| 3867 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3868 | * Returns the unread count of voicemails for a subId |
| 3869 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3870 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3871 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3872 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3873 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3874 | mApp, subId, callingPackage, callingFeatureId, |
| 3875 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3876 | return 0; |
| 3877 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3878 | final long identity = Binder.clearCallingIdentity(); |
| 3879 | try { |
| 3880 | final Phone phone = getPhone(subId); |
| 3881 | if (phone != null) { |
| 3882 | return phone.getVoiceMessageCount(); |
| 3883 | } else { |
| 3884 | return 0; |
| 3885 | } |
| 3886 | } finally { |
| 3887 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3888 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3889 | } |
| 3890 | |
| 3891 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3892 | * returns true, if the device is in a state where both voice and data |
| 3893 | * are supported simultaneously. This can change based on location or network condition. |
| 3894 | */ |
| 3895 | @Override |
| 3896 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3897 | final long identity = Binder.clearCallingIdentity(); |
| 3898 | try { |
| 3899 | final Phone phone = getPhone(subId); |
| 3900 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3901 | } finally { |
| 3902 | Binder.restoreCallingIdentity(identity); |
| 3903 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3904 | } |
| 3905 | |
| 3906 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3907 | * Send the dialer code if called from the current default dialer or the caller has |
| 3908 | * carrier privilege. |
| 3909 | * @param inputCode The dialer code to send |
| 3910 | */ |
| 3911 | @Override |
| 3912 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3913 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3914 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3915 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3916 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3917 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3918 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3919 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3920 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3921 | |
| 3922 | final long identity = Binder.clearCallingIdentity(); |
| 3923 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3924 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3925 | } finally { |
| 3926 | Binder.restoreCallingIdentity(identity); |
| 3927 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3928 | } |
| 3929 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3930 | @Override |
| 3931 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3932 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3933 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3934 | mApp, subId, "getNetworkSelectionMode"); |
| 3935 | final long identity = Binder.clearCallingIdentity(); |
| 3936 | try { |
| 3937 | if (!isActiveSubscription(subId)) { |
| 3938 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3939 | } |
| 3940 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3941 | } finally { |
| 3942 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3943 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3944 | } |
| 3945 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3946 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3947 | public boolean isInEmergencySmsMode() { |
| 3948 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3949 | final long identity = Binder.clearCallingIdentity(); |
| 3950 | try { |
| 3951 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3952 | if (phone.isInEmergencySmsMode()) { |
| 3953 | return true; |
| 3954 | } |
| 3955 | } |
| 3956 | } finally { |
| 3957 | Binder.restoreCallingIdentity(identity); |
| 3958 | } |
| 3959 | return false; |
| 3960 | } |
| 3961 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3962 | /** |
| 3963 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3964 | * @param subId The subscription to use to check the configuration. |
| 3965 | * @param c The callback that will be used to send the result. |
| 3966 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3967 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3968 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3969 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3970 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3971 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3972 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3973 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3974 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3975 | "IMS not available on device."); |
| 3976 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3977 | final long token = Binder.clearCallingIdentity(); |
| 3978 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 3979 | int slotId = getSlotIndexOrException(subId); |
| 3980 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 3981 | ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3982 | } catch (ImsException e) { |
| 3983 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3984 | } finally { |
| 3985 | Binder.restoreCallingIdentity(token); |
| 3986 | } |
| 3987 | } |
| 3988 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3989 | /** |
| 3990 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3991 | * @param subId The subscription to use to check the configuration. |
| 3992 | * @param c The callback that will be used to send the result. |
| 3993 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3994 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3995 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3996 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3997 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3998 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3999 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4000 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4001 | final long token = Binder.clearCallingIdentity(); |
| 4002 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4003 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 4004 | .removeRegistrationCallbackForSubscription(c, subId); |
| 4005 | } catch (ImsException e) { |
| 4006 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4007 | + "is inactive, ignoring unregister."); |
| 4008 | // If the subscription is no longer active, just return, since the callback |
| 4009 | // will already have been removed internally. |
| 4010 | } finally { |
| 4011 | Binder.restoreCallingIdentity(token); |
| 4012 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4013 | } |
| 4014 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4015 | /** |
| 4016 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4017 | */ |
| 4018 | @Override |
| 4019 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4020 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4021 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4022 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4023 | "IMS not available on device."); |
| 4024 | } |
| 4025 | final long token = Binder.clearCallingIdentity(); |
| 4026 | try { |
| 4027 | Phone phone = getPhone(subId); |
| 4028 | if (phone == null) { |
| 4029 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4030 | + subId + "'"); |
| 4031 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4032 | } |
| 4033 | phone.getImsRegistrationState(regState -> { |
| 4034 | try { |
| 4035 | consumer.accept((regState == null) |
| 4036 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4037 | } catch (RemoteException e) { |
| 4038 | // Ignore if the remote process is no longer available to call back. |
| 4039 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4040 | } |
| 4041 | }); |
| 4042 | } finally { |
| 4043 | Binder.restoreCallingIdentity(token); |
| 4044 | } |
| 4045 | } |
| 4046 | |
| 4047 | /** |
| 4048 | * Get the transport type for the IMS service registration state. |
| 4049 | */ |
| 4050 | @Override |
| 4051 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4052 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4053 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4054 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4055 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4056 | "IMS not available on device."); |
| 4057 | } |
| 4058 | final long token = Binder.clearCallingIdentity(); |
| 4059 | try { |
| 4060 | Phone phone = getPhone(subId); |
| 4061 | if (phone == null) { |
| 4062 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4063 | + subId + "'"); |
| 4064 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4065 | } |
| 4066 | phone.getImsRegistrationTech(regTech -> { |
| 4067 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4068 | int regTechConverted = (regTech == null) |
| 4069 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4070 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4071 | regTechConverted); |
| 4072 | try { |
| 4073 | consumer.accept(regTechConverted); |
| 4074 | } catch (RemoteException e) { |
| 4075 | // Ignore if the remote process is no longer available to call back. |
| 4076 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4077 | } |
| 4078 | }); |
| 4079 | } finally { |
| 4080 | Binder.restoreCallingIdentity(token); |
| 4081 | } |
| 4082 | } |
| 4083 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4084 | /** |
| 4085 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4086 | * @param subId The subscription to use to check the configuration. |
| 4087 | * @param c The callback that will be used to send the result. |
| 4088 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4089 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4090 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4091 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4092 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4093 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4094 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4095 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4096 | "IMS not available on device."); |
| 4097 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4098 | final long token = Binder.clearCallingIdentity(); |
| 4099 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4100 | int slotId = getSlotIndexOrException(subId); |
| 4101 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4102 | ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4103 | } catch (ImsException e) { |
| 4104 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4105 | } finally { |
| 4106 | Binder.restoreCallingIdentity(token); |
| 4107 | } |
| 4108 | } |
| 4109 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4110 | /** |
| 4111 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4112 | * @param subId The subscription to use to check the configuration. |
| 4113 | * @param c The callback that will be used to send the result. |
| 4114 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4115 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4116 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4117 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4118 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4119 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4120 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4121 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4122 | |
| 4123 | final long token = Binder.clearCallingIdentity(); |
| 4124 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4125 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4126 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4127 | } catch (ImsException e) { |
| 4128 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4129 | + "is inactive, ignoring unregister."); |
| 4130 | // If the subscription is no longer active, just return, since the callback |
| 4131 | // will already have been removed internally. |
| 4132 | } finally { |
| 4133 | Binder.restoreCallingIdentity(token); |
| 4134 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4135 | } |
| 4136 | |
| 4137 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4138 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4139 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4140 | final long token = Binder.clearCallingIdentity(); |
| 4141 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4142 | int slotId = getSlotIndexOrException(subId); |
| 4143 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4144 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4145 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4146 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4147 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4148 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4149 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4150 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4151 | } finally { |
| 4152 | Binder.restoreCallingIdentity(token); |
| 4153 | } |
| 4154 | } |
| 4155 | |
| 4156 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4157 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4158 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4159 | final long token = Binder.clearCallingIdentity(); |
| 4160 | try { |
| 4161 | Phone phone = getPhone(subId); |
| 4162 | if (phone == null) return false; |
| 4163 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4164 | } catch (com.android.ims.ImsException e) { |
| 4165 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4166 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4167 | } finally { |
| 4168 | Binder.restoreCallingIdentity(token); |
| 4169 | } |
| 4170 | } |
| 4171 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4172 | /** |
| 4173 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4174 | * subscription. |
| 4175 | * @param subId The subscription to use to check the configuration. |
| 4176 | * @param callback The callback that will be used to send the result. |
| 4177 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4178 | * @param transportType The transport type of the MmTelFeature capability. |
| 4179 | */ |
| 4180 | @Override |
| 4181 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4182 | int transportType) { |
| 4183 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 4184 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4185 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4186 | "IMS not available on device."); |
| 4187 | } |
| 4188 | final long token = Binder.clearCallingIdentity(); |
| 4189 | try { |
| 4190 | int slotId = getSlotIndex(subId); |
| 4191 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4192 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4193 | + subId + "'"); |
| 4194 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4195 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4196 | verifyImsMmTelConfiguredOrThrow(slotId); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4197 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4198 | transportType, aBoolean -> { |
| 4199 | try { |
| 4200 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4201 | } catch (RemoteException e) { |
| 4202 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4203 | + "running. Ignore"); |
| 4204 | } |
| 4205 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4206 | } catch (ImsException e) { |
| 4207 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4208 | } finally { |
| 4209 | Binder.restoreCallingIdentity(token); |
| 4210 | } |
| 4211 | } |
| 4212 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4213 | /** |
| 4214 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4215 | * @param subId The subscription to use to check the configuration. |
| 4216 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4217 | @Override |
| 4218 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4219 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4220 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4221 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4222 | final long token = Binder.clearCallingIdentity(); |
| 4223 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4224 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4225 | // 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] | 4226 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4227 | } catch (ImsException e) { |
| 4228 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4229 | } finally { |
| 4230 | Binder.restoreCallingIdentity(token); |
| 4231 | } |
| 4232 | } |
| 4233 | |
| 4234 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4235 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4236 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4237 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4238 | final long identity = Binder.clearCallingIdentity(); |
| 4239 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4240 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4241 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4242 | // 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] | 4243 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4244 | } catch (ImsException e) { |
| 4245 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4246 | } finally { |
| 4247 | Binder.restoreCallingIdentity(identity); |
| 4248 | } |
| 4249 | } |
| 4250 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4251 | /** |
| 4252 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4253 | * @param subId The subscription to use to check the configuration. |
| 4254 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4255 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4256 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4257 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4258 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4259 | final long identity = Binder.clearCallingIdentity(); |
| 4260 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4261 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4262 | // 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] | 4263 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4264 | } catch (ImsException e) { |
| 4265 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4266 | } finally { |
| 4267 | Binder.restoreCallingIdentity(identity); |
| 4268 | } |
| 4269 | } |
| 4270 | |
| 4271 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4272 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4273 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4274 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4275 | final long identity = Binder.clearCallingIdentity(); |
| 4276 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4277 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4278 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4279 | // 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] | 4280 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4281 | } catch (ImsException e) { |
| 4282 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4283 | } finally { |
| 4284 | Binder.restoreCallingIdentity(identity); |
| 4285 | } |
| 4286 | } |
| 4287 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4288 | /** |
| 4289 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4290 | * @param subId The subscription to use to check the configuration. |
| 4291 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4292 | @Override |
| 4293 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4294 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4295 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4296 | final long identity = Binder.clearCallingIdentity(); |
| 4297 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4298 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4299 | // 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] | 4300 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4301 | } catch (ImsException e) { |
| 4302 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4303 | } finally { |
| 4304 | Binder.restoreCallingIdentity(identity); |
| 4305 | } |
| 4306 | } |
| 4307 | |
| 4308 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4309 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4310 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4311 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4312 | final long identity = Binder.clearCallingIdentity(); |
| 4313 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4314 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4315 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4316 | // 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] | 4317 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4318 | } catch (ImsException e) { |
| 4319 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4320 | } finally { |
| 4321 | Binder.restoreCallingIdentity(identity); |
| 4322 | } |
| 4323 | } |
| 4324 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4325 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4326 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4327 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4328 | * @param subId The subscription to use to check the configuration. |
| 4329 | */ |
| 4330 | @Override |
| 4331 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4332 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4333 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4334 | final long identity = Binder.clearCallingIdentity(); |
| 4335 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4336 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4337 | // 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] | 4338 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4339 | } catch (ImsException e) { |
| 4340 | throw new ServiceSpecificException(e.getCode()); |
| 4341 | } finally { |
| 4342 | Binder.restoreCallingIdentity(identity); |
| 4343 | } |
| 4344 | } |
| 4345 | |
| 4346 | /** |
| 4347 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4348 | * Requires MODIFY_PHONE_STATE permission. |
| 4349 | * @param subId The subscription to use to check the configuration. |
| 4350 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4351 | * false otherwise |
| 4352 | */ |
| 4353 | @Override |
| 4354 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4355 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4356 | "setCrossSimCallingEnabled"); |
| 4357 | final long identity = Binder.clearCallingIdentity(); |
| 4358 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4359 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4360 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4361 | // 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] | 4362 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4363 | } catch (ImsException e) { |
| 4364 | throw new ServiceSpecificException(e.getCode()); |
| 4365 | } finally { |
| 4366 | Binder.restoreCallingIdentity(identity); |
| 4367 | } |
| 4368 | } |
| 4369 | |
| 4370 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4371 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4372 | * @param subId The subscription to use to check the configuration. |
| 4373 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4374 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4375 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4376 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4377 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4378 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4379 | final long identity = Binder.clearCallingIdentity(); |
| 4380 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4381 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4382 | // 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] | 4383 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
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 | |
| 4391 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4392 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4393 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4394 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4395 | final long identity = Binder.clearCallingIdentity(); |
| 4396 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4397 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4398 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4399 | // 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] | 4400 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4401 | } catch (ImsException e) { |
| 4402 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4403 | } finally { |
| 4404 | Binder.restoreCallingIdentity(identity); |
| 4405 | } |
| 4406 | } |
| 4407 | |
| 4408 | @Override |
| 4409 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4410 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4411 | "setVoWiFiNonPersistent"); |
| 4412 | final long identity = Binder.clearCallingIdentity(); |
| 4413 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4414 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4415 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4416 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4417 | } catch (ImsException e) { |
| 4418 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4419 | } finally { |
| 4420 | Binder.restoreCallingIdentity(identity); |
| 4421 | } |
| 4422 | } |
| 4423 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4424 | /** |
| 4425 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4426 | * @param subId The subscription to use to check the configuration. |
| 4427 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4428 | @Override |
| 4429 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4430 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4431 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4432 | final long identity = Binder.clearCallingIdentity(); |
| 4433 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4434 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4435 | // 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] | 4436 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4437 | } catch (ImsException e) { |
| 4438 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4439 | } finally { |
| 4440 | Binder.restoreCallingIdentity(identity); |
| 4441 | } |
| 4442 | } |
| 4443 | |
| 4444 | @Override |
| 4445 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4446 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4447 | "setVoWiFiModeSetting"); |
| 4448 | final long identity = Binder.clearCallingIdentity(); |
| 4449 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4450 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4451 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4452 | // 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] | 4453 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4454 | } catch (ImsException e) { |
| 4455 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4456 | } finally { |
| 4457 | Binder.restoreCallingIdentity(identity); |
| 4458 | } |
| 4459 | } |
| 4460 | |
| 4461 | @Override |
| 4462 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4463 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4464 | final long identity = Binder.clearCallingIdentity(); |
| 4465 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4466 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4467 | // 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] | 4468 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4469 | } catch (ImsException e) { |
| 4470 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4471 | } finally { |
| 4472 | Binder.restoreCallingIdentity(identity); |
| 4473 | } |
| 4474 | } |
| 4475 | |
| 4476 | @Override |
| 4477 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4478 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4479 | "setVoWiFiRoamingModeSetting"); |
| 4480 | final long identity = Binder.clearCallingIdentity(); |
| 4481 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4482 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4483 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4484 | // 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] | 4485 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4486 | } catch (ImsException e) { |
| 4487 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4488 | } finally { |
| 4489 | Binder.restoreCallingIdentity(identity); |
| 4490 | } |
| 4491 | } |
| 4492 | |
| 4493 | @Override |
| 4494 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4495 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4496 | "setRttCapabilityEnabled"); |
| 4497 | final long identity = Binder.clearCallingIdentity(); |
| 4498 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4499 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4500 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4501 | // 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] | 4502 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
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 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4510 | /** |
| 4511 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4512 | * @param subId The subscription to use to check the configuration. |
| 4513 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4514 | @Override |
| 4515 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4516 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4517 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4518 | final long identity = Binder.clearCallingIdentity(); |
| 4519 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4520 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4521 | // 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] | 4522 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4523 | } catch (ImsException e) { |
| 4524 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4525 | } finally { |
| 4526 | Binder.restoreCallingIdentity(identity); |
| 4527 | } |
| 4528 | } |
| 4529 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4530 | @Override |
| 4531 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4532 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4533 | final long identity = Binder.clearCallingIdentity(); |
| 4534 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4535 | if (!isImsAvailableOnDevice()) { |
| 4536 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4537 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4538 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4539 | int slotId = getSlotIndexOrException(subId); |
| 4540 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4541 | ImsManager.getInstance(mApp, slotId) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4542 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4543 | } catch (ImsException e) { |
| 4544 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4545 | } finally { |
| 4546 | Binder.restoreCallingIdentity(identity); |
| 4547 | } |
| 4548 | } |
| 4549 | |
| 4550 | @Override |
| 4551 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4552 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4553 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4554 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4555 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4556 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4557 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4558 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4559 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4560 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4561 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4562 | + "is inactive, ignoring unregister."); |
| 4563 | // If the subscription is no longer active, just return, since the callback will already |
| 4564 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4565 | } finally { |
| 4566 | Binder.restoreCallingIdentity(identity); |
| 4567 | } |
| 4568 | } |
| 4569 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4570 | |
| 4571 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4572 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4573 | message); |
| 4574 | } |
| 4575 | |
| 4576 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4577 | boolean isMmtelCapability) { |
| 4578 | Phone phone = getPhone(subId); |
| 4579 | if (phone == null) { |
| 4580 | loge("phone instance null for subid " + subId); |
| 4581 | return false; |
| 4582 | } |
| 4583 | if (isMmtelCapability) { |
| 4584 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4585 | return false; |
| 4586 | } |
| 4587 | } else { |
| 4588 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4589 | return false; |
| 4590 | } |
| 4591 | } |
| 4592 | return true; |
| 4593 | } |
| 4594 | |
| 4595 | @Override |
| 4596 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4597 | boolean isProvisioned) { |
| 4598 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4599 | |
| 4600 | final long identity = Binder.clearCallingIdentity(); |
| 4601 | try { |
| 4602 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4603 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4604 | return; |
| 4605 | } |
| 4606 | |
| 4607 | // this capability requires provisioning, route to the correct API. |
| 4608 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4609 | switch (capability) { |
| 4610 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4611 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4612 | ims.setEabProvisioned(isProvisioned); |
| 4613 | break; |
| 4614 | default: { |
| 4615 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4616 | + "rcs capability '" + capability + "', which does not require " |
| 4617 | + "provisioning."); |
| 4618 | } |
| 4619 | } |
| 4620 | } finally { |
| 4621 | Binder.restoreCallingIdentity(identity); |
| 4622 | } |
| 4623 | |
| 4624 | } |
| 4625 | |
| 4626 | |
| 4627 | @Override |
| 4628 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4629 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4630 | final long identity = Binder.clearCallingIdentity(); |
| 4631 | try { |
| 4632 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4633 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4634 | return true; |
| 4635 | } |
| 4636 | |
| 4637 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4638 | switch (capability) { |
| 4639 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4640 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4641 | return ims.isEabProvisionedOnDevice(); |
| 4642 | |
| 4643 | default: { |
| 4644 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4645 | + "capability '" + capability + "', which does not require " |
| 4646 | + "provisioning."); |
| 4647 | } |
| 4648 | } |
| 4649 | |
| 4650 | } finally { |
| 4651 | Binder.restoreCallingIdentity(identity); |
| 4652 | } |
| 4653 | } |
| 4654 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4655 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4656 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4657 | boolean isProvisioned) { |
| 4658 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4659 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE |
| 4660 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4661 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4662 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4663 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4664 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4665 | final long identity = Binder.clearCallingIdentity(); |
| 4666 | try { |
| 4667 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4668 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4669 | return; |
| 4670 | } |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4671 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4672 | || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
| 4673 | loge("setImsProvisioningStatusForCapability: called for technology that does " |
| 4674 | + "not support provisioning - " + tech); |
| 4675 | return; |
| 4676 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4677 | |
| 4678 | // this capability requires provisioning, route to the correct API. |
| 4679 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4680 | switch (capability) { |
| 4681 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4682 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4683 | ims.setVolteProvisioned(isProvisioned); |
| 4684 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4685 | ims.setWfcProvisioned(isProvisioned); |
| 4686 | } |
| 4687 | break; |
| 4688 | } |
| 4689 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4690 | // There is currently no difference in VT provisioning type. |
| 4691 | ims.setVtProvisioned(isProvisioned); |
| 4692 | break; |
| 4693 | } |
| 4694 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4695 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4696 | // change the capability of the feature instead if needed. |
| 4697 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4698 | == isProvisioned) { |
| 4699 | // No change in provisioning. |
| 4700 | return; |
| 4701 | } |
| 4702 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4703 | try { |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4704 | ims.changeMmTelCapability(isProvisioned, capability, tech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4705 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4706 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4707 | + ", Exception" + e.getMessage()); |
| 4708 | } |
| 4709 | break; |
| 4710 | } |
| 4711 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4712 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4713 | + "MmTel capability '" + capability + "', which does not require " |
| 4714 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4715 | } |
| 4716 | } |
| 4717 | |
| 4718 | } finally { |
| 4719 | Binder.restoreCallingIdentity(identity); |
| 4720 | } |
| 4721 | } |
| 4722 | |
| 4723 | @Override |
| 4724 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4725 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4726 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE |
| 4727 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4728 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4729 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4730 | } |
| 4731 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4732 | final long identity = Binder.clearCallingIdentity(); |
| 4733 | try { |
| 4734 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4735 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4736 | return true; |
| 4737 | } |
| 4738 | |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4739 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4740 | || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
| 4741 | loge("getImsProvisioningStatusForCapability: called for technology that does " |
| 4742 | + "not support provisioning - " + tech); |
| 4743 | return true; |
| 4744 | } |
| 4745 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4746 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4747 | switch (capability) { |
| 4748 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4749 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4750 | return ims.isVolteProvisionedOnDevice(); |
| 4751 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4752 | return ims.isWfcProvisionedOnDevice(); |
| 4753 | } |
| 4754 | // This should never happen, since we are checking tech above to make sure it |
| 4755 | // is either LTE or IWLAN. |
| 4756 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4757 | + "capability."); |
| 4758 | } |
| 4759 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4760 | // There is currently no difference in VT provisioning type. |
| 4761 | return ims.isVtProvisionedOnDevice(); |
| 4762 | } |
| 4763 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4764 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4765 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4766 | } |
| 4767 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4768 | throw new IllegalArgumentException( |
| 4769 | "Tried to get provisioning for MmTel capability '" + capability |
| 4770 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4771 | } |
| 4772 | } |
| 4773 | |
| 4774 | } finally { |
| 4775 | Binder.restoreCallingIdentity(identity); |
| 4776 | } |
| 4777 | } |
| 4778 | |
| 4779 | @Override |
| 4780 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4781 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4782 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4783 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4784 | } |
| 4785 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4786 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4787 | return (provisionedBits & capability) > 0; |
| 4788 | } |
| 4789 | |
| 4790 | @Override |
| 4791 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4792 | boolean isProvisioned) { |
| 4793 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4794 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4795 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4796 | } |
| 4797 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4798 | "setProvisioningStatusForCapability"); |
| 4799 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4800 | // If the current provisioning status for capability already matches isProvisioned, |
| 4801 | // do nothing. |
| 4802 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4803 | return; |
| 4804 | } |
| 4805 | if (isProvisioned) { |
| 4806 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4807 | } else { |
| 4808 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4809 | } |
| 4810 | } |
| 4811 | |
| 4812 | /** |
| 4813 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4814 | * technology. The bitfield should mirror the bitfield defined by |
| 4815 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4816 | */ |
| 4817 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4818 | String key = getMmTelProvisioningKey(subId, tech); |
| 4819 | // Default is no capabilities are provisioned. |
| 4820 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4821 | } |
| 4822 | |
| 4823 | /** |
| 4824 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4825 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4826 | * technology specified. |
| 4827 | * |
| 4828 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4829 | */ |
| 4830 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4831 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4832 | String key = getMmTelProvisioningKey(subId, tech); |
| 4833 | editor.putInt(key, newField); |
| 4834 | editor.commit(); |
| 4835 | } |
| 4836 | |
| 4837 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4838 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4839 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4840 | } |
| 4841 | |
| 4842 | /** |
| 4843 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4844 | * carrier associated with the subscription id. |
| 4845 | */ |
| 4846 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4847 | int capability) { |
| 4848 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4849 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4850 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4851 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4852 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4853 | false); |
| 4854 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4855 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4856 | |
| 4857 | // First check to make sure that the capability requires provisioning. |
| 4858 | switch (capability) { |
| 4859 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4860 | // intentional fallthrough |
| 4861 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4862 | if (requireVoiceVtProvisioning) { |
| 4863 | // Voice and Video requires provisioning |
| 4864 | return true; |
| 4865 | } |
| 4866 | break; |
| 4867 | } |
| 4868 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4869 | if (requireUtProvisioning) { |
| 4870 | // UT requires provisioning |
| 4871 | return true; |
| 4872 | } |
| 4873 | break; |
| 4874 | } |
| 4875 | } |
| 4876 | return false; |
| 4877 | } |
| 4878 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4879 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4880 | int capability) { |
| 4881 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4882 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4883 | |
| 4884 | boolean requireRcsProvisioning = c.getBoolean( |
| 4885 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4886 | |
| 4887 | // First check to make sure that the capability requires provisioning. |
| 4888 | switch (capability) { |
| 4889 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4890 | // intentional fallthrough |
| 4891 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4892 | if (requireRcsProvisioning) { |
| 4893 | // OPTION or PRESENCE requires provisioning |
| 4894 | return true; |
| 4895 | } |
| 4896 | break; |
| 4897 | } |
| 4898 | } |
| 4899 | return false; |
| 4900 | } |
| 4901 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4902 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4903 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4904 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4905 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4906 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4907 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4908 | final long identity = Binder.clearCallingIdentity(); |
| 4909 | try { |
| 4910 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4911 | int slotId = getSlotIndex(subId); |
| 4912 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4913 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4914 | + subId + "' for key:" + key); |
| 4915 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4916 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4917 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4918 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4919 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4920 | + subId + "' for key:" + key); |
| 4921 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4922 | } finally { |
| 4923 | Binder.restoreCallingIdentity(identity); |
| 4924 | } |
| 4925 | } |
| 4926 | |
| 4927 | @Override |
| 4928 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4929 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4930 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4931 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4932 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4933 | final long identity = Binder.clearCallingIdentity(); |
| 4934 | try { |
| 4935 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4936 | int slotId = getSlotIndex(subId); |
| 4937 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4938 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4939 | + subId + "' for key:" + key); |
| 4940 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4941 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4942 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4943 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4944 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4945 | + subId + "' for key:" + key); |
| 4946 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4947 | } finally { |
| 4948 | Binder.restoreCallingIdentity(identity); |
| 4949 | } |
| 4950 | } |
| 4951 | |
| 4952 | @Override |
| 4953 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4954 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4955 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4956 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4957 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4958 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4959 | final long identity = Binder.clearCallingIdentity(); |
| 4960 | try { |
| 4961 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4962 | int slotId = getSlotIndex(subId); |
| 4963 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4964 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4965 | + subId + "' for key:" + key); |
| 4966 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4967 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4968 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4969 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4970 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4971 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4972 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4973 | } finally { |
| 4974 | Binder.restoreCallingIdentity(identity); |
| 4975 | } |
| 4976 | } |
| 4977 | |
| 4978 | @Override |
| 4979 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4980 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4981 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4982 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4983 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4984 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4985 | final long identity = Binder.clearCallingIdentity(); |
| 4986 | try { |
| 4987 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4988 | int slotId = getSlotIndex(subId); |
| 4989 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4990 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4991 | + subId + "' for key:" + key); |
| 4992 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4993 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4994 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4995 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4996 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4997 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4998 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4999 | } finally { |
| 5000 | Binder.restoreCallingIdentity(identity); |
| 5001 | } |
| 5002 | } |
| 5003 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5004 | /** |
| 5005 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5006 | * for the given slot ID or no ImsResolver instance has been created. |
| 5007 | * @param slotId The slot ID that the IMS service is created for. |
| 5008 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5009 | */ |
| 5010 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5011 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5012 | ImsFeature.FEATURE_MMTEL)) { |
| 5013 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5014 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5015 | } |
| 5016 | } |
| 5017 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5018 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5019 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5020 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5021 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5022 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5023 | } |
| 5024 | return slotId; |
| 5025 | } |
| 5026 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5027 | private int getSlotIndex(int subId) { |
| 5028 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5029 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5030 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5031 | } |
| 5032 | return slotId; |
| 5033 | } |
| 5034 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5035 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5036 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5037 | */ |
| 5038 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5039 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5040 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5041 | try { |
| 5042 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5043 | } catch (SecurityException se) { |
| 5044 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5045 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5046 | + Binder.getCallingUid()); |
| 5047 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5048 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5049 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5050 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5051 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5052 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5053 | mApp, subId, callingPackage, callingFeatureId, |
| 5054 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5055 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5056 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5057 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5058 | final long identity = Binder.clearCallingIdentity(); |
| 5059 | try { |
| 5060 | final Phone phone = getPhone(subId); |
| 5061 | if (phone != null) { |
| 5062 | return phone.getServiceState().getDataNetworkType(); |
| 5063 | } else { |
| 5064 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5065 | } |
| 5066 | } finally { |
| 5067 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5068 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5069 | } |
| 5070 | |
| 5071 | /** |
| 5072 | * Returns the data network type |
| 5073 | */ |
| 5074 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5075 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5076 | return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(), |
| 5077 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5078 | } |
| 5079 | |
| 5080 | /** |
| 5081 | * Returns the data network type for a subId |
| 5082 | */ |
| 5083 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5084 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5085 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5086 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5087 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5088 | mApp, functionName)) { |
| 5089 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5090 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5091 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5092 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5093 | } |
| 5094 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5095 | final long identity = Binder.clearCallingIdentity(); |
| 5096 | try { |
| 5097 | final Phone phone = getPhone(subId); |
| 5098 | if (phone != null) { |
| 5099 | return phone.getServiceState().getDataNetworkType(); |
| 5100 | } else { |
| 5101 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5102 | } |
| 5103 | } finally { |
| 5104 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5105 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5106 | } |
| 5107 | |
| 5108 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5109 | * Returns the Voice network type for a subId |
| 5110 | */ |
| 5111 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5112 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5113 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5114 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5115 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5116 | mApp, functionName)) { |
| 5117 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5118 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5119 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5120 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5121 | } |
| 5122 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5123 | final long identity = Binder.clearCallingIdentity(); |
| 5124 | try { |
| 5125 | final Phone phone = getPhone(subId); |
| 5126 | if (phone != null) { |
| 5127 | return phone.getServiceState().getVoiceNetworkType(); |
| 5128 | } else { |
| 5129 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5130 | } |
| 5131 | } finally { |
| 5132 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5133 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5134 | } |
| 5135 | |
| 5136 | /** |
| 5137 | * @return true if a ICC card is present |
| 5138 | */ |
| 5139 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5140 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5141 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 5142 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5143 | } |
| 5144 | |
| 5145 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5146 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5147 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5148 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5149 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5150 | final long identity = Binder.clearCallingIdentity(); |
| 5151 | try { |
| 5152 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5153 | if (phone != null) { |
| 5154 | return phone.getIccCard().hasIccCard(); |
| 5155 | } else { |
| 5156 | return false; |
| 5157 | } |
| 5158 | } finally { |
| 5159 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5160 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5161 | } |
| 5162 | |
| 5163 | /** |
| 5164 | * Return if the current radio is LTE on CDMA. This |
| 5165 | * is a tri-state return value as for a period of time |
| 5166 | * the mode may be unknown. |
| 5167 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5168 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5169 | * @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] | 5170 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5171 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5172 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5173 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5174 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5175 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5176 | } |
| 5177 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5178 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5179 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5180 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5181 | try { |
| 5182 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5183 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5184 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5185 | } |
| 5186 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5187 | final long identity = Binder.clearCallingIdentity(); |
| 5188 | try { |
| 5189 | final Phone phone = getPhone(subId); |
| 5190 | if (phone == null) { |
| 5191 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5192 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5193 | return TelephonyProperties.lte_on_cdma_device() |
| 5194 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5195 | } |
| 5196 | } finally { |
| 5197 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5198 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5199 | } |
| 5200 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5201 | /** |
| 5202 | * {@hide} |
| 5203 | * Returns Default subId, 0 in the case of single standby. |
| 5204 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5205 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5206 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5207 | } |
| 5208 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5209 | private int getSlotForDefaultSubscription() { |
| 5210 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 5211 | } |
| 5212 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5213 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5214 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5215 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5216 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5217 | private boolean isActiveSubscription(int subId) { |
| 5218 | return mSubscriptionController.isActiveSubId(subId); |
| 5219 | } |
| 5220 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5221 | /** |
| 5222 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5223 | */ |
| 5224 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5225 | final long identity = Binder.clearCallingIdentity(); |
| 5226 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5227 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5228 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5229 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5230 | } finally { |
| 5231 | Binder.restoreCallingIdentity(identity); |
| 5232 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5233 | } |
| 5234 | |
| 5235 | /** |
| 5236 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5237 | */ |
| 5238 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5239 | final long identity = Binder.clearCallingIdentity(); |
| 5240 | try { |
| 5241 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5242 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5243 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5244 | } finally { |
| 5245 | Binder.restoreCallingIdentity(identity); |
| 5246 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5247 | } |
| 5248 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5249 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5250 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5251 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5252 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5253 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5254 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5255 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5256 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5257 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5258 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
| 5259 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5260 | } |
| 5261 | return PhoneFactory.getPhone(phoneId); |
| 5262 | } |
| 5263 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5264 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5265 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5266 | @NonNull IccLogicalChannelRequest request) { |
| 5267 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5268 | /*message=*/ "iccOpenLogicalChannel"); |
| 5269 | |
| 5270 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5271 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5272 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5273 | |
| 5274 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5275 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5276 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5277 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5278 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5279 | Phone phone; |
| 5280 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5281 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5282 | mApp, request.subId, message); |
| 5283 | phone = getPhoneFromSubId(request.subId); |
| 5284 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5285 | enforceModifyPermission(); |
| 5286 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5287 | } else { |
| 5288 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5289 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5290 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5291 | } |
| 5292 | |
| 5293 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5294 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5295 | final long identity = Binder.clearCallingIdentity(); |
| 5296 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5297 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5298 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5299 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5300 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5301 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5302 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5303 | loge("The calling package is not allowed to access ISD-R."); |
| 5304 | throw new SecurityException( |
| 5305 | "The calling package is not allowed to access ISD-R."); |
| 5306 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5307 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5308 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5309 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5310 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5311 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5312 | return response; |
| 5313 | } finally { |
| 5314 | Binder.restoreCallingIdentity(identity); |
| 5315 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5316 | } |
| 5317 | |
| 5318 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5319 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5320 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5321 | /*message=*/"iccCloseLogicalChannel"); |
| 5322 | |
| 5323 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5324 | |
| 5325 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5326 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5327 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5328 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5329 | IccLogicalChannelRequest request) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5330 | final long identity = Binder.clearCallingIdentity(); |
| 5331 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5332 | if (request.channel < 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5333 | return false; |
| 5334 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5335 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5336 | null /* workSource */); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5337 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5338 | return success; |
| 5339 | } finally { |
| 5340 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5341 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5342 | } |
| 5343 | |
| 5344 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5345 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5346 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5347 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5348 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5349 | if (DBG) { |
| 5350 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5351 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5352 | + p3 + " data=" + data); |
| 5353 | } |
| 5354 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5355 | command, p1, p2, p3, data); |
| 5356 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5357 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5358 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5359 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
| 5360 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5361 | enforceModifyPermission(); |
| 5362 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5363 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5364 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5365 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5366 | } |
| 5367 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5368 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5369 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5370 | } |
| 5371 | |
| 5372 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5373 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5374 | final long identity = Binder.clearCallingIdentity(); |
| 5375 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5376 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5377 | return ""; |
| 5378 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5379 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5380 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5381 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5382 | null /* workSource */); |
| 5383 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5384 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5385 | // Append the returned status code to the end of the response payload. |
| 5386 | String s = Integer.toHexString( |
| 5387 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5388 | if (response.payload != null) { |
| 5389 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5390 | } |
| 5391 | return s; |
| 5392 | } finally { |
| 5393 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5394 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5395 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5396 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5397 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5398 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5399 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5400 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5401 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5402 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5403 | if (DBG) { |
| 5404 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5405 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5406 | } |
| 5407 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5408 | cla, command, p1, p2, p3, data); |
| 5409 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5410 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5411 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5412 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
| 5413 | 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] | 5414 | enforceModifyPermission(); |
| 5415 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5416 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5417 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5418 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5419 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5420 | } |
| 5421 | |
| 5422 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5423 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5424 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5425 | } |
| 5426 | |
| 5427 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5428 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5429 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5430 | final long identity = Binder.clearCallingIdentity(); |
| 5431 | try { |
| 5432 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5433 | && TextUtils.equals(ISDR_AID, data)) { |
| 5434 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5435 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5436 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5437 | if (bestComponent == null |
| 5438 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5439 | loge("The calling package is not allowed to select ISD-R."); |
| 5440 | throw new SecurityException( |
| 5441 | "The calling package is not allowed to select ISD-R."); |
| 5442 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5443 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5444 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5445 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5446 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5447 | null /* workSource */); |
| 5448 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5449 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5450 | // Append the returned status code to the end of the response payload. |
| 5451 | String s = Integer.toHexString( |
| 5452 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5453 | if (response.payload != null) { |
| 5454 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5455 | } |
| 5456 | return s; |
| 5457 | } finally { |
| 5458 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5459 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5460 | } |
| 5461 | |
| 5462 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5463 | 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] | 5464 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5465 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5466 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5467 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5468 | final long identity = Binder.clearCallingIdentity(); |
| 5469 | try { |
| 5470 | if (DBG) { |
| 5471 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5472 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5473 | } |
| 5474 | |
| 5475 | IccIoResult response = |
| 5476 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5477 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5478 | subId); |
| 5479 | |
| 5480 | if (DBG) { |
| 5481 | log("Exchange SIM_IO [R]" + response); |
| 5482 | } |
| 5483 | |
| 5484 | byte[] result = null; |
| 5485 | int length = 2; |
| 5486 | if (response.payload != null) { |
| 5487 | length = 2 + response.payload.length; |
| 5488 | result = new byte[length]; |
| 5489 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5490 | } else { |
| 5491 | result = new byte[length]; |
| 5492 | } |
| 5493 | |
| 5494 | result[length - 1] = (byte) response.sw2; |
| 5495 | result[length - 2] = (byte) response.sw1; |
| 5496 | return result; |
| 5497 | } finally { |
| 5498 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5499 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5500 | } |
| 5501 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5502 | /** |
| 5503 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5504 | * on a particular subscription |
| 5505 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5506 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5507 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5508 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5509 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5510 | return null; |
| 5511 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5512 | |
| 5513 | final long identity = Binder.clearCallingIdentity(); |
| 5514 | try { |
| 5515 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5516 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5517 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5518 | return null; |
| 5519 | } |
| 5520 | Object response = sendRequest( |
| 5521 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5522 | if (response instanceof String[]) { |
| 5523 | return (String[]) response; |
| 5524 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5525 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5526 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5527 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5528 | } finally { |
| 5529 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5530 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5531 | } |
| 5532 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5533 | /** |
| 5534 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5535 | * subscription. |
| 5536 | * |
| 5537 | * @param subId the id of the subscription. |
| 5538 | * @param appType the uicc app type, must be USIM or SIM. |
| 5539 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5540 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5541 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5542 | * @return number of fplmns that is successfully written to the SIM. |
| 5543 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5544 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5545 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5546 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5547 | mApp, subId, "setForbiddenPlmns"); |
| 5548 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5549 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5550 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5551 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5552 | } |
| 5553 | if (fplmns == null) { |
| 5554 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5555 | } |
| 5556 | for (String fplmn : fplmns) { |
| 5557 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5558 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5559 | } |
| 5560 | } |
| 5561 | final long identity = Binder.clearCallingIdentity(); |
| 5562 | try { |
| 5563 | Object response = sendRequest( |
| 5564 | CMD_SET_FORBIDDEN_PLMNS, |
| 5565 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5566 | subId); |
| 5567 | return (int) response; |
| 5568 | } finally { |
| 5569 | Binder.restoreCallingIdentity(identity); |
| 5570 | } |
| 5571 | } |
| 5572 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5573 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5574 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5575 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5576 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5577 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5578 | final long identity = Binder.clearCallingIdentity(); |
| 5579 | try { |
| 5580 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5581 | if (response.payload == null) { |
| 5582 | return ""; |
| 5583 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5584 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5585 | // Append the returned status code to the end of the response payload. |
| 5586 | String s = Integer.toHexString( |
| 5587 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5588 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5589 | return s; |
| 5590 | } finally { |
| 5591 | Binder.restoreCallingIdentity(identity); |
| 5592 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5593 | } |
| 5594 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5595 | /** |
| 5596 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5597 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5598 | * |
| 5599 | * @param itemID the ID of the item to read |
| 5600 | * @return the NV item as a String, or null on error. |
| 5601 | */ |
| 5602 | @Override |
| 5603 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5604 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5605 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5606 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5607 | |
| 5608 | final long identity = Binder.clearCallingIdentity(); |
| 5609 | try { |
| 5610 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5611 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5612 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5613 | return value; |
| 5614 | } finally { |
| 5615 | Binder.restoreCallingIdentity(identity); |
| 5616 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5617 | } |
| 5618 | |
| 5619 | /** |
| 5620 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5621 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5622 | * |
| 5623 | * @param itemID the ID of the item to read |
| 5624 | * @param itemValue the value to write, as a String |
| 5625 | * @return true on success; false on any failure |
| 5626 | */ |
| 5627 | @Override |
| 5628 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5629 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5630 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5631 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5632 | |
| 5633 | final long identity = Binder.clearCallingIdentity(); |
| 5634 | try { |
| 5635 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5636 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5637 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5638 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5639 | return success; |
| 5640 | } finally { |
| 5641 | Binder.restoreCallingIdentity(identity); |
| 5642 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5643 | } |
| 5644 | |
| 5645 | /** |
| 5646 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5647 | * Used for device configuration by some CDMA operators. |
| 5648 | * |
| 5649 | * @param preferredRoamingList byte array containing the new PRL |
| 5650 | * @return true on success; false on any failure |
| 5651 | */ |
| 5652 | @Override |
| 5653 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5654 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5655 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5656 | |
| 5657 | final long identity = Binder.clearCallingIdentity(); |
| 5658 | try { |
| 5659 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5660 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5661 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5662 | return success; |
| 5663 | } finally { |
| 5664 | Binder.restoreCallingIdentity(identity); |
| 5665 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5666 | } |
| 5667 | |
| 5668 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5669 | * 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] | 5670 | * Used for device configuration by some CDMA operators. |
| 5671 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5672 | * @param slotIndex - device slot. |
| 5673 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5674 | * @return true on success; false on any failure |
| 5675 | */ |
| 5676 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5677 | public boolean resetModemConfig(int slotIndex) { |
| 5678 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5679 | if (phone != null) { |
| 5680 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5681 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5682 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5683 | final long identity = Binder.clearCallingIdentity(); |
| 5684 | try { |
| 5685 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5686 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5687 | return success; |
| 5688 | } finally { |
| 5689 | Binder.restoreCallingIdentity(identity); |
| 5690 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5691 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5692 | return false; |
| 5693 | } |
| 5694 | |
| 5695 | /** |
| 5696 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5697 | * |
| 5698 | * @param slotIndex - device slot. |
| 5699 | * |
| 5700 | * @return true on success; false on any failure |
| 5701 | */ |
| 5702 | @Override |
| 5703 | public boolean rebootModem(int slotIndex) { |
| 5704 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5705 | if (phone != null) { |
| 5706 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5707 | mApp, phone.getSubId(), "rebootModem"); |
| 5708 | |
| 5709 | final long identity = Binder.clearCallingIdentity(); |
| 5710 | try { |
| 5711 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5712 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5713 | return success; |
| 5714 | } finally { |
| 5715 | Binder.restoreCallingIdentity(identity); |
| 5716 | } |
| 5717 | } |
| 5718 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5719 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5720 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5721 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5722 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5723 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5724 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5725 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5726 | return new String[0]; |
| 5727 | } |
| 5728 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5729 | final long identity = Binder.clearCallingIdentity(); |
| 5730 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5731 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5732 | } finally { |
| 5733 | Binder.restoreCallingIdentity(identity); |
| 5734 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5735 | } |
| 5736 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5737 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5738 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5739 | * {@link #disableIms(int)}. |
| 5740 | * @param slotIndex device slot. |
| 5741 | */ |
| 5742 | public void resetIms(int slotIndex) { |
| 5743 | enforceModifyPermission(); |
| 5744 | |
| 5745 | final long identity = Binder.clearCallingIdentity(); |
| 5746 | try { |
| 5747 | if (mImsResolver == null) { |
| 5748 | // may happen if the does not support IMS. |
| 5749 | return; |
| 5750 | } |
| 5751 | mImsResolver.disableIms(slotIndex); |
| 5752 | mImsResolver.enableIms(slotIndex); |
| 5753 | } finally { |
| 5754 | Binder.restoreCallingIdentity(identity); |
| 5755 | } |
| 5756 | } |
| 5757 | |
| 5758 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5759 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5760 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5761 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5762 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5763 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5764 | |
| 5765 | final long identity = Binder.clearCallingIdentity(); |
| 5766 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5767 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5768 | // may happen if the device does not support IMS. |
| 5769 | return; |
| 5770 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5771 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5772 | } finally { |
| 5773 | Binder.restoreCallingIdentity(identity); |
| 5774 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5775 | } |
| 5776 | |
| 5777 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5778 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5779 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5780 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5781 | public void disableIms(int slotId) { |
| 5782 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5783 | |
| 5784 | final long identity = Binder.clearCallingIdentity(); |
| 5785 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5786 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5787 | // may happen if the device does not support IMS. |
| 5788 | return; |
| 5789 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5790 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5791 | } finally { |
| 5792 | Binder.restoreCallingIdentity(identity); |
| 5793 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5794 | } |
| 5795 | |
| 5796 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5797 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5798 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5799 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5800 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5801 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5802 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5803 | |
| 5804 | final long identity = Binder.clearCallingIdentity(); |
| 5805 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5806 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5807 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5808 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5809 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5810 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5811 | } finally { |
| 5812 | Binder.restoreCallingIdentity(identity); |
| 5813 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5814 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5815 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5816 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5817 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5818 | @Override |
| 5819 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5820 | enforceModifyPermission(); |
| 5821 | |
| 5822 | final long identity = Binder.clearCallingIdentity(); |
| 5823 | try { |
| 5824 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5825 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5826 | } finally { |
| 5827 | Binder.restoreCallingIdentity(identity); |
| 5828 | } |
| 5829 | } |
| 5830 | |
| 5831 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5832 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5833 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5834 | */ |
| 5835 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5836 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5837 | |
| 5838 | final long identity = Binder.clearCallingIdentity(); |
| 5839 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5840 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5841 | // may happen if the device does not support IMS. |
| 5842 | return null; |
| 5843 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5844 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5845 | } finally { |
| 5846 | Binder.restoreCallingIdentity(identity); |
| 5847 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5848 | } |
| 5849 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5850 | /** |
| 5851 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5852 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5853 | */ |
| 5854 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5855 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5856 | |
| 5857 | final long identity = Binder.clearCallingIdentity(); |
| 5858 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5859 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5860 | // may happen if the device does not support IMS. |
| 5861 | return null; |
| 5862 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5863 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5864 | } finally { |
| 5865 | Binder.restoreCallingIdentity(identity); |
| 5866 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5867 | } |
| 5868 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5869 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5870 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5871 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5872 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5873 | * @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] | 5874 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5875 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5876 | * @param packageName The name of the package that the current configuration will be replaced |
| 5877 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5878 | * @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] | 5879 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5880 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5881 | int[] featureTypes, String packageName) { |
| 5882 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5883 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5884 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5885 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5886 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5887 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5888 | final long identity = Binder.clearCallingIdentity(); |
| 5889 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5890 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5891 | // may happen if the device does not support IMS. |
| 5892 | return false; |
| 5893 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5894 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5895 | for (int featureType : featureTypes) { |
| 5896 | featureConfig.put(featureType, packageName); |
| 5897 | } |
| 5898 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5899 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5900 | } finally { |
| 5901 | Binder.restoreCallingIdentity(identity); |
| 5902 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5903 | } |
| 5904 | |
| 5905 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5906 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5907 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5908 | * |
| 5909 | * This should only be used for testing. |
| 5910 | * |
| 5911 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5912 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5913 | */ |
| 5914 | @Override |
| 5915 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5916 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5917 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5918 | "clearCarrierImsServiceOverride"); |
| 5919 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5920 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5921 | "clearCarrierImsServiceOverride"); |
| 5922 | |
| 5923 | final long identity = Binder.clearCallingIdentity(); |
| 5924 | try { |
| 5925 | if (mImsResolver == null) { |
| 5926 | // may happen if the device does not support IMS. |
| 5927 | return false; |
| 5928 | } |
| 5929 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5930 | } finally { |
| 5931 | Binder.restoreCallingIdentity(identity); |
| 5932 | } |
| 5933 | } |
| 5934 | |
| 5935 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5936 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5937 | * |
| 5938 | * @param slotId The slot that the ImsService is associated with. |
| 5939 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5940 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5941 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5942 | * @return the package name of the ImsService configuration. |
| 5943 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5944 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5945 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5946 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5947 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5948 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5949 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5950 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5951 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5952 | final long identity = Binder.clearCallingIdentity(); |
| 5953 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5954 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5955 | // may happen if the device does not support IMS. |
| 5956 | return ""; |
| 5957 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5958 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5959 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5960 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5961 | } finally { |
| 5962 | Binder.restoreCallingIdentity(identity); |
| 5963 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5964 | } |
| 5965 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5966 | /** |
| 5967 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5968 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5969 | * @param callback A callback with an integer containing the |
| 5970 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5971 | */ |
| 5972 | @Override |
| 5973 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5974 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5975 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5976 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5977 | "IMS not available on device."); |
| 5978 | } |
| 5979 | final long token = Binder.clearCallingIdentity(); |
| 5980 | try { |
| 5981 | int slotId = getSlotIndex(subId); |
| 5982 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5983 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5984 | + subId + "'"); |
| 5985 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5986 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5987 | verifyImsMmTelConfiguredOrThrow(slotId); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5988 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5989 | try { |
| 5990 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5991 | } catch (RemoteException e) { |
| 5992 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5993 | + "Ignore"); |
| 5994 | } |
| 5995 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5996 | } catch (ImsException e) { |
| 5997 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5998 | } finally { |
| 5999 | Binder.restoreCallingIdentity(token); |
| 6000 | } |
| 6001 | } |
| 6002 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6003 | /** |
| 6004 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6005 | */ |
| 6006 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6007 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6008 | |
| 6009 | final long identity = Binder.clearCallingIdentity(); |
| 6010 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6011 | // NOTE: Before S, this method only set the default phone. |
| 6012 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6013 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6014 | phone.setImsRegistrationState(registered); |
| 6015 | } |
| 6016 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6017 | } finally { |
| 6018 | Binder.restoreCallingIdentity(identity); |
| 6019 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6020 | } |
| 6021 | |
| 6022 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6023 | * Set the network selection mode to automatic. |
| 6024 | * |
| 6025 | */ |
| 6026 | @Override |
| 6027 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6028 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6029 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6030 | |
| 6031 | final long identity = Binder.clearCallingIdentity(); |
| 6032 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6033 | if (!isActiveSubscription(subId)) { |
| 6034 | return; |
| 6035 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6036 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6037 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6038 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6039 | } finally { |
| 6040 | Binder.restoreCallingIdentity(identity); |
| 6041 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6042 | } |
| 6043 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6044 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6045 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6046 | * |
| 6047 | * @param subId the id of the subscription. |
| 6048 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6049 | * the operator to attach to. |
| 6050 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6051 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6052 | * normal network selection next time. |
| 6053 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6054 | */ |
| 6055 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6056 | public boolean setNetworkSelectionModeManual( |
| 6057 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6058 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6059 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6060 | |
| 6061 | if (!isActiveSubscription(subId)) { |
| 6062 | return false; |
| 6063 | } |
| 6064 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6065 | final long identity = Binder.clearCallingIdentity(); |
| 6066 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6067 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6068 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6069 | if (DBG) { |
| 6070 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6071 | + " operator: " + operatorInfo); |
| 6072 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6073 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6074 | } finally { |
| 6075 | Binder.restoreCallingIdentity(identity); |
| 6076 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6077 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6078 | /** |
| 6079 | * Get the manual network selection |
| 6080 | * |
| 6081 | * @param subId the id of the subscription. |
| 6082 | * |
| 6083 | * @return the previously saved user selected PLMN |
| 6084 | */ |
| 6085 | @Override |
| 6086 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6087 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6088 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6089 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 6090 | |
| 6091 | final long identity = Binder.clearCallingIdentity(); |
| 6092 | try { |
| 6093 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6094 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6095 | } |
| 6096 | |
| 6097 | final Phone phone = getPhone(subId); |
| 6098 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6099 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6100 | } |
| 6101 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6102 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6103 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6104 | } finally { |
| 6105 | Binder.restoreCallingIdentity(identity); |
| 6106 | } |
| 6107 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6108 | |
| 6109 | /** |
| 6110 | * Scans for available networks. |
| 6111 | */ |
| 6112 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6113 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6114 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6115 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6116 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6117 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6118 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6119 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6120 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6121 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6122 | .setCallingPid(Binder.getCallingPid()) |
| 6123 | .setCallingUid(Binder.getCallingUid()) |
| 6124 | .setMethod("getCellNetworkScanResults") |
| 6125 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6126 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6127 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6128 | .build()); |
| 6129 | switch (locationResult) { |
| 6130 | case DENIED_HARD: |
| 6131 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6132 | case DENIED_SOFT: |
| 6133 | return null; |
| 6134 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6135 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6136 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6137 | try { |
| 6138 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6139 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6140 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6141 | } finally { |
| 6142 | Binder.restoreCallingIdentity(identity); |
| 6143 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6144 | } |
| 6145 | |
| 6146 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6147 | * Get the call forwarding info, given the call forwarding reason. |
| 6148 | */ |
| 6149 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6150 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6151 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6152 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6153 | long identity = Binder.clearCallingIdentity(); |
| 6154 | try { |
| 6155 | if (DBG) { |
| 6156 | log("getCallForwarding: subId " + subId |
| 6157 | + " callForwardingReason" + callForwardingReason); |
| 6158 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6159 | |
| 6160 | Phone phone = getPhone(subId); |
| 6161 | if (phone == null) { |
| 6162 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6163 | callback.onError( |
| 6164 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6165 | } catch (RemoteException e) { |
| 6166 | // ignore |
| 6167 | } |
| 6168 | return; |
| 6169 | } |
| 6170 | |
| 6171 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6172 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6173 | @Override |
| 6174 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6175 | try { |
| 6176 | callback.onCallForwardingInfoAvailable(info); |
| 6177 | } catch (RemoteException e) { |
| 6178 | // ignore |
| 6179 | } |
| 6180 | } |
| 6181 | |
| 6182 | @Override |
| 6183 | public void onError(int error) { |
| 6184 | try { |
| 6185 | callback.onError(error); |
| 6186 | } catch (RemoteException e) { |
| 6187 | // ignore |
| 6188 | } |
| 6189 | } |
| 6190 | }); |
| 6191 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6192 | } finally { |
| 6193 | Binder.restoreCallingIdentity(identity); |
| 6194 | } |
| 6195 | } |
| 6196 | |
| 6197 | /** |
| 6198 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6199 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6200 | */ |
| 6201 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6202 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6203 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6204 | enforceModifyPermission(); |
| 6205 | long identity = Binder.clearCallingIdentity(); |
| 6206 | try { |
| 6207 | if (DBG) { |
| 6208 | log("setCallForwarding: subId " + subId |
| 6209 | + " callForwardingInfo" + callForwardingInfo); |
| 6210 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6211 | |
| 6212 | Phone phone = getPhone(subId); |
| 6213 | if (phone == null) { |
| 6214 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6215 | callback.accept( |
| 6216 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6217 | } catch (RemoteException e) { |
| 6218 | // ignore |
| 6219 | } |
| 6220 | return; |
| 6221 | } |
| 6222 | |
| 6223 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6224 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6225 | |
| 6226 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6227 | } finally { |
| 6228 | Binder.restoreCallingIdentity(identity); |
| 6229 | } |
| 6230 | } |
| 6231 | |
| 6232 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6233 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6234 | */ |
| 6235 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6236 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6237 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6238 | long identity = Binder.clearCallingIdentity(); |
| 6239 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6240 | Phone phone = getPhone(subId); |
| 6241 | if (phone == null) { |
| 6242 | try { |
| 6243 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6244 | } catch (RemoteException e) { |
| 6245 | // ignore |
| 6246 | } |
| 6247 | return; |
| 6248 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6249 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6250 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6251 | boolean requireUssd = c.getBoolean( |
| 6252 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6253 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6254 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6255 | if (requireUssd) { |
| 6256 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6257 | getSubscriptionCarrierId(subId)); |
| 6258 | String newUssdCommand = ""; |
| 6259 | try { |
| 6260 | newUssdCommand = carrierXmlParser.getFeature( |
| 6261 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6262 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6263 | } catch (NullPointerException e) { |
| 6264 | loge("Failed to generate USSD number" + e); |
| 6265 | } |
| 6266 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6267 | mMainThreadHandler, callback, carrierXmlParser, |
| 6268 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6269 | final String ussdCommand = newUssdCommand; |
| 6270 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6271 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6272 | }); |
| 6273 | } else { |
| 6274 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6275 | callback::accept); |
| 6276 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6277 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6278 | } finally { |
| 6279 | Binder.restoreCallingIdentity(identity); |
| 6280 | } |
| 6281 | } |
| 6282 | |
| 6283 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6284 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6285 | */ |
| 6286 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6287 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6288 | enforceModifyPermission(); |
| 6289 | long identity = Binder.clearCallingIdentity(); |
| 6290 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6291 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6292 | |
| 6293 | Phone phone = getPhone(subId); |
| 6294 | if (phone == null) { |
| 6295 | try { |
| 6296 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6297 | } catch (RemoteException e) { |
| 6298 | // ignore |
| 6299 | } |
| 6300 | return; |
| 6301 | } |
| 6302 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6303 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6304 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6305 | boolean requireUssd = c.getBoolean( |
| 6306 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6307 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6308 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6309 | if (requireUssd) { |
| 6310 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6311 | getSubscriptionCarrierId(subId)); |
| 6312 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6313 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6314 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6315 | String newUssdCommand = ""; |
| 6316 | try { |
| 6317 | newUssdCommand = carrierXmlParser.getFeature( |
| 6318 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6319 | .makeCommand(ssAction, null); |
| 6320 | } catch (NullPointerException e) { |
| 6321 | loge("Failed to generate USSD number" + e); |
| 6322 | } |
| 6323 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6324 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6325 | final String ussdCommand = newUssdCommand; |
| 6326 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6327 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6328 | }); |
| 6329 | } else { |
| 6330 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6331 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6332 | |
| 6333 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6334 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6335 | } finally { |
| 6336 | Binder.restoreCallingIdentity(identity); |
| 6337 | } |
| 6338 | } |
| 6339 | |
| 6340 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6341 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6342 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6343 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6344 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6345 | * location related information which will be sent if the caller already possess |
| 6346 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6347 | * @param request contains the radio access networks with bands/channels to scan |
| 6348 | * @param messenger callback messenger for scan results or errors |
| 6349 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6350 | * @return the id of the requested scan which can be used to stop the scan. |
| 6351 | */ |
| 6352 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6353 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6354 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6355 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6356 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6357 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6358 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6359 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6360 | if (!renounceFineLocationAccess) { |
| 6361 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
| 6362 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6363 | .setCallingPackage(callingPackage) |
| 6364 | .setCallingFeatureId(callingFeatureId) |
| 6365 | .setCallingPid(Binder.getCallingPid()) |
| 6366 | .setCallingUid(Binder.getCallingUid()) |
| 6367 | .setMethod("requestNetworkScan") |
| 6368 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6369 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6370 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6371 | .build()); |
| 6372 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6373 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6374 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6375 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6376 | if (e != null) { |
| 6377 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6378 | throw e; |
| 6379 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6380 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6381 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6382 | } |
| 6383 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6384 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6385 | int callingUid = Binder.getCallingUid(); |
| 6386 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6387 | final long identity = Binder.clearCallingIdentity(); |
| 6388 | try { |
| 6389 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6390 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6391 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6392 | } finally { |
| 6393 | Binder.restoreCallingIdentity(identity); |
| 6394 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6395 | } |
| 6396 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6397 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6398 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6399 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6400 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6401 | boolean hasNetworkScanPermission = |
| 6402 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6403 | == PERMISSION_GRANTED; |
| 6404 | |
| 6405 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6406 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6407 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6408 | } |
| 6409 | |
| 6410 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6411 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6412 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6413 | return new SecurityException("Specific channels must not be" |
| 6414 | + " scanned without location access."); |
| 6415 | } |
| 6416 | } |
| 6417 | } |
| 6418 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6419 | return null; |
| 6420 | } |
| 6421 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6422 | /** |
| 6423 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6424 | * |
| 6425 | * @param subId id of the subscription |
| 6426 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6427 | */ |
| 6428 | @Override |
| 6429 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6430 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6431 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6432 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6433 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6434 | final long identity = Binder.clearCallingIdentity(); |
| 6435 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6436 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6437 | } finally { |
| 6438 | Binder.restoreCallingIdentity(identity); |
| 6439 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6440 | } |
| 6441 | |
| 6442 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6443 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6444 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6445 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6446 | */ |
| 6447 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6448 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6449 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6450 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6451 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6452 | |
| 6453 | final long identity = Binder.clearCallingIdentity(); |
| 6454 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6455 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6456 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6457 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6458 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6459 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6460 | } finally { |
| 6461 | Binder.restoreCallingIdentity(identity); |
| 6462 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6463 | } |
| 6464 | |
| 6465 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6466 | * Get the allowed network types for certain reason. |
| 6467 | * |
| 6468 | * @param subId the id of the subscription. |
| 6469 | * @param reason the reason the allowed network type change is taking place |
| 6470 | * @return the allowed network types. |
| 6471 | */ |
| 6472 | @Override |
| 6473 | public long getAllowedNetworkTypesForReason(int subId, |
| 6474 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6475 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6476 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6477 | final long identity = Binder.clearCallingIdentity(); |
| 6478 | try { |
| 6479 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6480 | } finally { |
| 6481 | Binder.restoreCallingIdentity(identity); |
| 6482 | } |
| 6483 | } |
| 6484 | |
| 6485 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6486 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6487 | * @param subId subscription id of the sim card |
| 6488 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6489 | * This can be passed following states |
| 6490 | * <ol> |
| 6491 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6492 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6493 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6494 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6495 | * </ol> |
| 6496 | * @return operation result. |
| 6497 | */ |
| 6498 | @Override |
| 6499 | public int setNrDualConnectivityState(int subId, |
| 6500 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6501 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6502 | mApp, subId, "enableNRDualConnectivity"); |
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 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6506 | } |
| 6507 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6508 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6509 | final long identity = Binder.clearCallingIdentity(); |
| 6510 | try { |
| 6511 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6512 | nrDualConnectivityState, subId, |
| 6513 | workSource); |
| 6514 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6515 | return result; |
| 6516 | } finally { |
| 6517 | Binder.restoreCallingIdentity(identity); |
| 6518 | } |
| 6519 | } |
| 6520 | |
| 6521 | /** |
| 6522 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6523 | * @return true if dual connectivity is enabled else false |
| 6524 | */ |
| 6525 | @Override |
| 6526 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6527 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6528 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6529 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6530 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6531 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6532 | return false; |
| 6533 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6534 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6535 | final long identity = Binder.clearCallingIdentity(); |
| 6536 | try { |
| 6537 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6538 | null, subId, workSource); |
| 6539 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6540 | return isEnabled; |
| 6541 | } finally { |
| 6542 | Binder.restoreCallingIdentity(identity); |
| 6543 | } |
| 6544 | } |
| 6545 | |
| 6546 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6547 | * Set the allowed network types of the device and |
| 6548 | * provide the reason triggering the allowed network change. |
| 6549 | * |
| 6550 | * @param subId the id of the subscription. |
| 6551 | * @param reason the reason the allowed network type change is taking place |
| 6552 | * @param allowedNetworkTypes the allowed network types. |
| 6553 | * @return true on success; false on any failure. |
| 6554 | */ |
| 6555 | @Override |
| 6556 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6557 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6558 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6559 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6560 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6561 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6562 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6563 | return false; |
| 6564 | } |
| 6565 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6566 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6567 | return false; |
| 6568 | } |
| 6569 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6570 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6571 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6572 | |
| 6573 | |
| 6574 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6575 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6576 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6577 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6578 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6579 | final long identity = Binder.clearCallingIdentity(); |
| 6580 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6581 | Boolean success = (Boolean) sendRequest( |
| 6582 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6583 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6584 | |
| 6585 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6586 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6587 | } finally { |
| 6588 | Binder.restoreCallingIdentity(identity); |
| 6589 | } |
| 6590 | } |
| 6591 | |
| 6592 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6593 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6594 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6595 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6596 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6597 | * @hide |
| 6598 | */ |
| 6599 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6600 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6601 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6602 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6603 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6604 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6605 | if (phone != null) { |
| 6606 | return phone.hasMatchedTetherApnSetting(); |
| 6607 | } else { |
| 6608 | return false; |
| 6609 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6610 | } finally { |
| 6611 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6612 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6613 | } |
| 6614 | |
| 6615 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6616 | * Get the user enabled state of Mobile Data. |
| 6617 | * |
| 6618 | * TODO: remove and use isUserDataEnabled. |
| 6619 | * This can't be removed now because some vendor codes |
| 6620 | * calls through ITelephony directly while they should |
| 6621 | * use TelephonyManager. |
| 6622 | * |
| 6623 | * @return true on enabled |
| 6624 | */ |
| 6625 | @Override |
| 6626 | public boolean getDataEnabled(int subId) { |
| 6627 | return isUserDataEnabled(subId); |
| 6628 | } |
| 6629 | |
| 6630 | /** |
| 6631 | * Get whether mobile data is enabled per user setting. |
| 6632 | * |
| 6633 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6634 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6635 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6636 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6637 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6638 | * |
| 6639 | * @return {@code true} if data is enabled else {@code false} |
| 6640 | */ |
| 6641 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6642 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6643 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6644 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6645 | try { |
| 6646 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6647 | functionName); |
| 6648 | } catch (Exception e) { |
| 6649 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6650 | } |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6651 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6652 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6653 | mApp, subId, functionName); |
| 6654 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6655 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6656 | |
| 6657 | final long identity = Binder.clearCallingIdentity(); |
| 6658 | try { |
| 6659 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6660 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6661 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6662 | if (phone != null) { |
| 6663 | boolean retVal = phone.isUserDataEnabled(); |
| 6664 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6665 | return retVal; |
| 6666 | } else { |
| 6667 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6668 | return false; |
| 6669 | } |
| 6670 | } finally { |
| 6671 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6672 | } |
| 6673 | } |
| 6674 | |
| 6675 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6676 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6677 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6678 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6679 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6680 | * @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] | 6681 | */ |
| 6682 | @Override |
| 6683 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6684 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6685 | try { |
| 6686 | try { |
| 6687 | mApp.enforceCallingOrSelfPermission( |
| 6688 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6689 | functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6690 | } catch (Exception e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6691 | try { |
| 6692 | mApp.enforceCallingOrSelfPermission( |
| 6693 | android.Manifest.permission.READ_PHONE_STATE, |
| 6694 | functionName); |
| 6695 | } catch (Exception e2) { |
| 6696 | mApp.enforceCallingOrSelfPermission( |
| 6697 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6698 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6699 | } |
| 6700 | } catch (Exception e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6701 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6702 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6703 | |
| 6704 | final long identity = Binder.clearCallingIdentity(); |
| 6705 | try { |
| 6706 | int phoneId = mSubscriptionController.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6707 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6708 | if (phone != null) { |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6709 | boolean retVal; |
| 6710 | if (phone.isUsingNewDataStack()) { |
| 6711 | retVal = phone.getDataNetworkController().getDataSettingsManager() |
| 6712 | .isDataEnabled(); |
| 6713 | } else { |
| 6714 | retVal = phone.getDataEnabledSettings().isDataEnabled(); |
| 6715 | } |
| 6716 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6717 | return retVal; |
| 6718 | } else { |
| 6719 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6720 | return false; |
| 6721 | } |
| 6722 | } finally { |
| 6723 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6724 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6725 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6726 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6727 | /** |
| 6728 | * Check if data is enabled for a specific reason |
| 6729 | * @param subId Subscription index |
| 6730 | * @param reason the reason the data enable change is taking place |
| 6731 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6732 | */ |
| 6733 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6734 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6735 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6736 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6737 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6738 | try { |
| 6739 | mApp.enforceCallingOrSelfPermission( |
| 6740 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6741 | functionName); |
| 6742 | } catch (Exception e) { |
| 6743 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6744 | functionName); |
| 6745 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6746 | } catch (Exception e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6747 | try { |
| 6748 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6749 | functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6750 | } catch (Exception e2) { |
| 6751 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6752 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6753 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6754 | } |
| 6755 | |
| 6756 | |
| 6757 | final long identity = Binder.clearCallingIdentity(); |
| 6758 | try { |
| 6759 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6760 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6761 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6762 | + " reason=" + reason); |
| 6763 | } |
| 6764 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6765 | if (phone != null) { |
| 6766 | boolean retVal; |
| 6767 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6768 | retVal = phone.isUserDataEnabled(); |
| 6769 | } else { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6770 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6771 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6772 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6773 | return retVal; |
| 6774 | } else { |
| 6775 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6776 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6777 | + subId + " retVal=false"); |
| 6778 | } |
| 6779 | return false; |
| 6780 | } |
| 6781 | } finally { |
| 6782 | Binder.restoreCallingIdentity(identity); |
| 6783 | } |
| 6784 | } |
| 6785 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6786 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6787 | Phone phone) { |
Sarah Chin | 3394efe | 2021-04-09 10:37:15 -0700 | [diff] [blame] | 6788 | if (uid == Process.PHONE_UID) { |
| 6789 | // Skip the check if it's the phone UID (system UID removed in b/184713596) |
| 6790 | // 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] | 6791 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6792 | } |
| 6793 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6794 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6795 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6796 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6797 | || subController == null) return privilegeFromSim; |
| 6798 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6799 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6800 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6801 | |
| 6802 | final long identity = Binder.clearCallingIdentity(); |
| 6803 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6804 | int subId = phone.getSubId(); |
| 6805 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6806 | // A test override is in place for the privileges for this subId, so don't try to |
| 6807 | // read the subscription privileges. |
| 6808 | return privilegeFromSim; |
| 6809 | } |
| 6810 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6811 | SubscriptionManager subManager = (SubscriptionManager) |
| 6812 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6813 | for (String pkg : packages) { |
| 6814 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6815 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6816 | } |
| 6817 | } |
| 6818 | return privilegeFromSim; |
| 6819 | } finally { |
| 6820 | Binder.restoreCallingIdentity(identity); |
| 6821 | } |
| 6822 | } |
| 6823 | |
| 6824 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6825 | String pkgName) { |
| 6826 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6827 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6828 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6829 | || subController == null) return privilegeFromSim; |
| 6830 | |
| 6831 | final long identity = Binder.clearCallingIdentity(); |
| 6832 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6833 | int subId = phone.getSubId(); |
| 6834 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6835 | // A test override is in place for the privileges for this subId, so don't try to |
| 6836 | // read the subscription privileges. |
| 6837 | return privilegeFromSim; |
| 6838 | } |
| 6839 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6840 | SubscriptionManager subManager = (SubscriptionManager) |
| 6841 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6842 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6843 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6844 | } finally { |
| 6845 | Binder.restoreCallingIdentity(identity); |
| 6846 | } |
| 6847 | } |
| 6848 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6849 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6850 | public int getCarrierPrivilegeStatus(int subId) { |
| 6851 | final Phone phone = getPhone(subId); |
| 6852 | if (phone == null) { |
| 6853 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6854 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6855 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6856 | UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
| 6857 | if (port == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6858 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6859 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6860 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6861 | |
| 6862 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6863 | port.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6864 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6865 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6866 | |
| 6867 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6868 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6869 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6870 | final Phone phone = getPhone(subId); |
| 6871 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6872 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6873 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6874 | } |
| 6875 | UiccProfile profile = |
| 6876 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6877 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6878 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6879 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6880 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6881 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6882 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6883 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6884 | } |
| 6885 | |
| 6886 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6887 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6888 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6889 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6890 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6891 | } |
| 6892 | |
| 6893 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6894 | UiccPort port = UiccController.getInstance().getUiccPort(phoneId); |
| 6895 | if (port == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6896 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6897 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6898 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6899 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6900 | port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6901 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6902 | } |
| 6903 | |
| 6904 | @Override |
| 6905 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Sarah Chin | fc3169b | 2021-04-28 20:21:03 -0700 | [diff] [blame] | 6906 | // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6907 | if (TextUtils.isEmpty(pkgName)) |
| 6908 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6909 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6910 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6911 | UiccPort port = UiccController.getInstance().getUiccPort(i); |
| 6912 | if (port == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6913 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6914 | continue; |
| 6915 | } |
| 6916 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6917 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6918 | port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6919 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6920 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6921 | break; |
| 6922 | } |
| 6923 | } |
| 6924 | |
| 6925 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6926 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6927 | |
| 6928 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6929 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6930 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6931 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6932 | loge("phoneId " + phoneId + " is not valid."); |
| 6933 | return null; |
| 6934 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6935 | UiccPort port = UiccController.getInstance().getUiccPort(phoneId); |
| 6936 | if (port == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6937 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6938 | return null ; |
| 6939 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6940 | return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6941 | } |
| 6942 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6943 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6944 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6945 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6946 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6947 | List<String> privilegedPackages = new ArrayList<>(); |
| 6948 | List<PackageInfo> packages = null; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6949 | UiccPort port = UiccController.getInstance().getUiccPort(phoneId); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6950 | // has UICC in that slot. |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6951 | if (port != null) { |
| 6952 | if (port.hasCarrierPrivilegeRules()) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6953 | if (packages == null) { |
| 6954 | // Only check packages in user 0 for now |
| 6955 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6956 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6957 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6958 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6959 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6960 | } |
| 6961 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6962 | PackageInfo pkgInfo = packages.get(p); |
| 6963 | if (pkgInfo != null && pkgInfo.packageName != null |
Sooraj Sasindran | 97bce6f | 2021-09-28 21:37:29 +0000 | [diff] [blame] | 6964 | && getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6965 | port.getCarrierPrivilegeStatus(pkgInfo), |
| 6966 | getPhone(phoneId), pkgInfo.packageName) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6967 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6968 | privilegedPackages.add(pkgInfo.packageName); |
| 6969 | } |
| 6970 | } |
| 6971 | } |
| 6972 | } |
| 6973 | return privilegedPackages; |
| 6974 | } |
| 6975 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6976 | @Override |
| 6977 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6978 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6979 | |
| 6980 | final long identity = Binder.clearCallingIdentity(); |
| 6981 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6982 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6983 | try { |
| 6984 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6985 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6986 | } |
| 6987 | } finally { |
| 6988 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6989 | } |
| 6990 | return privilegedPackages; |
| 6991 | } |
| 6992 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6993 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6994 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6995 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 6996 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6997 | return null; |
| 6998 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6999 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7000 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7001 | return null; |
| 7002 | } |
| 7003 | return iccId; |
| 7004 | } |
| 7005 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7006 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7007 | public void setCallComposerStatus(int subId, int status) { |
| 7008 | enforceModifyPermission(); |
| 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 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7018 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7019 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7020 | } |
| 7021 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7022 | } catch (ImsException e) { |
| 7023 | throw new ServiceSpecificException(e.getCode()); |
| 7024 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7025 | Binder.restoreCallingIdentity(identity); |
| 7026 | } |
| 7027 | } |
| 7028 | |
| 7029 | @Override |
| 7030 | public int getCallComposerStatus(int subId) { |
| 7031 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7032 | |
| 7033 | final long identity = Binder.clearCallingIdentity(); |
| 7034 | try { |
| 7035 | Phone phone = getPhone(subId); |
| 7036 | if (phone != null) { |
| 7037 | Phone defaultPhone = phone.getImsPhone(); |
| 7038 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7039 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7040 | return imsPhone.getCallComposerStatus(); |
| 7041 | } |
| 7042 | } |
| 7043 | } finally { |
| 7044 | Binder.restoreCallingIdentity(identity); |
| 7045 | } |
| 7046 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7047 | } |
| 7048 | |
| 7049 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7050 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7051 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7052 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7053 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7054 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7055 | final long identity = Binder.clearCallingIdentity(); |
| 7056 | try { |
| 7057 | final String iccId = getIccId(subId); |
| 7058 | final Phone phone = getPhone(subId); |
| 7059 | if (phone == null) { |
| 7060 | return false; |
| 7061 | } |
| 7062 | final String subscriberId = phone.getSubscriberId(); |
| 7063 | |
| 7064 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7065 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7066 | + subscriberId + " to " + number); |
| 7067 | } |
| 7068 | |
| 7069 | if (TextUtils.isEmpty(iccId)) { |
| 7070 | return false; |
| 7071 | } |
| 7072 | |
| 7073 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7074 | |
| 7075 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7076 | if (alphaTag == null) { |
| 7077 | editor.remove(alphaTagPrefKey); |
| 7078 | } else { |
| 7079 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7080 | } |
| 7081 | |
| 7082 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7083 | // track all merged IMSIs based on line number |
| 7084 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7085 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7086 | if (number == null) { |
| 7087 | editor.remove(numberPrefKey); |
| 7088 | editor.remove(subscriberPrefKey); |
| 7089 | } else { |
| 7090 | editor.putString(numberPrefKey, number); |
| 7091 | editor.putString(subscriberPrefKey, subscriberId); |
| 7092 | } |
| 7093 | |
| 7094 | editor.commit(); |
| 7095 | return true; |
| 7096 | } finally { |
| 7097 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7098 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7099 | } |
| 7100 | |
| 7101 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7102 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7103 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7104 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7105 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7106 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7107 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7108 | return null; |
| 7109 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7110 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7111 | final long identity = Binder.clearCallingIdentity(); |
| 7112 | try { |
| 7113 | String iccId = getIccId(subId); |
| 7114 | if (iccId != null) { |
| 7115 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7116 | if (DBG_MERGE) { |
| 7117 | log("getLine1NumberForDisplay returning " |
| 7118 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7119 | } |
| 7120 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7121 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7122 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7123 | return null; |
| 7124 | } finally { |
| 7125 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7126 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7127 | } |
| 7128 | |
| 7129 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7130 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7131 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7132 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7133 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7134 | return null; |
| 7135 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7136 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7137 | final long identity = Binder.clearCallingIdentity(); |
| 7138 | try { |
| 7139 | String iccId = getIccId(subId); |
| 7140 | if (iccId != null) { |
| 7141 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7142 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7143 | } |
| 7144 | return null; |
| 7145 | } finally { |
| 7146 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7147 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7148 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7149 | |
| 7150 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7151 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7152 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7153 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7154 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7155 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7156 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7157 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7158 | return null; |
| 7159 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7160 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7161 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7162 | // the process, where TelephonyManager was instantiated. |
| 7163 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7164 | final long identity = Binder.clearCallingIdentity(); |
| 7165 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7166 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7167 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7168 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7169 | |
| 7170 | // Figure out what subscribers are currently active |
| 7171 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7172 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7173 | // Only consider subs which match the current subId |
| 7174 | // This logic can be simplified. See b/131189269 for progress. |
| 7175 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7176 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7177 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7178 | |
| 7179 | // First pass, find a number override for an active subscriber |
| 7180 | String mergeNumber = null; |
| 7181 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7182 | for (String key : prefs.keySet()) { |
| 7183 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7184 | final String subscriberId = (String) prefs.get(key); |
| 7185 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7186 | final String iccId = key.substring( |
| 7187 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7188 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7189 | mergeNumber = (String) prefs.get(numberKey); |
| 7190 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7191 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7192 | + " for active subscriber " + subscriberId); |
| 7193 | } |
| 7194 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7195 | break; |
| 7196 | } |
| 7197 | } |
| 7198 | } |
| 7199 | } |
| 7200 | |
| 7201 | // Shortcut when no active merged subscribers |
| 7202 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7203 | return null; |
| 7204 | } |
| 7205 | |
| 7206 | // Second pass, find all subscribers under that line override |
| 7207 | final ArraySet<String> result = new ArraySet<>(); |
| 7208 | for (String key : prefs.keySet()) { |
| 7209 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7210 | final String number = (String) prefs.get(key); |
| 7211 | if (mergeNumber.equals(number)) { |
| 7212 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7213 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7214 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7215 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7216 | result.add(subscriberId); |
| 7217 | } |
| 7218 | } |
| 7219 | } |
| 7220 | } |
| 7221 | |
| 7222 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7223 | Arrays.sort(resultArray); |
| 7224 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7225 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7226 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7227 | } |
| 7228 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7229 | } finally { |
| 7230 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7231 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7232 | } |
| 7233 | |
| 7234 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7235 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7236 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7237 | |
| 7238 | final long identity = Binder.clearCallingIdentity(); |
| 7239 | try { |
| 7240 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7241 | TelephonyManager.class); |
| 7242 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7243 | if (subscriberId == null) { |
| 7244 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7245 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7246 | + subId); |
| 7247 | } |
| 7248 | return null; |
| 7249 | } |
| 7250 | |
| 7251 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 7252 | .getSubscriptionInfo(subId); |
| 7253 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 7254 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7255 | if (groupUuid == null) { |
| 7256 | return new String[]{subscriberId}; |
| 7257 | } |
| 7258 | |
| 7259 | // Get all subscriberIds from the group. |
| 7260 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 7261 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7262 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7263 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7264 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7265 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7266 | if (subscriberId != null) { |
| 7267 | mergedSubscriberIds.add(subscriberId); |
| 7268 | } |
| 7269 | } |
| 7270 | |
| 7271 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7272 | } finally { |
| 7273 | Binder.restoreCallingIdentity(identity); |
| 7274 | |
| 7275 | } |
| 7276 | } |
| 7277 | |
| 7278 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7279 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7280 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7281 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7282 | |
| 7283 | final long identity = Binder.clearCallingIdentity(); |
| 7284 | try { |
| 7285 | final Phone phone = getPhone(subId); |
| 7286 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7287 | } finally { |
| 7288 | Binder.restoreCallingIdentity(identity); |
| 7289 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7290 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7291 | |
| 7292 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7293 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7294 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7295 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7296 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7297 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7298 | |
| 7299 | final long identity = Binder.clearCallingIdentity(); |
| 7300 | try { |
| 7301 | final Phone phone = getPhone(subId); |
| 7302 | if (phone == null) { |
| 7303 | return false; |
| 7304 | } |
| 7305 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7306 | cdmaNonRoamingList); |
| 7307 | } finally { |
| 7308 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7309 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7310 | } |
| 7311 | |
| 7312 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7313 | @Deprecated |
| 7314 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7315 | enforceModifyPermission(); |
| 7316 | |
| 7317 | int returnValue = 0; |
| 7318 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7319 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7320 | if(result.exception == null) { |
| 7321 | if (result.result != null) { |
| 7322 | byte[] responseData = (byte[])(result.result); |
| 7323 | if(responseData.length > oemResp.length) { |
| 7324 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7325 | responseData.length + "bytes. Buffer Size is " + |
| 7326 | oemResp.length + "bytes."); |
| 7327 | } |
| 7328 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7329 | returnValue = responseData.length; |
| 7330 | } |
| 7331 | } else { |
| 7332 | CommandException ex = (CommandException) result.exception; |
| 7333 | returnValue = ex.getCommandError().ordinal(); |
| 7334 | if(returnValue > 0) returnValue *= -1; |
| 7335 | } |
| 7336 | } catch (RuntimeException e) { |
| 7337 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7338 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7339 | if(returnValue > 0) returnValue *= -1; |
| 7340 | } |
| 7341 | |
| 7342 | return returnValue; |
| 7343 | } |
| 7344 | |
| 7345 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7346 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7347 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7348 | try { |
| 7349 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7350 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7351 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7352 | } catch (SecurityException e) { |
| 7353 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7354 | throw e; |
| 7355 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7356 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7357 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7358 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7359 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7360 | final long identity = Binder.clearCallingIdentity(); |
| 7361 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7362 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7363 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7364 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7365 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7366 | } finally { |
| 7367 | Binder.restoreCallingIdentity(identity); |
| 7368 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7369 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7370 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7371 | |
| 7372 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7373 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7374 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7375 | try { |
| 7376 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7377 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7378 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7379 | } |
| 7380 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7381 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7382 | } |
| 7383 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7384 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7385 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7386 | throw new SecurityException("App must be the dialer role holder to" |
| 7387 | + " upload a call composer pic"); |
| 7388 | } |
| 7389 | |
| 7390 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7391 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7392 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7393 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7394 | boolean readUntilEnd = false; |
| 7395 | int totalBytesRead = 0; |
| 7396 | byte[] buffer = new byte[16 * 1024]; |
| 7397 | while (true) { |
| 7398 | int numRead; |
| 7399 | try { |
| 7400 | numRead = input.read(buffer); |
| 7401 | } catch (IOException e) { |
| 7402 | try { |
| 7403 | fd.checkError(); |
| 7404 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7405 | null); |
| 7406 | } catch (IOException e1) { |
| 7407 | // This means that the other side closed explicitly with an error. If this |
| 7408 | // happens, log and ignore. |
| 7409 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7410 | } |
| 7411 | break; |
| 7412 | } |
| 7413 | if (numRead == -1) { |
| 7414 | readUntilEnd = true; |
| 7415 | break; |
| 7416 | } |
| 7417 | totalBytesRead += numRead; |
| 7418 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7419 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7420 | try { |
| 7421 | input.close(); |
| 7422 | } catch (IOException e) { |
| 7423 | // ignore |
| 7424 | } |
| 7425 | break; |
| 7426 | } |
| 7427 | output.write(buffer, 0, numRead); |
| 7428 | } |
| 7429 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7430 | // close is above, where the picture size is too big. |
| 7431 | |
| 7432 | try { |
| 7433 | fd.checkError(); |
| 7434 | } catch (IOException e) { |
| 7435 | loge("Remote end for call composer closed with an error: " + e); |
| 7436 | return; |
| 7437 | } |
| 7438 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7439 | if (!readUntilEnd) { |
| 7440 | loge("Did not finish reading entire image; aborting"); |
| 7441 | return; |
| 7442 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7443 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7444 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7445 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7446 | new CallComposerPictureTransfer.Factory() {}, |
| 7447 | imageData, |
| 7448 | (result) -> { |
| 7449 | if (result.first != null) { |
| 7450 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7451 | Bundle outputResult = new Bundle(); |
| 7452 | outputResult.putParcelable( |
| 7453 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7454 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7455 | outputResult); |
| 7456 | } else { |
| 7457 | callback.send(result.second, null); |
| 7458 | } |
| 7459 | } |
| 7460 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7461 | }); |
| 7462 | } |
| 7463 | |
| 7464 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7465 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7466 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7467 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7468 | |
| 7469 | final long identity = Binder.clearCallingIdentity(); |
| 7470 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7471 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7472 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7473 | } finally { |
| 7474 | Binder.restoreCallingIdentity(identity); |
| 7475 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7476 | } |
| 7477 | |
| 7478 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7479 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7480 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7481 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7482 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7483 | return false; |
| 7484 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7485 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7486 | final long identity = Binder.clearCallingIdentity(); |
| 7487 | try { |
| 7488 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7489 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7490 | // In the long run, we may instead need to check if there exists a connection service |
| 7491 | // which can support video calling. |
| 7492 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7493 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7494 | return imsManager.isVtEnabledByPlatform() |
| 7495 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7496 | && imsManager.isVtEnabledByUser(); |
| 7497 | } finally { |
| 7498 | Binder.restoreCallingIdentity(identity); |
| 7499 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7500 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7501 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7502 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7503 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7504 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7505 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7506 | mApp, subId, callingPackage, callingFeatureId, |
| 7507 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7508 | return false; |
| 7509 | } |
| 7510 | |
| 7511 | final long identity = Binder.clearCallingIdentity(); |
| 7512 | try { |
| 7513 | CarrierConfigManager configManager = |
| 7514 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7515 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7516 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7517 | } finally { |
| 7518 | Binder.restoreCallingIdentity(identity); |
| 7519 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7520 | } |
| 7521 | |
| 7522 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7523 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7524 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7525 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7526 | return false; |
| 7527 | } |
| 7528 | |
| 7529 | final long identity = Binder.clearCallingIdentity(); |
| 7530 | try { |
| 7531 | CarrierConfigManager configManager = |
| 7532 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7533 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7534 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7535 | } finally { |
| 7536 | Binder.restoreCallingIdentity(identity); |
| 7537 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7538 | } |
| 7539 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7540 | @Override |
| 7541 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7542 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7543 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7544 | } |
| 7545 | |
| 7546 | @Override |
| 7547 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7548 | final long identity = Binder.clearCallingIdentity(); |
| 7549 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7550 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7551 | } finally { |
| 7552 | Binder.restoreCallingIdentity(identity); |
| 7553 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7554 | } |
| 7555 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7556 | /** |
| 7557 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7558 | * support for the feature and device firmware support. |
| 7559 | * |
| 7560 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7561 | */ |
| 7562 | @Override |
| 7563 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7564 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7565 | final Phone phone = getPhone(subscriptionId); |
| 7566 | if (phone == null) { |
| 7567 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7568 | return false; |
| 7569 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7570 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7571 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7572 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7573 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7574 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7575 | return isCarrierSupported && isDeviceSupported; |
| 7576 | } finally { |
| 7577 | Binder.restoreCallingIdentity(identity); |
| 7578 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7579 | } |
| 7580 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7581 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7582 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7583 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7584 | * 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] | 7585 | */ |
| 7586 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7587 | final long identity = Binder.clearCallingIdentity(); |
| 7588 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7589 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7590 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7591 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7592 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7593 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7594 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7595 | } finally { |
| 7596 | Binder.restoreCallingIdentity(identity); |
| 7597 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7598 | } |
| 7599 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7600 | @Deprecated |
| 7601 | @Override |
| 7602 | public String getDeviceId(String callingPackage) { |
| 7603 | return getDeviceIdWithFeature(callingPackage, null); |
| 7604 | } |
| 7605 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7606 | /** |
| 7607 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7608 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7609 | * |
| 7610 | * <p>Requires Permission: |
| 7611 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7612 | */ |
| 7613 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7614 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7615 | try { |
| 7616 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7617 | } catch (SecurityException se) { |
| 7618 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7619 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7620 | + Binder.getCallingUid()); |
| 7621 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7622 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7623 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7624 | return null; |
| 7625 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7626 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7627 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7628 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7629 | return null; |
| 7630 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7631 | |
| 7632 | final long identity = Binder.clearCallingIdentity(); |
| 7633 | try { |
| 7634 | return phone.getDeviceId(); |
| 7635 | } finally { |
| 7636 | Binder.restoreCallingIdentity(identity); |
| 7637 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7638 | } |
| 7639 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7640 | /** |
| 7641 | * {@hide} |
| 7642 | * Returns the IMS Registration Status on a particular subid |
| 7643 | * |
| 7644 | * @param subId |
| 7645 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7646 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7647 | Phone phone = getPhone(subId); |
| 7648 | if (phone != null) { |
| 7649 | return phone.isImsRegistered(); |
| 7650 | } else { |
| 7651 | return false; |
| 7652 | } |
| 7653 | } |
| 7654 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7655 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7656 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7657 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7658 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7659 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7660 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7661 | } |
| 7662 | final long identity = Binder.clearCallingIdentity(); |
| 7663 | try { |
| 7664 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7665 | } finally { |
| 7666 | Binder.restoreCallingIdentity(identity); |
| 7667 | } |
| 7668 | } |
| 7669 | |
| 7670 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7671 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7672 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7673 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7674 | mApp, |
| 7675 | subscriptionId, |
| 7676 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7677 | final long identity = Binder.clearCallingIdentity(); |
| 7678 | try { |
| 7679 | Phone phone = getPhone(subscriptionId); |
| 7680 | if (phone == null) { |
| 7681 | return null; |
| 7682 | } |
| 7683 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7684 | } finally { |
| 7685 | Binder.restoreCallingIdentity(identity); |
| 7686 | } |
| 7687 | } |
| 7688 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7689 | /** |
| 7690 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7691 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7692 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7693 | final long identity = Binder.clearCallingIdentity(); |
| 7694 | try { |
| 7695 | Phone phone = getPhone(subId); |
| 7696 | if (phone != null) { |
| 7697 | return phone.isWifiCallingEnabled(); |
| 7698 | } else { |
| 7699 | return false; |
| 7700 | } |
| 7701 | } finally { |
| 7702 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7703 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7704 | } |
| 7705 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7706 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7707 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7708 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7709 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7710 | final long identity = Binder.clearCallingIdentity(); |
| 7711 | try { |
| 7712 | Phone phone = getPhone(subId); |
| 7713 | if (phone != null) { |
| 7714 | return phone.isVideoEnabled(); |
| 7715 | } else { |
| 7716 | return false; |
| 7717 | } |
| 7718 | } finally { |
| 7719 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7720 | } |
| 7721 | } |
| 7722 | |
| 7723 | /** |
| 7724 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7725 | * defined in {@link ImsRegistrationImplBase}. |
| 7726 | */ |
| 7727 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7728 | final long identity = Binder.clearCallingIdentity(); |
| 7729 | try { |
| 7730 | Phone phone = getPhone(subId); |
| 7731 | if (phone != null) { |
| 7732 | return phone.getImsRegistrationTech(); |
| 7733 | } else { |
| 7734 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7735 | } |
| 7736 | } finally { |
| 7737 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7738 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7739 | } |
| 7740 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7741 | @Override |
| 7742 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7743 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7744 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7745 | return; |
| 7746 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7747 | Phone defaultPhone = getDefaultPhone(); |
| 7748 | if (defaultPhone != null) { |
| 7749 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7750 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7751 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7752 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7753 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7754 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7755 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7756 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7757 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7758 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7759 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7760 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7761 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7762 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7763 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7764 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7765 | // There has been issues when Sms raw table somehow stores orphan |
| 7766 | // fragments. They lead to garbled message when new fragments come |
| 7767 | // in and combined with those stale ones. In case this happens again, |
| 7768 | // user can reset all network settings which will clean up this table. |
| 7769 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7770 | // Clean up IMS settings as well here. |
| 7771 | int slotId = getSlotIndex(subId); |
| 7772 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7773 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7774 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7775 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7776 | if (defaultPhone == null) { |
| 7777 | return; |
| 7778 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7779 | // Erase modem config if erase modem on network setting is enabled. |
| 7780 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7781 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7782 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7783 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7784 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7785 | |
| 7786 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7787 | } finally { |
| 7788 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7789 | } |
| 7790 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7791 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7792 | @VisibleForTesting |
| 7793 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7794 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7795 | return; |
| 7796 | } |
| 7797 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7798 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7799 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7800 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7801 | "user=" + defaultNetworkType); |
| 7802 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7803 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7804 | defaultNetworkType, null); |
| 7805 | } |
| 7806 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7807 | private void cleanUpSmsRawTable(Context context) { |
| 7808 | ContentResolver resolver = context.getContentResolver(); |
| 7809 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7810 | resolver.delete(uri, null, null); |
| 7811 | } |
| 7812 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7813 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7814 | public String getSimLocaleForSubscriber(int subId) { |
| 7815 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7816 | final Phone phone = getPhone(subId); |
| 7817 | if (phone == null) { |
| 7818 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7819 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7820 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7821 | final long identity = Binder.clearCallingIdentity(); |
| 7822 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7823 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7824 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7825 | if (info == null) { |
| 7826 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7827 | return null; |
| 7828 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7829 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7830 | // preferences (EF-PL and EF-LI)... |
| 7831 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7832 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7833 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7834 | if (localeFromDefaultSim != null) { |
| 7835 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7836 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7837 | + localeFromDefaultSim); |
| 7838 | return localeFromDefaultSim.toLanguageTag(); |
| 7839 | } else { |
| 7840 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7841 | } |
| 7842 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7843 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7844 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7845 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7846 | // the SIM and carrier preferences does not include a country we add the country |
| 7847 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7848 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7849 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7850 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7851 | return mccLocale.toLanguageTag(); |
| 7852 | } |
| 7853 | |
| 7854 | if (DBG) log("No locale found - returning null"); |
| 7855 | return null; |
| 7856 | } finally { |
| 7857 | Binder.restoreCallingIdentity(identity); |
| 7858 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7859 | } |
| 7860 | |
| 7861 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7862 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7863 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7864 | } |
| 7865 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7866 | /** |
| 7867 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7868 | */ |
| 7869 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7870 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7871 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7872 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7873 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7874 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7875 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7876 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7877 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7878 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7879 | * representing the state of the modem. |
| 7880 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7881 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7882 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7883 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7884 | */ |
| 7885 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7886 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7887 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7888 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7889 | |
| 7890 | final long identity = Binder.clearCallingIdentity(); |
| 7891 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7892 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7893 | } finally { |
| 7894 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7895 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7896 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7897 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7898 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7899 | // less than total activity duration. |
| 7900 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7901 | if (info == null) { |
| 7902 | return false; |
| 7903 | } |
| 7904 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7905 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7906 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7907 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7908 | return (info.isValid() |
| 7909 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7910 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7911 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7912 | && (totalTxTimeMs <= activityDurationMs)); |
| 7913 | } |
| 7914 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7915 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7916 | * Returns the service state information on specified subscription. |
| 7917 | */ |
| 7918 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7919 | public ServiceState getServiceStateForSubscriber(int subId, |
| 7920 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 7921 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7922 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7923 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7924 | return null; |
| 7925 | } |
| 7926 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7927 | boolean hasFinePermission = false; |
| 7928 | boolean hasCoarsePermission = false; |
| 7929 | if (!renounceFineLocationAccess) { |
| 7930 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7931 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7932 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7933 | .setCallingPackage(callingPackage) |
| 7934 | .setCallingFeatureId(callingFeatureId) |
| 7935 | .setCallingPid(Binder.getCallingPid()) |
| 7936 | .setCallingUid(Binder.getCallingUid()) |
| 7937 | .setMethod("getServiceStateForSubscriber") |
| 7938 | .setLogAsInfo(true) |
| 7939 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7940 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7941 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7942 | .build()); |
| 7943 | hasFinePermission = |
| 7944 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7945 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7946 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7947 | if (!renounceCoarseLocationAccess) { |
| 7948 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7949 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7950 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7951 | .setCallingPackage(callingPackage) |
| 7952 | .setCallingFeatureId(callingFeatureId) |
| 7953 | .setCallingPid(Binder.getCallingPid()) |
| 7954 | .setCallingUid(Binder.getCallingUid()) |
| 7955 | .setMethod("getServiceStateForSubscriber") |
| 7956 | .setLogAsInfo(true) |
| 7957 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7958 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7959 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7960 | .build()); |
| 7961 | hasCoarsePermission = |
| 7962 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7963 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7964 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7965 | final Phone phone = getPhone(subId); |
| 7966 | if (phone == null) { |
| 7967 | return null; |
| 7968 | } |
| 7969 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7970 | final long identity = Binder.clearCallingIdentity(); |
| 7971 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7972 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7973 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7974 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7975 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7976 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7977 | Rlog.d(LOG_TAG, |
| 7978 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7979 | return null; |
| 7980 | } |
| 7981 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7982 | ServiceState ss = phone.getServiceState(); |
| 7983 | |
| 7984 | // Scrub out the location info in ServiceState depending on what level of access |
| 7985 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7986 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7987 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7988 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7989 | } finally { |
| 7990 | Binder.restoreCallingIdentity(identity); |
| 7991 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7992 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7993 | |
| 7994 | /** |
| 7995 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7996 | * |
| 7997 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7998 | * voicemail ringtone. |
| 7999 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8000 | * PhoneAccount. |
| 8001 | */ |
| 8002 | @Override |
| 8003 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8004 | final long identity = Binder.clearCallingIdentity(); |
| 8005 | try { |
| 8006 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8007 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8008 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8009 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8010 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8011 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8012 | } finally { |
| 8013 | Binder.restoreCallingIdentity(identity); |
| 8014 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8015 | } |
| 8016 | |
| 8017 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8018 | * Sets the per-account voicemail ringtone. |
| 8019 | * |
| 8020 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8021 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8022 | * |
| 8023 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8024 | * voicemail ringtone. |
| 8025 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8026 | * PhoneAccount. |
| 8027 | */ |
| 8028 | @Override |
| 8029 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8030 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8031 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8032 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8033 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8034 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8035 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8036 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8037 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8038 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8039 | |
| 8040 | final long identity = Binder.clearCallingIdentity(); |
| 8041 | try { |
| 8042 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8043 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8044 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8045 | } |
| 8046 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8047 | } finally { |
| 8048 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8049 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8050 | } |
| 8051 | |
| 8052 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8053 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8054 | * |
| 8055 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8056 | * voicemail vibration setting. |
| 8057 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8058 | */ |
| 8059 | @Override |
| 8060 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8061 | final long identity = Binder.clearCallingIdentity(); |
| 8062 | try { |
| 8063 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8064 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8065 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8066 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8067 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8068 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8069 | } finally { |
| 8070 | Binder.restoreCallingIdentity(identity); |
| 8071 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8072 | } |
| 8073 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8074 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8075 | * Sets the per-account voicemail vibration. |
| 8076 | * |
| 8077 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8078 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8079 | * |
| 8080 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8081 | * voicemail vibration setting. |
| 8082 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8083 | * specific PhoneAccount. |
| 8084 | */ |
| 8085 | @Override |
| 8086 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8087 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8088 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8089 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8090 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8091 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8092 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8093 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8094 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8095 | } |
| 8096 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8097 | final long identity = Binder.clearCallingIdentity(); |
| 8098 | try { |
| 8099 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8100 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8101 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8102 | } |
| 8103 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8104 | } finally { |
| 8105 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8106 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8107 | } |
| 8108 | |
| 8109 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8110 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8111 | * |
| 8112 | * @throws SecurityException if the caller does not have the required permission |
| 8113 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8114 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8115 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8116 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8117 | } |
| 8118 | |
| 8119 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8120 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8121 | * permission. |
| 8122 | * |
| 8123 | * @throws SecurityException if the caller does not have the required permission |
| 8124 | */ |
| 8125 | private void enforceSendSmsPermission() { |
| 8126 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8127 | } |
| 8128 | |
| 8129 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8130 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8131 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8132 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8133 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8134 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8135 | final long identity = Binder.clearCallingIdentity(); |
| 8136 | try { |
| 8137 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8138 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8139 | if (componentName == null) { |
| 8140 | throw new SecurityException( |
| 8141 | "Caller not current active visual voicemail package[null]"); |
| 8142 | } |
| 8143 | String vvmPackage = componentName.getPackageName(); |
| 8144 | if (!callingPackage.equals(vvmPackage)) { |
| 8145 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 8146 | + vvmPackage + "]"); |
| 8147 | } |
| 8148 | } finally { |
| 8149 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8150 | } |
| 8151 | } |
| 8152 | |
| 8153 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8154 | * Return the application ID for the app type. |
| 8155 | * |
| 8156 | * @param subId the subscription ID that this request applies to. |
| 8157 | * @param appType the uicc app type. |
| 8158 | * @return Application ID for specificied app type, or null if no uicc. |
| 8159 | */ |
| 8160 | @Override |
| 8161 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8162 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8163 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8164 | |
| 8165 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8166 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8167 | if (phone == null) { |
| 8168 | return null; |
| 8169 | } |
| 8170 | String aid = null; |
| 8171 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8172 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8173 | .getApplicationByType(appType).getAid(); |
| 8174 | } catch (Exception e) { |
| 8175 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8176 | } |
| 8177 | return aid; |
| 8178 | } finally { |
| 8179 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8180 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8181 | } |
| 8182 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8183 | /** |
| 8184 | * Return the Electronic Serial Number. |
| 8185 | * |
| 8186 | * @param subId the subscription ID that this request applies to. |
| 8187 | * @return ESN or null if error. |
| 8188 | */ |
| 8189 | @Override |
| 8190 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8191 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8192 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8193 | |
| 8194 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8195 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8196 | if (phone == null) { |
| 8197 | return null; |
| 8198 | } |
| 8199 | String esn = null; |
| 8200 | try { |
| 8201 | esn = phone.getEsn(); |
| 8202 | } catch (Exception e) { |
| 8203 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8204 | } |
| 8205 | return esn; |
| 8206 | } finally { |
| 8207 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8208 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8209 | } |
| 8210 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8211 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8212 | * Return the Preferred Roaming List Version. |
| 8213 | * |
| 8214 | * @param subId the subscription ID that this request applies to. |
| 8215 | * @return PRLVersion or null if error. |
| 8216 | */ |
| 8217 | @Override |
| 8218 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8219 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8220 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8221 | |
| 8222 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8223 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8224 | if (phone == null) { |
| 8225 | return null; |
| 8226 | } |
| 8227 | String cdmaPrlVersion = null; |
| 8228 | try { |
| 8229 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8230 | } catch (Exception e) { |
| 8231 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8232 | } |
| 8233 | return cdmaPrlVersion; |
| 8234 | } finally { |
| 8235 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8236 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8237 | } |
| 8238 | |
| 8239 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8240 | * Get snapshot of Telephony histograms |
| 8241 | * @return List of Telephony histograms |
| 8242 | * @hide |
| 8243 | */ |
| 8244 | @Override |
| 8245 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8246 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8247 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8248 | |
| 8249 | final long identity = Binder.clearCallingIdentity(); |
| 8250 | try { |
| 8251 | return RIL.getTelephonyRILTimingHistograms(); |
| 8252 | } finally { |
| 8253 | Binder.restoreCallingIdentity(identity); |
| 8254 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8255 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8256 | |
| 8257 | /** |
| 8258 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8259 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8260 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8261 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8262 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8263 | * @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] | 8264 | */ |
| 8265 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8266 | @TelephonyManager.SetCarrierRestrictionResult |
| 8267 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8268 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8269 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8270 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8271 | if (carrierRestrictionRules == null) { |
| 8272 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8273 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8274 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8275 | final long identity = Binder.clearCallingIdentity(); |
| 8276 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8277 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8278 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8279 | } finally { |
| 8280 | Binder.restoreCallingIdentity(identity); |
| 8281 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8282 | } |
| 8283 | |
| 8284 | /** |
| 8285 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8286 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8287 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8288 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8289 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8290 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8291 | */ |
| 8292 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8293 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8294 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8295 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8296 | |
| 8297 | final long identity = Binder.clearCallingIdentity(); |
| 8298 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8299 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8300 | if (response instanceof CarrierRestrictionRules) { |
| 8301 | return (CarrierRestrictionRules) response; |
| 8302 | } |
| 8303 | // Response is an Exception of some kind, |
| 8304 | // which is signalled to the user as a NULL retval |
| 8305 | return null; |
| 8306 | } catch (Exception e) { |
| 8307 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8308 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8309 | } finally { |
| 8310 | Binder.restoreCallingIdentity(identity); |
| 8311 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8312 | } |
| 8313 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8314 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8315 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8316 | * @param subId the subscription ID that this action applies to. |
| 8317 | * @param enabled control enable or disable radio. |
| 8318 | * {@hide} |
| 8319 | */ |
| 8320 | @Override |
| 8321 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8322 | enforceModifyPermission(); |
| 8323 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8324 | |
| 8325 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8326 | if (phone == null) { |
| 8327 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8328 | return; |
| 8329 | } |
| 8330 | try { |
| 8331 | phone.carrierActionSetRadioEnabled(enabled); |
| 8332 | } catch (Exception e) { |
| 8333 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8334 | } finally { |
| 8335 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8336 | } |
| 8337 | } |
| 8338 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8339 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8340 | * Enable or disable Voice over NR (VoNR) |
| 8341 | * @param subId the subscription ID that this action applies to. |
| 8342 | * @param enabled enable or disable VoNR. |
| 8343 | * @return operation result. |
| 8344 | */ |
| 8345 | @Override |
| 8346 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8347 | enforceModifyPermission(); |
| 8348 | final Phone phone = getPhone(subId); |
| 8349 | |
| 8350 | final long identity = Binder.clearCallingIdentity(); |
| 8351 | if (phone == null) { |
| 8352 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8353 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8354 | } |
| 8355 | |
| 8356 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8357 | try { |
| 8358 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8359 | workSource); |
| 8360 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8361 | |
| 8362 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8363 | if (DBG) { |
| 8364 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8365 | } |
| 8366 | SubscriptionManager.setSubscriptionProperty( |
| 8367 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8368 | (enabled ? "1" : "0")); |
| 8369 | } |
| 8370 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8371 | return result; |
| 8372 | } finally { |
| 8373 | Binder.restoreCallingIdentity(identity); |
| 8374 | } |
| 8375 | } |
| 8376 | |
| 8377 | /** |
| 8378 | * Is voice over NR enabled |
| 8379 | * @return true if VoNR is enabled else false |
| 8380 | */ |
| 8381 | @Override |
| 8382 | public boolean isVoNrEnabled(int subId) { |
| 8383 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8384 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8385 | final long identity = Binder.clearCallingIdentity(); |
| 8386 | try { |
| 8387 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8388 | null, subId, workSource); |
| 8389 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8390 | return isEnabled; |
| 8391 | } finally { |
| 8392 | Binder.restoreCallingIdentity(identity); |
| 8393 | } |
| 8394 | } |
| 8395 | |
| 8396 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8397 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8398 | * network status based on which carrier apps could apply actions accordingly, |
| 8399 | * enable/disable default url handler for example. |
| 8400 | * |
| 8401 | * @param subId the subscription ID that this action applies to. |
| 8402 | * @param report control start/stop reporting the default network status. |
| 8403 | * {@hide} |
| 8404 | */ |
| 8405 | @Override |
| 8406 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8407 | enforceModifyPermission(); |
| 8408 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8409 | |
| 8410 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8411 | if (phone == null) { |
| 8412 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8413 | return; |
| 8414 | } |
| 8415 | try { |
| 8416 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8417 | } catch (Exception e) { |
| 8418 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8419 | } finally { |
| 8420 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8421 | } |
| 8422 | } |
| 8423 | |
| 8424 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8425 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8426 | * @param subId the subscription ID that this action applies to. |
| 8427 | * {@hide} |
| 8428 | */ |
| 8429 | @Override |
| 8430 | public void carrierActionResetAll(int subId) { |
| 8431 | enforceModifyPermission(); |
| 8432 | final Phone phone = getPhone(subId); |
| 8433 | if (phone == null) { |
| 8434 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8435 | return; |
| 8436 | } |
| 8437 | try { |
| 8438 | phone.carrierActionResetAll(); |
| 8439 | } catch (Exception e) { |
| 8440 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8441 | } |
| 8442 | } |
| 8443 | |
| 8444 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8445 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8446 | * bug report is being generated. |
| 8447 | */ |
| 8448 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8449 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8450 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8451 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8452 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8453 | + Binder.getCallingPid() |
| 8454 | + ", uid=" + Binder.getCallingUid() |
| 8455 | + "without permission " |
| 8456 | + android.Manifest.permission.DUMP); |
| 8457 | return; |
| 8458 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8459 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8460 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8461 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8462 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8463 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8464 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8465 | @NonNull String[] args) { |
| 8466 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8467 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8468 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8469 | } |
| 8470 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8471 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8472 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8473 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8474 | * @param reason the reason the data enable change is taking place |
| 8475 | * @param enabled True if enabling the data, otherwise disabling. |
| 8476 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8477 | */ |
| 8478 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8479 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8480 | boolean enabled) { |
| 8481 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8482 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8483 | try { |
| 8484 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8485 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8486 | } catch (SecurityException se) { |
| 8487 | enforceModifyPermission(); |
| 8488 | } |
| 8489 | } else { |
| 8490 | enforceModifyPermission(); |
| 8491 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8492 | |
| 8493 | final long identity = Binder.clearCallingIdentity(); |
| 8494 | try { |
| 8495 | Phone phone = getPhone(subId); |
| 8496 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8497 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8498 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8499 | } else { |
| 8500 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 8501 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8502 | } |
| 8503 | } finally { |
| 8504 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8505 | } |
| 8506 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8507 | |
| 8508 | /** |
| 8509 | * Get Client request stats |
| 8510 | * @return List of Client Request Stats |
| 8511 | * @hide |
| 8512 | */ |
| 8513 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8514 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8515 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8516 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8517 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8518 | return null; |
| 8519 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8520 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8521 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8522 | final long identity = Binder.clearCallingIdentity(); |
| 8523 | try { |
| 8524 | if (phone != null) { |
| 8525 | return phone.getClientRequestStats(); |
| 8526 | } |
| 8527 | |
| 8528 | return null; |
| 8529 | } finally { |
| 8530 | Binder.restoreCallingIdentity(identity); |
| 8531 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8532 | } |
| 8533 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8534 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8535 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8536 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8537 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8538 | |
| 8539 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8540 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8541 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8542 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8543 | * @param state State of SIM (power down, power up, pass through) |
| 8544 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8545 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8546 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8547 | * |
| 8548 | **/ |
| 8549 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8550 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8551 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8552 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8553 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8554 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8555 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8556 | final long identity = Binder.clearCallingIdentity(); |
| 8557 | try { |
| 8558 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8559 | phone.setSimPowerState(state, null, workSource); |
| 8560 | } |
| 8561 | } finally { |
| 8562 | Binder.restoreCallingIdentity(identity); |
| 8563 | } |
| 8564 | } |
| 8565 | |
| 8566 | /** |
| 8567 | * Set SIM card power state. |
| 8568 | * |
| 8569 | * @param slotIndex SIM slot id. |
| 8570 | * @param state State of SIM (power down, power up, pass through) |
| 8571 | * @param callback callback to trigger after success or failure |
| 8572 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8573 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8574 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8575 | * |
| 8576 | **/ |
| 8577 | @Override |
| 8578 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8579 | IIntegerConsumer callback) { |
| 8580 | enforceModifyPermission(); |
| 8581 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8582 | |
| 8583 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8584 | |
| 8585 | final long identity = Binder.clearCallingIdentity(); |
| 8586 | try { |
| 8587 | if (phone != null) { |
| 8588 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8589 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8590 | } |
| 8591 | } finally { |
| 8592 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8593 | } |
| 8594 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8595 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8596 | private boolean isUssdApiAllowed(int subId) { |
| 8597 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8598 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8599 | if (configManager == null) { |
| 8600 | return false; |
| 8601 | } |
| 8602 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8603 | if (pb == null) { |
| 8604 | return false; |
| 8605 | } |
| 8606 | return pb.getBoolean( |
| 8607 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8608 | } |
| 8609 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8610 | /** |
| 8611 | * Check if phone is in emergency callback mode |
| 8612 | * @return true if phone is in emergency callback mode |
| 8613 | * @param subId sub id |
| 8614 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8615 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8616 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8617 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8618 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8619 | |
| 8620 | final long identity = Binder.clearCallingIdentity(); |
| 8621 | try { |
| 8622 | if (phone != null) { |
| 8623 | return phone.isInEcm(); |
| 8624 | } else { |
| 8625 | return false; |
| 8626 | } |
| 8627 | } finally { |
| 8628 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8629 | } |
| 8630 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8631 | |
| 8632 | /** |
| 8633 | * Get the current signal strength information for the given subscription. |
| 8634 | * Because this information is not updated when the device is in a low power state |
| 8635 | * it should not be relied-upon to be current. |
| 8636 | * @param subId Subscription index |
| 8637 | * @return the most recent cached signal strength info from the modem |
| 8638 | */ |
| 8639 | @Override |
| 8640 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8641 | final long identity = Binder.clearCallingIdentity(); |
| 8642 | try { |
| 8643 | Phone p = getPhone(subId); |
| 8644 | if (p == null) { |
| 8645 | return null; |
| 8646 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8647 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8648 | return p.getSignalStrength(); |
| 8649 | } finally { |
| 8650 | Binder.restoreCallingIdentity(identity); |
| 8651 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8652 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8653 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8654 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8655 | * Get the current modem radio state for the given slot. |
| 8656 | * @param slotIndex slot index. |
| 8657 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8658 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8659 | * @return the current radio power state from the modem |
| 8660 | */ |
| 8661 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8662 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8663 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8664 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8665 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8666 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8667 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8668 | } |
| 8669 | |
| 8670 | final long identity = Binder.clearCallingIdentity(); |
| 8671 | try { |
| 8672 | return phone.getRadioPowerState(); |
| 8673 | } finally { |
| 8674 | Binder.restoreCallingIdentity(identity); |
| 8675 | } |
| 8676 | } |
| 8677 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8678 | } |
| 8679 | |
| 8680 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8681 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8682 | * |
| 8683 | * <p>Requires one of the following permissions: |
| 8684 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8685 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8686 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8687 | * privileges. |
| 8688 | * |
| 8689 | * @param subId subscription id |
| 8690 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8691 | * {@code false}. |
| 8692 | */ |
| 8693 | @Override |
| 8694 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8695 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8696 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8697 | try { |
| 8698 | mApp.enforceCallingOrSelfPermission( |
| 8699 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8700 | functionName); |
| 8701 | } catch (Exception e) { |
| 8702 | mApp.enforceCallingOrSelfPermission( |
| 8703 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 8704 | } |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8705 | } catch (Exception e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8706 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8707 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8708 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8709 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8710 | boolean isEnabled = false; |
| 8711 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8712 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8713 | Phone phone = getPhone(subId); |
| 8714 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8715 | } finally { |
| 8716 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8717 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8718 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8719 | } |
| 8720 | |
| 8721 | |
| 8722 | /** |
| 8723 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8724 | * |
| 8725 | * <p> Requires permission: |
| 8726 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8727 | * privileges. |
| 8728 | * |
| 8729 | * @param subId subscription id |
| 8730 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8731 | */ |
| 8732 | @Override |
| 8733 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8734 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8735 | mApp, subId, "setDataRoamingEnabled"); |
| 8736 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8737 | final long identity = Binder.clearCallingIdentity(); |
| 8738 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8739 | Phone phone = getPhone(subId); |
| 8740 | if (phone != null) { |
| 8741 | phone.setDataRoamingEnabled(isEnabled); |
| 8742 | } |
| 8743 | } finally { |
| 8744 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8745 | } |
| 8746 | } |
| 8747 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8748 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8749 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8750 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8751 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8752 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8753 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8754 | boolean isAllowed = true; |
| 8755 | final long identity = Binder.clearCallingIdentity(); |
| 8756 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8757 | Phone phone = getPhone(subId); |
| 8758 | if (phone != null) { |
| 8759 | isAllowed = phone.isCspPlmnEnabled(); |
| 8760 | } |
| 8761 | } finally { |
| 8762 | Binder.restoreCallingIdentity(identity); |
| 8763 | } |
| 8764 | return isAllowed; |
| 8765 | } |
| 8766 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8767 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 8768 | UiccProfile profile = port.getUiccProfile(); |
| 8769 | if (profile == null || |
| 8770 | profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8771 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8772 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8773 | } |
| 8774 | return true; |
| 8775 | } |
| 8776 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8777 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8778 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8779 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8780 | mApp.getSystemService(AppOpsManager.class) |
| 8781 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8782 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8783 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8784 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8785 | try { |
| 8786 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8787 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8788 | } catch (SecurityException e) { |
| 8789 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8790 | // has carrier privileges on an active UICC |
| 8791 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8792 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8793 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8794 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8795 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8796 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8797 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8798 | Binder.getCallingUid())) { |
| 8799 | isIccIdAccessRestricted = true; |
| 8800 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8801 | final long identity = Binder.clearCallingIdentity(); |
| 8802 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8803 | UiccController uiccController = UiccController.getInstance(); |
| 8804 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8805 | if (hasReadPermission) { |
| 8806 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8807 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8808 | |
| 8809 | // Remove private info if the caller doesn't have access |
| 8810 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8811 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8812 | //setting the value after compatibility check |
| 8813 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8814 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8815 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8816 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8817 | if (card == null) { |
| 8818 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8819 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8820 | continue; |
| 8821 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8822 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 8823 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8824 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8825 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8826 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8827 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 8828 | for (UiccPortInfo portInfo : portInfos) { |
| 8829 | UiccPort port = uiccController.getUiccPortForSlot( |
| 8830 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 8831 | if (port == null) { |
| 8832 | // assume no access if port is null |
| 8833 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8834 | continue; |
| 8835 | } |
| 8836 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 8837 | uiccPortInfos.add(portInfo); |
| 8838 | } else { |
| 8839 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8840 | } |
| 8841 | } |
| 8842 | filteredInfos.add(new UiccCardInfo( |
| 8843 | cardInfo.isEuicc(), |
| 8844 | cardInfo.getCardId(), |
| 8845 | null, |
| 8846 | cardInfo.getPhysicalSlotIndex(), |
| 8847 | cardInfo.isRemovable(), |
| 8848 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8849 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8850 | } |
| 8851 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8852 | } finally { |
| 8853 | Binder.restoreCallingIdentity(identity); |
| 8854 | } |
| 8855 | } |
| 8856 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8857 | /** |
| 8858 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 8859 | * generally private and require carrier privileges to view. |
| 8860 | * |
| 8861 | * @hide |
| 8862 | */ |
| 8863 | @NonNull |
| 8864 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 8865 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 8866 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 8867 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 8868 | } |
| 8869 | return new UiccCardInfo( |
| 8870 | cardInfo.isEuicc(), |
| 8871 | cardInfo.getCardId(), |
| 8872 | null, |
| 8873 | cardInfo.getPhysicalSlotIndex(), |
| 8874 | cardInfo.isRemovable(), |
| 8875 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8876 | portinfo |
| 8877 | ); |
| 8878 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8879 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8880 | /** |
| 8881 | * @hide |
| 8882 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 8883 | * These values are generally private and require carrier privileges to view. |
| 8884 | */ |
| 8885 | @NonNull |
| 8886 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 8887 | return new UiccPortInfo( |
| 8888 | UiccPortInfo.ICCID_REDACTED, |
| 8889 | portInfo.getPortIndex(), |
| 8890 | portInfo.getLogicalSlotIndex(), |
| 8891 | portInfo.isActive() |
| 8892 | ); |
| 8893 | } |
| 8894 | @Override |
| 8895 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8896 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8897 | mApp.getSystemService(AppOpsManager.class) |
| 8898 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8899 | |
| 8900 | boolean hasReadPermission = false; |
| 8901 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8902 | |
| 8903 | try { |
| 8904 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
| 8905 | hasReadPermission = true; |
| 8906 | } catch (SecurityException e) { |
| 8907 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8908 | // has carrier privileges on an active UICC |
| 8909 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8910 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8911 | hasReadPermission = true; |
| 8912 | } |
| 8913 | } |
| 8914 | |
| 8915 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8916 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8917 | Binder.getCallingUid())) { |
| 8918 | isLogicalSlotAccessRestricted = true; |
| 8919 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8920 | final long identity = Binder.clearCallingIdentity(); |
| 8921 | try { |
| 8922 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8923 | if (slots == null) { |
| 8924 | Rlog.i(LOG_TAG, "slots is null."); |
| 8925 | return null; |
| 8926 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8927 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8928 | for (int i = 0; i < slots.length; i++) { |
| 8929 | UiccSlot slot = slots[i]; |
| 8930 | if (slot == null) { |
| 8931 | continue; |
| 8932 | } |
| 8933 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8934 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8935 | UiccCard card = slot.getUiccCard(); |
| 8936 | if (card != null) { |
| 8937 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8938 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8939 | cardId = slot.getEid(); |
| 8940 | if (TextUtils.isEmpty(cardId)) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8941 | // If cardId is null, use iccId of default port as cardId. Check if has |
| 8942 | // read permission otherwise set to null.(card is null which means no |
| 8943 | // carrier permission) |
| 8944 | cardId = hasReadPermission ? slot.getIccId( |
| 8945 | TelephonyManager.DEFAULT_PORT_INDEX) : null; |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8946 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8947 | } |
| 8948 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8949 | if (cardId != null) { |
| 8950 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8951 | // if cardId is an EID, it's all digits so this is fine |
| 8952 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8953 | } |
| 8954 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8955 | int cardState = 0; |
| 8956 | switch (slot.getCardState()) { |
| 8957 | case CARDSTATE_ABSENT: |
| 8958 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8959 | break; |
| 8960 | case CARDSTATE_PRESENT: |
| 8961 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8962 | break; |
| 8963 | case CARDSTATE_ERROR: |
| 8964 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8965 | break; |
| 8966 | case CARDSTATE_RESTRICTED: |
| 8967 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8968 | break; |
| 8969 | default: |
| 8970 | break; |
| 8971 | |
| 8972 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8973 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 8974 | int[] portIndexes = slot.getPortList(); |
| 8975 | for (int portIdx : portIndexes) { |
| 8976 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
| 8977 | callingPackage, hasReadPermission)); |
| 8978 | if (slot.isPortActive(portIdx)) { |
| 8979 | UiccPort port = slot.getUiccCard().getUiccPort(portIdx); |
| 8980 | portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(), |
| 8981 | port.getPhoneId(), true)); |
| 8982 | } else { |
| 8983 | portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false)); |
| 8984 | } |
| 8985 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8986 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8987 | slot.isEuicc(), |
| 8988 | cardId, |
| 8989 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8990 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8991 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8992 | //setting the value after compatibility check |
| 8993 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8994 | } |
| 8995 | return infos; |
| 8996 | } finally { |
| 8997 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8998 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8999 | } |
| 9000 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9001 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9002 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9003 | boolean hasReadPermission) { |
| 9004 | String iccId = slot.getIccId(portIndex); |
| 9005 | if (hasReadPermission) { // if has read permission |
| 9006 | return iccId; |
| 9007 | } else { |
| 9008 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9009 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9010 | // if no read permission, checking carrier privilege access |
| 9011 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9012 | return iccId; |
| 9013 | } |
| 9014 | } |
| 9015 | } |
| 9016 | // No read permission or carrier privilege access. |
| 9017 | return UiccPortInfo.ICCID_REDACTED; |
| 9018 | } |
| 9019 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9020 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9021 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9022 | public boolean switchSlots(int[] physicalSlots) { |
| 9023 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9024 | |
| 9025 | final long identity = Binder.clearCallingIdentity(); |
| 9026 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9027 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9028 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9029 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9030 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9031 | physicalSlots[i], i)); |
| 9032 | } |
| 9033 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9034 | } finally { |
| 9035 | Binder.restoreCallingIdentity(identity); |
| 9036 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9037 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9038 | |
| 9039 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9040 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9041 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9042 | enforceModifyPermission(); |
| 9043 | |
| 9044 | final long identity = Binder.clearCallingIdentity(); |
| 9045 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9046 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9047 | } finally { |
| 9048 | Binder.restoreCallingIdentity(identity); |
| 9049 | } |
| 9050 | } |
| 9051 | |
| 9052 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9053 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9054 | final long identity = Binder.clearCallingIdentity(); |
| 9055 | try { |
| 9056 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9057 | } finally { |
| 9058 | Binder.restoreCallingIdentity(identity); |
| 9059 | } |
| 9060 | } |
| 9061 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9062 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9063 | * A test API to reload the UICC profile. |
| 9064 | * |
| 9065 | * <p>Requires that the calling app has permission |
| 9066 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9067 | * @hide |
| 9068 | */ |
| 9069 | @Override |
| 9070 | public void refreshUiccProfile(int subId) { |
| 9071 | enforceModifyPermission(); |
| 9072 | |
| 9073 | final long identity = Binder.clearCallingIdentity(); |
| 9074 | try { |
| 9075 | Phone phone = getPhone(subId); |
| 9076 | if (phone == null) { |
| 9077 | return; |
| 9078 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9079 | UiccPort uiccPort = phone.getUiccPort(); |
| 9080 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9081 | return; |
| 9082 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9083 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9084 | if (uiccProfile == null) { |
| 9085 | return; |
| 9086 | } |
| 9087 | uiccProfile.refresh(); |
| 9088 | } finally { |
| 9089 | Binder.restoreCallingIdentity(identity); |
| 9090 | } |
| 9091 | } |
| 9092 | |
| 9093 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9094 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9095 | */ |
| 9096 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9097 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9098 | } |
| 9099 | |
| 9100 | /** |
| 9101 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9102 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9103 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9104 | */ |
| 9105 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9106 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9107 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9108 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9109 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9110 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9111 | return isDataRoamingEnabled; |
| 9112 | } |
| 9113 | |
| 9114 | /** |
| 9115 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9116 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9117 | */ |
| 9118 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9119 | List<Integer> list = TelephonyProperties.default_network(); |
| 9120 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 9121 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9122 | return list.get(phoneId); |
| 9123 | } |
| 9124 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9125 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9126 | |
| 9127 | @Override |
| 9128 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9129 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9130 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9131 | |
| 9132 | final long identity = Binder.clearCallingIdentity(); |
| 9133 | try { |
| 9134 | final Phone phone = getPhone(subId); |
| 9135 | if (phone == null) { |
| 9136 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9137 | return; |
| 9138 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9139 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9140 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9141 | if (carrierPrivilegeRules == null) { |
| 9142 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9143 | } else { |
| 9144 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9145 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9146 | } finally { |
| 9147 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9148 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9149 | } |
| 9150 | |
| 9151 | @Override |
| 9152 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9153 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9154 | |
| 9155 | final long identity = Binder.clearCallingIdentity(); |
| 9156 | try { |
| 9157 | final Phone phone = getPhone(subId); |
| 9158 | if (phone == null) { |
| 9159 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9160 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9161 | } |
| 9162 | return phone.getCarrierIdListVersion(); |
| 9163 | } finally { |
| 9164 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9165 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9166 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9167 | |
| 9168 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9169 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9170 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9171 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9172 | mApp, subId, callingPackage, callingFeatureId, |
| 9173 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9174 | return -1; |
| 9175 | } |
| 9176 | |
| 9177 | final long identity = Binder.clearCallingIdentity(); |
| 9178 | try { |
| 9179 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9180 | } finally { |
| 9181 | Binder.restoreCallingIdentity(identity); |
| 9182 | } |
| 9183 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9184 | |
| 9185 | @Override |
| 9186 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9187 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9188 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9189 | mApp, subId, "getCdmaRoamingMode"); |
| 9190 | |
| 9191 | final long identity = Binder.clearCallingIdentity(); |
| 9192 | try { |
| 9193 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9194 | } finally { |
| 9195 | Binder.restoreCallingIdentity(identity); |
| 9196 | } |
| 9197 | } |
| 9198 | |
| 9199 | @Override |
| 9200 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9201 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9202 | mApp, subId, "setCdmaRoamingMode"); |
| 9203 | |
| 9204 | final long identity = Binder.clearCallingIdentity(); |
| 9205 | try { |
| 9206 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9207 | } finally { |
| 9208 | Binder.restoreCallingIdentity(identity); |
| 9209 | } |
| 9210 | } |
| 9211 | |
| 9212 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9213 | public int getCdmaSubscriptionMode(int subId) { |
| 9214 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9215 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9216 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9217 | |
| 9218 | final long identity = Binder.clearCallingIdentity(); |
| 9219 | try { |
| 9220 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9221 | } finally { |
| 9222 | Binder.restoreCallingIdentity(identity); |
| 9223 | } |
| 9224 | } |
| 9225 | |
| 9226 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9227 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9228 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9229 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9230 | |
| 9231 | final long identity = Binder.clearCallingIdentity(); |
| 9232 | try { |
| 9233 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9234 | } finally { |
| 9235 | Binder.restoreCallingIdentity(identity); |
| 9236 | } |
| 9237 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9238 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9239 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9240 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9241 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9242 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9243 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9244 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9245 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9246 | } |
| 9247 | final long identity = Binder.clearCallingIdentity(); |
| 9248 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9249 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9250 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9251 | if (phone.getEmergencyNumberTracker() != null |
| 9252 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9253 | emergencyNumberListInternal.put( |
| 9254 | phone.getSubId(), |
| 9255 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9256 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9257 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9258 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9259 | } finally { |
| 9260 | Binder.restoreCallingIdentity(identity); |
| 9261 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9262 | } |
| 9263 | |
| 9264 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9265 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9266 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9267 | if (!exactMatch) { |
| 9268 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9269 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9270 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9271 | } |
| 9272 | final long identity = Binder.clearCallingIdentity(); |
| 9273 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9274 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9275 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9276 | && phone.getEmergencyNumberTracker() |
| 9277 | .isEmergencyNumber(number, exactMatch)) { |
| 9278 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9279 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9280 | } |
| 9281 | return false; |
| 9282 | } finally { |
| 9283 | Binder.restoreCallingIdentity(identity); |
| 9284 | } |
| 9285 | } |
| 9286 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9287 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9288 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9289 | */ |
| 9290 | @Override |
| 9291 | public void startEmergencyCallbackMode() { |
| 9292 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9293 | "startEmergencyCallbackMode"); |
| 9294 | enforceModifyPermission(); |
| 9295 | final long identity = Binder.clearCallingIdentity(); |
| 9296 | try { |
| 9297 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9298 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9299 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9300 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9301 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9302 | gsmCdmaPhone.obtainMessage( |
| 9303 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9304 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9305 | } |
| 9306 | } |
| 9307 | } finally { |
| 9308 | Binder.restoreCallingIdentity(identity); |
| 9309 | } |
| 9310 | } |
| 9311 | |
| 9312 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9313 | * Update emergency number list for test mode. |
| 9314 | */ |
| 9315 | @Override |
| 9316 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9317 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9318 | "updateEmergencyNumberListTestMode"); |
| 9319 | |
| 9320 | final long identity = Binder.clearCallingIdentity(); |
| 9321 | try { |
| 9322 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9323 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9324 | if (tracker != null) { |
| 9325 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9326 | } |
| 9327 | } |
| 9328 | } finally { |
| 9329 | Binder.restoreCallingIdentity(identity); |
| 9330 | } |
| 9331 | } |
| 9332 | |
| 9333 | /** |
| 9334 | * Get the full emergency number list for test mode. |
| 9335 | */ |
| 9336 | @Override |
| 9337 | public List<String> getEmergencyNumberListTestMode() { |
| 9338 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9339 | "getEmergencyNumberListTestMode"); |
| 9340 | |
| 9341 | final long identity = Binder.clearCallingIdentity(); |
| 9342 | try { |
| 9343 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9344 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9345 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9346 | if (tracker != null) { |
| 9347 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9348 | emergencyNumbers.add(num.getNumber()); |
| 9349 | } |
| 9350 | } |
| 9351 | } |
| 9352 | return new ArrayList<>(emergencyNumbers); |
| 9353 | } finally { |
| 9354 | Binder.restoreCallingIdentity(identity); |
| 9355 | } |
| 9356 | } |
| 9357 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9358 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9359 | public int getEmergencyNumberDbVersion(int subId) { |
| 9360 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9361 | |
| 9362 | final long identity = Binder.clearCallingIdentity(); |
| 9363 | try { |
| 9364 | final Phone phone = getPhone(subId); |
| 9365 | if (phone == null) { |
| 9366 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9367 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9368 | } |
| 9369 | return phone.getEmergencyNumberDbVersion(); |
| 9370 | } finally { |
| 9371 | Binder.restoreCallingIdentity(identity); |
| 9372 | } |
| 9373 | } |
| 9374 | |
| 9375 | @Override |
| 9376 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9377 | enforceModifyPermission(); |
| 9378 | |
| 9379 | final long identity = Binder.clearCallingIdentity(); |
| 9380 | try { |
| 9381 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9382 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9383 | if (tracker != null) { |
| 9384 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9385 | } |
| 9386 | } |
| 9387 | } finally { |
| 9388 | Binder.restoreCallingIdentity(identity); |
| 9389 | } |
| 9390 | } |
| 9391 | |
| 9392 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9393 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9394 | enforceActiveEmergencySessionPermission(); |
| 9395 | |
| 9396 | final long identity = Binder.clearCallingIdentity(); |
| 9397 | try { |
| 9398 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9399 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9400 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9401 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9402 | } |
| 9403 | } |
| 9404 | } finally { |
| 9405 | Binder.restoreCallingIdentity(identity); |
| 9406 | } |
| 9407 | } |
| 9408 | |
| 9409 | @Override |
| 9410 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9411 | enforceActiveEmergencySessionPermission(); |
| 9412 | |
| 9413 | final long identity = Binder.clearCallingIdentity(); |
| 9414 | try { |
| 9415 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9416 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9417 | if (tracker != null) { |
| 9418 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9419 | } |
| 9420 | } |
| 9421 | } finally { |
| 9422 | Binder.restoreCallingIdentity(identity); |
| 9423 | } |
| 9424 | } |
| 9425 | |
| 9426 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9427 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9428 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9429 | Phone phone = getPhone(subId); |
| 9430 | if (phone == null) { |
| 9431 | return null; |
| 9432 | } |
| 9433 | final long identity = Binder.clearCallingIdentity(); |
| 9434 | try { |
| 9435 | UiccProfile profile = UiccController.getInstance() |
| 9436 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9437 | if (profile != null) { |
| 9438 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9439 | } |
| 9440 | } finally { |
| 9441 | Binder.restoreCallingIdentity(identity); |
| 9442 | } |
| 9443 | return null; |
| 9444 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9445 | |
| 9446 | /** |
| 9447 | * Enable or disable a modem stack. |
| 9448 | */ |
| 9449 | @Override |
| 9450 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9451 | enforceModifyPermission(); |
| 9452 | |
| 9453 | final long identity = Binder.clearCallingIdentity(); |
| 9454 | try { |
| 9455 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9456 | if (phone == null) { |
| 9457 | return false; |
| 9458 | } else { |
| 9459 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9460 | } |
| 9461 | } finally { |
| 9462 | Binder.restoreCallingIdentity(identity); |
| 9463 | } |
| 9464 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9465 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9466 | /** |
| 9467 | * Whether a modem stack is enabled or not. |
| 9468 | */ |
| 9469 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9470 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9471 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9472 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9473 | if (phone == null) return false; |
| 9474 | |
| 9475 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9476 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9477 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9478 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9479 | } |
| 9480 | |
| 9481 | final long identity = Binder.clearCallingIdentity(); |
| 9482 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9483 | try { |
| 9484 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9485 | } catch (NoSuchElementException ex) { |
| 9486 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9487 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9488 | } finally { |
| 9489 | Binder.restoreCallingIdentity(identity); |
| 9490 | } |
| 9491 | } |
| 9492 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9493 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9494 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9495 | enforceModifyPermission(); |
| 9496 | |
| 9497 | final long identity = Binder.clearCallingIdentity(); |
| 9498 | try { |
| 9499 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9500 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9501 | .commit(); |
| 9502 | } finally { |
| 9503 | Binder.restoreCallingIdentity(identity); |
| 9504 | } |
| 9505 | } |
| 9506 | |
| 9507 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9508 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9509 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9510 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9511 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9512 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9513 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9514 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9515 | |
| 9516 | final long identity = Binder.clearCallingIdentity(); |
| 9517 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9518 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9519 | } finally { |
| 9520 | Binder.restoreCallingIdentity(identity); |
| 9521 | } |
| 9522 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9523 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9524 | @TelephonyManager.IsMultiSimSupportedResult |
| 9525 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9526 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9527 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9528 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9529 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9530 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9531 | } |
| 9532 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9533 | // supported by the modem, indicate that it is restricted. |
| 9534 | PhoneCapability staticCapability = |
| 9535 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9536 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9537 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9538 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9539 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9540 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9541 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9542 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9543 | } |
| 9544 | // Check if support of multiple SIMs is restricted by carrier |
| 9545 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9546 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9547 | } |
| 9548 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9549 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9550 | } |
| 9551 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9552 | /** |
| 9553 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9554 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9555 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9556 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9557 | * @param numOfSims number of active sims we want to switch to |
| 9558 | */ |
| 9559 | @Override |
| 9560 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9561 | if (numOfSims == 1) { |
| 9562 | enforceModifyPermission(); |
| 9563 | } else { |
| 9564 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9565 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9566 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9567 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9568 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9569 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9570 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9571 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9572 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9573 | return; |
| 9574 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9575 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9576 | } finally { |
| 9577 | Binder.restoreCallingIdentity(identity); |
| 9578 | } |
| 9579 | } |
| 9580 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9581 | @Override |
| 9582 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9583 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9584 | Phone phone = getPhone(subId); |
| 9585 | if (phone == null) { |
| 9586 | return false; |
| 9587 | } |
| 9588 | final long identity = Binder.clearCallingIdentity(); |
| 9589 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9590 | UiccPort uiccPort = phone.getUiccPort(); |
| 9591 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9592 | return false; |
| 9593 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9594 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9595 | if (uiccProfile == null) { |
| 9596 | return false; |
| 9597 | } |
| 9598 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9599 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9600 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9601 | } |
| 9602 | return false; |
| 9603 | } finally { |
| 9604 | Binder.restoreCallingIdentity(identity); |
| 9605 | } |
| 9606 | } |
| 9607 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9608 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9609 | * Get whether making changes to modem configurations will trigger reboot. |
| 9610 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9611 | */ |
| 9612 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9613 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9614 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9615 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9616 | mApp, subId, callingPackage, callingFeatureId, |
| 9617 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9618 | return false; |
| 9619 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9620 | final long identity = Binder.clearCallingIdentity(); |
| 9621 | try { |
| 9622 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9623 | } finally { |
| 9624 | Binder.restoreCallingIdentity(identity); |
| 9625 | } |
| 9626 | } |
| 9627 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9628 | private void updateModemStateMetrics() { |
| 9629 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9630 | // TODO: check the state for each modem if the api is ready. |
| 9631 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9632 | } |
| 9633 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9634 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9635 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9636 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9637 | // Verify that the callingPackage belongs to the calling UID |
| 9638 | mApp.getSystemService(AppOpsManager.class) |
| 9639 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9640 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9641 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9642 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9643 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 9644 | if (slotInfos != null) { |
| 9645 | for (int i = 0; i < slotInfos.length; i++) { |
| 9646 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 9647 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 9648 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 9649 | portInfo.getLogicalSlotIndex())); |
| 9650 | } |
| 9651 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9652 | } |
| 9653 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9654 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9655 | } finally { |
| 9656 | Binder.restoreCallingIdentity(identity); |
| 9657 | } |
| 9658 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9659 | |
| 9660 | /** |
| 9661 | * Get the IRadio HAL Version |
| 9662 | */ |
| 9663 | @Override |
| 9664 | public int getRadioHalVersion() { |
| 9665 | Phone phone = getDefaultPhone(); |
| 9666 | if (phone == null) return -1; |
| 9667 | HalVersion hv = phone.getHalVersion(); |
| 9668 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9669 | return hv.major * 100 + hv.minor; |
| 9670 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9671 | |
| 9672 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9673 | * Get the current calling package name. |
| 9674 | * @return the current calling package name |
| 9675 | */ |
| 9676 | @Override |
| 9677 | public String getCurrentPackageName() { |
| 9678 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9679 | } |
| 9680 | |
| 9681 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9682 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9683 | * corresponding network requests on a subId. |
| 9684 | * |
| 9685 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9686 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9687 | * 2) APN is un-metered for this subscription, or |
| 9688 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9689 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9690 | * |
| 9691 | * @return whether data is allowed for a apn type. |
| 9692 | * |
| 9693 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9694 | */ |
| 9695 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9696 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9697 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9698 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9699 | |
| 9700 | // Now that all security checks passes, perform the operation as ourselves. |
| 9701 | final long identity = Binder.clearCallingIdentity(); |
| 9702 | try { |
| 9703 | Phone phone = getPhone(subId); |
| 9704 | if (phone == null) return false; |
| 9705 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9706 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9707 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9708 | } finally { |
| 9709 | Binder.restoreCallingIdentity(identity); |
| 9710 | } |
| 9711 | } |
| 9712 | |
| 9713 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9714 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9715 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9716 | |
| 9717 | // Now that all security checks passes, perform the operation as ourselves. |
| 9718 | final long identity = Binder.clearCallingIdentity(); |
| 9719 | try { |
| 9720 | Phone phone = getPhone(subId); |
| 9721 | if (phone == null) return true; // By default return true. |
| 9722 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9723 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9724 | } finally { |
| 9725 | Binder.restoreCallingIdentity(identity); |
| 9726 | } |
| 9727 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9728 | |
| 9729 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9730 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9731 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9732 | enforceModifyPermission(); |
| 9733 | long token = Binder.clearCallingIdentity(); |
| 9734 | try { |
| 9735 | Phone phone = getPhone(subscriptionId); |
| 9736 | if (phone == null) { |
| 9737 | try { |
| 9738 | if (resultCallback != null) { |
| 9739 | resultCallback.accept(false); |
| 9740 | } |
| 9741 | } catch (RemoteException e) { |
| 9742 | // ignore |
| 9743 | } |
| 9744 | return; |
| 9745 | } |
| 9746 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9747 | Pair.create(specifiers, (x) -> { |
| 9748 | try { |
| 9749 | if (resultCallback != null) { |
| 9750 | resultCallback.accept(x); |
| 9751 | } |
| 9752 | } catch (RemoteException e) { |
| 9753 | // ignore |
| 9754 | } |
| 9755 | }); |
| 9756 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9757 | } finally { |
| 9758 | Binder.restoreCallingIdentity(token); |
| 9759 | } |
| 9760 | } |
| 9761 | |
| 9762 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9763 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9764 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9765 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9766 | mApp, subId, "getSystemSelectionChannels"); |
| 9767 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9768 | final long identity = Binder.clearCallingIdentity(); |
| 9769 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 9770 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 9771 | if (result instanceof IllegalStateException) { |
| 9772 | throw (IllegalStateException) result; |
| 9773 | } |
| 9774 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9775 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9776 | return specifiers; |
| 9777 | } finally { |
| 9778 | Binder.restoreCallingIdentity(identity); |
| 9779 | } |
| 9780 | } |
| 9781 | |
| 9782 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9783 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9784 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9785 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9786 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9787 | if (iccRecords == null) { |
| 9788 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9789 | return false; |
| 9790 | } |
| 9791 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9792 | } |
| 9793 | |
| 9794 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9795 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9796 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9797 | if (callingPackage == null) { |
| 9798 | callingPackage = getCurrentPackageName(); |
| 9799 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9800 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9801 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9802 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9803 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9804 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9805 | } |
| 9806 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9807 | Intent intent = new Intent(); |
| 9808 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9809 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9810 | // Bring up choose default SMS subscription dialog right now |
| 9811 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9812 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9813 | mApp.startActivity(intent); |
| 9814 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9815 | |
| 9816 | @Override |
| 9817 | public String getMmsUAProfUrl(int subId) { |
| 9818 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9819 | final long identity = Binder.clearCallingIdentity(); |
| 9820 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9821 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9822 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9823 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9824 | return carrierUAProfUrl; |
| 9825 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9826 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9827 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9828 | } finally { |
| 9829 | Binder.restoreCallingIdentity(identity); |
| 9830 | } |
| 9831 | } |
| 9832 | |
| 9833 | @Override |
| 9834 | public String getMmsUserAgent(int subId) { |
| 9835 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9836 | final long identity = Binder.clearCallingIdentity(); |
| 9837 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9838 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9839 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9840 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9841 | return carrierUserAgent; |
| 9842 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9843 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9844 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9845 | } finally { |
| 9846 | Binder.restoreCallingIdentity(identity); |
| 9847 | } |
| 9848 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9849 | |
| 9850 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9851 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9852 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9853 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9854 | final long identity = Binder.clearCallingIdentity(); |
| 9855 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9856 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9857 | if (phone == null) return false; |
| 9858 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9859 | switch (policy) { |
| 9860 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9861 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9862 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9863 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9864 | default: |
| 9865 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9866 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9867 | } finally { |
| 9868 | Binder.restoreCallingIdentity(identity); |
| 9869 | } |
| 9870 | } |
| 9871 | |
| 9872 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9873 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9874 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9875 | enforceModifyPermission(); |
| 9876 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9877 | final long identity = Binder.clearCallingIdentity(); |
| 9878 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9879 | Phone phone = getPhone(subscriptionId); |
| 9880 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9881 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9882 | switch (policy) { |
| 9883 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9884 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9885 | break; |
| 9886 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9887 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9888 | break; |
| 9889 | default: |
| 9890 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9891 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9892 | } finally { |
| 9893 | Binder.restoreCallingIdentity(identity); |
| 9894 | } |
| 9895 | } |
| 9896 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9897 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9898 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9899 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9900 | * otherwise. |
| 9901 | */ |
| 9902 | @Override |
| 9903 | public void setCepEnabled(boolean isCepEnabled) { |
| 9904 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9905 | |
| 9906 | final long identity = Binder.clearCallingIdentity(); |
| 9907 | try { |
| 9908 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9909 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9910 | Phone defaultPhone = phone.getImsPhone(); |
| 9911 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9912 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9913 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9914 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9915 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9916 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9917 | + imsPhone.getMsisdn()); |
| 9918 | } |
| 9919 | } |
| 9920 | } finally { |
| 9921 | Binder.restoreCallingIdentity(identity); |
| 9922 | } |
| 9923 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9924 | |
| 9925 | /** |
| 9926 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9927 | * |
| 9928 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9929 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9930 | * before being read. |
| 9931 | */ |
| 9932 | @Override |
| 9933 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9934 | isCompressed) { |
| 9935 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9936 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9937 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9938 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9939 | } |
| 9940 | if (!isImsAvailableOnDevice()) { |
| 9941 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9942 | "IMS not available on device."); |
| 9943 | } |
| 9944 | |
| 9945 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9946 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9947 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9948 | } finally { |
| 9949 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9950 | } |
| 9951 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9952 | |
| 9953 | @Override |
| 9954 | public boolean isIccLockEnabled(int subId) { |
| 9955 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9956 | |
| 9957 | // Now that all security checks passes, perform the operation as ourselves. |
| 9958 | final long identity = Binder.clearCallingIdentity(); |
| 9959 | try { |
| 9960 | Phone phone = getPhone(subId); |
| 9961 | if (phone != null && phone.getIccCard() != null) { |
| 9962 | return phone.getIccCard().getIccLockEnabled(); |
| 9963 | } else { |
| 9964 | return false; |
| 9965 | } |
| 9966 | } finally { |
| 9967 | Binder.restoreCallingIdentity(identity); |
| 9968 | } |
| 9969 | } |
| 9970 | |
| 9971 | /** |
| 9972 | * Set the ICC pin lock enabled or disabled. |
| 9973 | * |
| 9974 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9975 | * three cases: |
| 9976 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9977 | * successfully. |
| 9978 | * - Positive number and zero for remaining password attempts. |
| 9979 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9980 | * |
| 9981 | */ |
| 9982 | @Override |
| 9983 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9984 | enforceModifyPermission(); |
| 9985 | |
| 9986 | Phone phone = getPhone(subId); |
| 9987 | if (phone == null) { |
| 9988 | return 0; |
| 9989 | } |
| 9990 | // Now that all security checks passes, perform the operation as ourselves. |
| 9991 | final long identity = Binder.clearCallingIdentity(); |
| 9992 | try { |
| 9993 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9994 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9995 | return attemptsRemaining; |
| 9996 | |
| 9997 | } catch (Exception e) { |
| 9998 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9999 | } finally { |
| 10000 | Binder.restoreCallingIdentity(identity); |
| 10001 | } |
| 10002 | return 0; |
| 10003 | } |
| 10004 | |
| 10005 | /** |
| 10006 | * Change the ICC password used in ICC pin lock. |
| 10007 | * |
| 10008 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10009 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10010 | * - Positive number and zero for remaining password attempts. |
| 10011 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10012 | * |
| 10013 | */ |
| 10014 | @Override |
| 10015 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10016 | enforceModifyPermission(); |
| 10017 | |
| 10018 | Phone phone = getPhone(subId); |
| 10019 | if (phone == null) { |
| 10020 | return 0; |
| 10021 | } |
| 10022 | // Now that all security checks passes, perform the operation as ourselves. |
| 10023 | final long identity = Binder.clearCallingIdentity(); |
| 10024 | try { |
| 10025 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10026 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10027 | return attemptsRemaining; |
| 10028 | |
| 10029 | } catch (Exception e) { |
| 10030 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10031 | } finally { |
| 10032 | Binder.restoreCallingIdentity(identity); |
| 10033 | } |
| 10034 | return 0; |
| 10035 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10036 | |
| 10037 | /** |
| 10038 | * Request for receiving user activity notification |
| 10039 | */ |
| 10040 | @Override |
| 10041 | public void requestUserActivityNotification() { |
| 10042 | if (!mNotifyUserActivity.get() |
| 10043 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10044 | mNotifyUserActivity.set(true); |
| 10045 | } |
| 10046 | } |
| 10047 | |
| 10048 | /** |
| 10049 | * Called when userActivity is signalled in the power manager. |
| 10050 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10051 | */ |
| 10052 | @Override |
| 10053 | public void userActivity() { |
| 10054 | // *************************************** |
| 10055 | // * Inherited from PhoneWindowManager * |
| 10056 | // *************************************** |
| 10057 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10058 | // WITH ITS LOCKS HELD. |
| 10059 | // |
| 10060 | // This code must be VERY careful about the locks |
| 10061 | // it acquires. |
| 10062 | // In fact, the current code acquires way too many, |
| 10063 | // and probably has lurking deadlocks. |
| 10064 | |
| 10065 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10066 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10067 | } |
| 10068 | |
| 10069 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10070 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10071 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10072 | } |
| 10073 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10074 | |
| 10075 | @Override |
| 10076 | public boolean canConnectTo5GInDsdsMode() { |
| 10077 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10078 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10079 | |
| 10080 | @Override |
| 10081 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10082 | String callingFeatureId) { |
| 10083 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10084 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10085 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10086 | } |
| 10087 | |
| 10088 | Phone phone = getPhone(subId); |
| 10089 | if (phone == null) { |
| 10090 | throw new RuntimeException("phone is not available"); |
| 10091 | } |
| 10092 | // Now that all security checks passes, perform the operation as ourselves. |
| 10093 | final long identity = Binder.clearCallingIdentity(); |
| 10094 | try { |
| 10095 | return phone.getEquivalentHomePlmns(); |
| 10096 | } finally { |
| 10097 | Binder.restoreCallingIdentity(identity); |
| 10098 | } |
| 10099 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10100 | |
| 10101 | @Override |
| 10102 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10103 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10104 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10105 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10106 | if (radioInterfaceCapabilities == null) { |
| 10107 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10108 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10109 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10110 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10111 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10112 | @Override |
| 10113 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10114 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10115 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10116 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10117 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10118 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10119 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10120 | if (DBG) { |
| 10121 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10122 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10123 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10124 | } |
| 10125 | |
| 10126 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10127 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10128 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10129 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10130 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10131 | if (callback != null) { |
| 10132 | try { |
| 10133 | callback.onAuthenticationFailure( |
| 10134 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10135 | } catch (RemoteException exception) { |
| 10136 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10137 | } |
| 10138 | return; |
| 10139 | } |
| 10140 | } |
| 10141 | |
| 10142 | final long token = Binder.clearCallingIdentity(); |
| 10143 | try { |
| 10144 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10145 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 10146 | forceBootStrapping, callback)); |
| 10147 | } finally { |
| 10148 | Binder.restoreCallingIdentity(token); |
| 10149 | } |
| 10150 | } |
| 10151 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10152 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10153 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10154 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10155 | * requested radio power state will actually be set. See {@link |
| 10156 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10157 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10158 | * @param enable {@code true} if trying to turn radio on. |
| 10159 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10160 | * false}. |
| 10161 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10162 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10163 | boolean isPhoneAvailable = false; |
| 10164 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10165 | Phone phone = PhoneFactory.getPhone(i); |
| 10166 | if (phone != null) { |
| 10167 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 10168 | isPhoneAvailable = true; |
| 10169 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10170 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10171 | |
| 10172 | // return true if successfully informed the phone object about the thermal radio power |
| 10173 | // request. |
| 10174 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10175 | } |
| 10176 | |
| 10177 | private int handleDataThrottlingRequest(int subId, |
| 10178 | DataThrottlingRequest dataThrottlingRequest) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10179 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10180 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10181 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10182 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10183 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10184 | } |
| 10185 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10186 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10187 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10188 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10189 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10190 | } |
| 10191 | |
| 10192 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 10193 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10194 | if (isDataThrottlingSupported) { |
| 10195 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10196 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10197 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10198 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10199 | } else if (thermalMitigationResult |
| 10200 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10201 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10202 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10203 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10204 | } |
| 10205 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10206 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10207 | |
| 10208 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10209 | } |
| 10210 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10211 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10212 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10213 | for (String pckg : context.getResources() |
| 10214 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10215 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10216 | } |
| 10217 | } |
| 10218 | |
| 10219 | return sThermalMitigationAllowlistedPackages; |
| 10220 | } |
| 10221 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10222 | private boolean isAnyPhoneInEmergencyState() { |
| 10223 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10224 | if (tm.isInEmergencyCall()) { |
| 10225 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10226 | return true; |
| 10227 | } |
| 10228 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10229 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10230 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10231 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10232 | + phone.isInEcm()); |
| 10233 | return true; |
| 10234 | } |
| 10235 | } |
| 10236 | |
| 10237 | return false; |
| 10238 | } |
| 10239 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10240 | /** |
| 10241 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10242 | * @param packageName name of package to be allowlisted |
| 10243 | * @param context |
| 10244 | */ |
| 10245 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10246 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10247 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10248 | } |
| 10249 | |
| 10250 | /** |
| 10251 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10252 | * @param packageName name of package to remove from allowlist |
| 10253 | * @param context |
| 10254 | */ |
| 10255 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10256 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10257 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10258 | } |
| 10259 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10260 | /** |
| 10261 | * Thermal mitigation request to control functionalities at modem. |
| 10262 | * |
| 10263 | * @param subId the id of the subscription. |
| 10264 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10265 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10266 | * |
| 10267 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10268 | */ |
| 10269 | @Override |
| 10270 | @ThermalMitigationResult |
| 10271 | public int sendThermalMitigationRequest( |
| 10272 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10273 | ThermalMitigationRequest thermalMitigationRequest, |
| 10274 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10275 | enforceModifyPermission(); |
| 10276 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10277 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10278 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10279 | .contains(callingPackage)) { |
| 10280 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10281 | + "calling package: " + callingPackage); |
| 10282 | } |
| 10283 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10284 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10285 | final long identity = Binder.clearCallingIdentity(); |
| 10286 | |
| 10287 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10288 | try { |
| 10289 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10290 | switch (thermalMitigationAction) { |
| 10291 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10292 | thermalMitigationResult = |
| 10293 | handleDataThrottlingRequest(subId, |
| 10294 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 10295 | break; |
| 10296 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10297 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10298 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10299 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10300 | } |
| 10301 | |
| 10302 | // Ensure that radio is on. If not able to power on due to phone being |
| 10303 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10304 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10305 | thermalMitigationResult = |
| 10306 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10307 | break; |
| 10308 | } |
| 10309 | |
| 10310 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 10311 | false); |
| 10312 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10313 | break; |
| 10314 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10315 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10316 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10317 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10318 | } |
| 10319 | |
| 10320 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10321 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10322 | Phone phone = getPhone(subId); |
| 10323 | if (phone == null) { |
| 10324 | thermalMitigationResult = |
| 10325 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10326 | break; |
| 10327 | } |
| 10328 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10329 | TelephonyConnectionService service = |
| 10330 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10331 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10332 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10333 | thermalMitigationResult = |
| 10334 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10335 | break; |
| 10336 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10337 | thermalMitigationResult = |
| 10338 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10339 | break; |
| 10340 | } |
| 10341 | } else { |
| 10342 | thermalMitigationResult = |
| 10343 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10344 | break; |
| 10345 | } |
| 10346 | |
| 10347 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10348 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10349 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10350 | thermalMitigationResult = |
| 10351 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10352 | break; |
| 10353 | } |
| 10354 | thermalMitigationResult = |
| 10355 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10356 | break; |
| 10357 | default: |
| 10358 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10359 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10360 | } |
| 10361 | } catch (IllegalArgumentException e) { |
| 10362 | throw e; |
| 10363 | } catch (Exception e) { |
| 10364 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10365 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10366 | } finally { |
| 10367 | Binder.restoreCallingIdentity(identity); |
| 10368 | } |
| 10369 | |
| 10370 | if (DBG) { |
| 10371 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10372 | + thermalMitigationResult); |
| 10373 | } |
| 10374 | |
| 10375 | return thermalMitigationResult; |
| 10376 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10377 | |
| 10378 | /** |
| 10379 | * Set the GbaService Package Name that Telephony will bind to. |
| 10380 | * |
| 10381 | * @param subId The sim that the GbaService is associated with. |
| 10382 | * @param packageName The name of the package to be replaced with. |
| 10383 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10384 | */ |
| 10385 | @Override |
| 10386 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10387 | enforceModifyPermission(); |
| 10388 | |
| 10389 | final long identity = Binder.clearCallingIdentity(); |
| 10390 | try { |
| 10391 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10392 | } finally { |
| 10393 | Binder.restoreCallingIdentity(identity); |
| 10394 | } |
| 10395 | } |
| 10396 | |
| 10397 | /** |
| 10398 | * Return the package name of the currently bound GbaService. |
| 10399 | * |
| 10400 | * @param subId The sim that the GbaService is associated with. |
| 10401 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10402 | */ |
| 10403 | @Override |
| 10404 | public String getBoundGbaService(int subId) { |
| 10405 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10406 | |
| 10407 | final long identity = Binder.clearCallingIdentity(); |
| 10408 | try { |
| 10409 | return getGbaManager(subId).getServicePackage(); |
| 10410 | } finally { |
| 10411 | Binder.restoreCallingIdentity(identity); |
| 10412 | } |
| 10413 | } |
| 10414 | |
| 10415 | /** |
| 10416 | * Set the release time for telephony to unbind GbaService. |
| 10417 | * |
| 10418 | * @param subId The sim that the GbaService is associated with. |
| 10419 | * @param interval The release time to unbind GbaService by millisecond. |
| 10420 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10421 | */ |
| 10422 | @Override |
| 10423 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10424 | enforceModifyPermission(); |
| 10425 | |
| 10426 | final long identity = Binder.clearCallingIdentity(); |
| 10427 | try { |
| 10428 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10429 | } finally { |
| 10430 | Binder.restoreCallingIdentity(identity); |
| 10431 | } |
| 10432 | } |
| 10433 | |
| 10434 | /** |
| 10435 | * Return the release time for telephony to unbind GbaService. |
| 10436 | * |
| 10437 | * @param subId The sim that the GbaService is associated with. |
| 10438 | * @return The release time to unbind GbaService by millisecond. |
| 10439 | */ |
| 10440 | @Override |
| 10441 | public int getGbaReleaseTime(int subId) { |
| 10442 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10443 | |
| 10444 | final long identity = Binder.clearCallingIdentity(); |
| 10445 | try { |
| 10446 | return getGbaManager(subId).getReleaseTime(); |
| 10447 | } finally { |
| 10448 | Binder.restoreCallingIdentity(identity); |
| 10449 | } |
| 10450 | } |
| 10451 | |
| 10452 | private GbaManager getGbaManager(int subId) { |
| 10453 | GbaManager instance = GbaManager.getInstance(subId); |
| 10454 | if (instance == null) { |
| 10455 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10456 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10457 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10458 | } |
| 10459 | return instance; |
| 10460 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10461 | |
| 10462 | /** |
| 10463 | * indicate whether the device and the carrier can support |
| 10464 | * RCS VoLTE single registration. |
| 10465 | */ |
| 10466 | @Override |
| 10467 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10468 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10469 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10470 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10471 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10472 | |
| 10473 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10474 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10475 | } |
| 10476 | |
| 10477 | final long identity = Binder.clearCallingIdentity(); |
| 10478 | try { |
| 10479 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10480 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10481 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10482 | if (isCapable != null) { |
| 10483 | return isCapable; |
| 10484 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10485 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10486 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10487 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10488 | } finally { |
| 10489 | Binder.restoreCallingIdentity(identity); |
| 10490 | } |
| 10491 | } |
| 10492 | |
| 10493 | /** |
| 10494 | * Register RCS provisioning callback. |
| 10495 | */ |
| 10496 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10497 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10498 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10499 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10500 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10501 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10502 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10503 | |
| 10504 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10505 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10506 | } |
| 10507 | if (!isImsAvailableOnDevice()) { |
| 10508 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10509 | "IMS not available on device."); |
| 10510 | } |
| 10511 | |
| 10512 | final long identity = Binder.clearCallingIdentity(); |
| 10513 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10514 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10515 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10516 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10517 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10518 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10519 | } finally { |
| 10520 | Binder.restoreCallingIdentity(identity); |
| 10521 | } |
| 10522 | } |
| 10523 | |
| 10524 | /** |
| 10525 | * Unregister RCS provisioning callback. |
| 10526 | */ |
| 10527 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10528 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10529 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10530 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10531 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10532 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10533 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10534 | |
| 10535 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10536 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10537 | } |
| 10538 | if (!isImsAvailableOnDevice()) { |
| 10539 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10540 | "IMS not available on device."); |
| 10541 | } |
| 10542 | |
| 10543 | final long identity = Binder.clearCallingIdentity(); |
| 10544 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10545 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10546 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10547 | } finally { |
| 10548 | Binder.restoreCallingIdentity(identity); |
| 10549 | } |
| 10550 | } |
| 10551 | |
| 10552 | /** |
| 10553 | * trigger RCS reconfiguration. |
| 10554 | */ |
| 10555 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10556 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10557 | "triggerRcsReconfiguration", |
| 10558 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10559 | |
| 10560 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10561 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10562 | } |
| 10563 | if (!isImsAvailableOnDevice()) { |
| 10564 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10565 | "IMS not available on device."); |
| 10566 | } |
| 10567 | |
| 10568 | final long identity = Binder.clearCallingIdentity(); |
| 10569 | try { |
| 10570 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10571 | } finally { |
| 10572 | Binder.restoreCallingIdentity(identity); |
| 10573 | } |
| 10574 | } |
| 10575 | |
| 10576 | /** |
| 10577 | * Provide the client configuration parameters of the RCS application. |
| 10578 | */ |
| 10579 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10580 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10581 | "setRcsClientConfiguration", |
| 10582 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10583 | |
| 10584 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10585 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10586 | } |
| 10587 | if (!isImsAvailableOnDevice()) { |
| 10588 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10589 | "IMS not available on device."); |
| 10590 | } |
| 10591 | |
| 10592 | final long identity = Binder.clearCallingIdentity(); |
| 10593 | |
| 10594 | try { |
| 10595 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10596 | if (configBinder == null) { |
| 10597 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10598 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10599 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10600 | } else { |
| 10601 | configBinder.setRcsClientConfiguration(rcc); |
| 10602 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 10603 | |
| 10604 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 10605 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10606 | } catch (RemoteException e) { |
| 10607 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10608 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10609 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10610 | } finally { |
| 10611 | Binder.restoreCallingIdentity(identity); |
| 10612 | } |
| 10613 | } |
| 10614 | |
| 10615 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10616 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10617 | */ |
| 10618 | @Override |
| 10619 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10620 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10621 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10622 | |
| 10623 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10624 | } |
| 10625 | |
| 10626 | /** |
| 10627 | * Gets the test mode for RCS VoLTE single registration. |
| 10628 | */ |
| 10629 | @Override |
| 10630 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10631 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10632 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10633 | |
| 10634 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10635 | } |
| 10636 | |
| 10637 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10638 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10639 | */ |
| 10640 | @Override |
| 10641 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10642 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10643 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10644 | enforceModifyPermission(); |
| 10645 | |
| 10646 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10647 | : Boolean.parseBoolean(enabledStr); |
| 10648 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10649 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10650 | } |
| 10651 | |
| 10652 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10653 | * Sends a device to device communication message. Only usable via shell. |
| 10654 | * @param message message to send. |
| 10655 | * @param value message value. |
| 10656 | */ |
| 10657 | @Override |
| 10658 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10659 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10660 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10661 | enforceModifyPermission(); |
| 10662 | |
| 10663 | final long identity = Binder.clearCallingIdentity(); |
| 10664 | try { |
| 10665 | TelephonyConnectionService service = |
| 10666 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10667 | if (service == null) { |
| 10668 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10669 | return; |
| 10670 | } |
| 10671 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10672 | } finally { |
| 10673 | Binder.restoreCallingIdentity(identity); |
| 10674 | } |
| 10675 | } |
| 10676 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10677 | /** |
| 10678 | * Sets the specified device to device transport active. |
| 10679 | * @param transport The transport to set active. |
| 10680 | */ |
| 10681 | @Override |
| 10682 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10683 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10684 | "setActiveDeviceToDeviceTransport"); |
| 10685 | enforceModifyPermission(); |
| 10686 | |
| 10687 | final long identity = Binder.clearCallingIdentity(); |
| 10688 | try { |
| 10689 | TelephonyConnectionService service = |
| 10690 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10691 | if (service == null) { |
| 10692 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10693 | return; |
| 10694 | } |
| 10695 | service.setActiveDeviceToDeviceTransport(transport); |
| 10696 | } finally { |
| 10697 | Binder.restoreCallingIdentity(identity); |
| 10698 | } |
| 10699 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10700 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10701 | @Override |
| 10702 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10703 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10704 | "setDeviceToDeviceForceEnabled"); |
| 10705 | |
| 10706 | final long identity = Binder.clearCallingIdentity(); |
| 10707 | try { |
| 10708 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10709 | p -> { |
| 10710 | Phone thePhone = p.getImsPhone(); |
| 10711 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10712 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10713 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10714 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10715 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10716 | (ImsPhoneCallTracker) tracker; |
| 10717 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10718 | } |
| 10719 | } |
| 10720 | } |
| 10721 | ); |
| 10722 | } finally { |
| 10723 | Binder.restoreCallingIdentity(identity); |
| 10724 | } |
| 10725 | } |
| 10726 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10727 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10728 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10729 | */ |
| 10730 | @Override |
| 10731 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10732 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10733 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10734 | } |
| 10735 | |
| 10736 | /** |
| 10737 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10738 | */ |
| 10739 | @Override |
| 10740 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10741 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10742 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10743 | enforceModifyPermission(); |
| 10744 | |
| 10745 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10746 | : Boolean.parseBoolean(enabledStr); |
| 10747 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10748 | subId, enabled); |
| 10749 | } |
| 10750 | |
| 10751 | /** |
| 10752 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10753 | */ |
| 10754 | @Override |
| 10755 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10756 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10757 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10758 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10759 | |
| 10760 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 10761 | * Overrides the ims feature validation result |
| 10762 | */ |
| 10763 | @Override |
| 10764 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 10765 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10766 | "setImsFeatureValidationOverride"); |
| 10767 | |
| 10768 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10769 | : Boolean.parseBoolean(enabledStr); |
| 10770 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 10771 | subId, enabled); |
| 10772 | } |
| 10773 | |
| 10774 | /** |
| 10775 | * Gets the ims feature validation override value |
| 10776 | */ |
| 10777 | @Override |
| 10778 | public boolean getImsFeatureValidationOverride(int subId) { |
| 10779 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10780 | "getImsFeatureValidationOverride"); |
| 10781 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 10782 | } |
| 10783 | |
| 10784 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10785 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10786 | * their mobile plan. |
| 10787 | */ |
| 10788 | @Override |
| 10789 | public String getMobileProvisioningUrl() { |
| 10790 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10791 | final long identity = Binder.clearCallingIdentity(); |
| 10792 | try { |
| 10793 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10794 | } finally { |
| 10795 | Binder.restoreCallingIdentity(identity); |
| 10796 | } |
| 10797 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10798 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10799 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10800 | * Get the EAB contact from the EAB database. |
| 10801 | */ |
| 10802 | @Override |
| 10803 | public String getContactFromEab(String contact) { |
| 10804 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10805 | enforceModifyPermission(); |
| 10806 | final long identity = Binder.clearCallingIdentity(); |
| 10807 | try { |
| 10808 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10809 | } finally { |
| 10810 | Binder.restoreCallingIdentity(identity); |
| 10811 | } |
| 10812 | } |
| 10813 | |
| 10814 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 10815 | * Get the EAB capability from the EAB database. |
| 10816 | */ |
| 10817 | @Override |
| 10818 | public String getCapabilityFromEab(String contact) { |
| 10819 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 10820 | enforceModifyPermission(); |
| 10821 | final long identity = Binder.clearCallingIdentity(); |
| 10822 | try { |
| 10823 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 10824 | } finally { |
| 10825 | Binder.restoreCallingIdentity(identity); |
| 10826 | } |
| 10827 | } |
| 10828 | |
| 10829 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10830 | * Remove the EAB contacts from the EAB database. |
| 10831 | */ |
| 10832 | @Override |
| 10833 | public int removeContactFromEab(int subId, String contacts) { |
| 10834 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10835 | enforceModifyPermission(); |
| 10836 | final long identity = Binder.clearCallingIdentity(); |
| 10837 | try { |
| 10838 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10839 | } finally { |
| 10840 | Binder.restoreCallingIdentity(identity); |
| 10841 | } |
| 10842 | } |
| 10843 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10844 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10845 | public boolean getDeviceUceEnabled() { |
| 10846 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10847 | final long identity = Binder.clearCallingIdentity(); |
| 10848 | try { |
| 10849 | return mApp.getDeviceUceEnabled(); |
| 10850 | } finally { |
| 10851 | Binder.restoreCallingIdentity(identity); |
| 10852 | } |
| 10853 | } |
| 10854 | |
| 10855 | @Override |
| 10856 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10857 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10858 | final long identity = Binder.clearCallingIdentity(); |
| 10859 | try { |
| 10860 | mApp.setDeviceUceEnabled(isEnabled); |
| 10861 | } finally { |
| 10862 | Binder.restoreCallingIdentity(identity); |
| 10863 | } |
| 10864 | } |
| 10865 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10866 | /** |
| 10867 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10868 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10869 | */ |
| 10870 | // Used for SHELL command only right now. |
| 10871 | @Override |
| 10872 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 10873 | List<String> featureTags) { |
| 10874 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10875 | "addUceRegistrationOverrideShell"); |
| 10876 | final long identity = Binder.clearCallingIdentity(); |
| 10877 | try { |
| 10878 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 10879 | new ArraySet<>(featureTags)); |
| 10880 | } catch (ImsException e) { |
| 10881 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10882 | } finally { |
| 10883 | Binder.restoreCallingIdentity(identity); |
| 10884 | } |
| 10885 | } |
| 10886 | |
| 10887 | /** |
| 10888 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10889 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10890 | */ |
| 10891 | // Used for SHELL command only right now. |
| 10892 | @Override |
| 10893 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 10894 | List<String> featureTags) { |
| 10895 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10896 | "removeUceRegistrationOverrideShell"); |
| 10897 | final long identity = Binder.clearCallingIdentity(); |
| 10898 | try { |
| 10899 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 10900 | new ArraySet<>(featureTags)); |
| 10901 | } catch (ImsException e) { |
| 10902 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10903 | } finally { |
| 10904 | Binder.restoreCallingIdentity(identity); |
| 10905 | } |
| 10906 | } |
| 10907 | |
| 10908 | /** |
| 10909 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 10910 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10911 | */ |
| 10912 | // Used for SHELL command only right now. |
| 10913 | @Override |
| 10914 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 10915 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10916 | "clearUceRegistrationOverrideShell"); |
| 10917 | final long identity = Binder.clearCallingIdentity(); |
| 10918 | try { |
| 10919 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 10920 | } catch (ImsException e) { |
| 10921 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10922 | } finally { |
| 10923 | Binder.restoreCallingIdentity(identity); |
| 10924 | } |
| 10925 | } |
| 10926 | |
| 10927 | /** |
| 10928 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10929 | */ |
| 10930 | // Used for SHELL command only right now. |
| 10931 | @Override |
| 10932 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 10933 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10934 | "getLatestRcsContactUceCapabilityShell"); |
| 10935 | final long identity = Binder.clearCallingIdentity(); |
| 10936 | try { |
| 10937 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 10938 | } catch (ImsException e) { |
| 10939 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10940 | } finally { |
| 10941 | Binder.restoreCallingIdentity(identity); |
| 10942 | } |
| 10943 | } |
| 10944 | |
| 10945 | /** |
| 10946 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 10947 | * device does not have an active PUBLISH. |
| 10948 | */ |
| 10949 | // Used for SHELL command only right now. |
| 10950 | @Override |
| 10951 | public String getLastUcePidfXmlShell(int subId) { |
| 10952 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 10953 | final long identity = Binder.clearCallingIdentity(); |
| 10954 | try { |
| 10955 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 10956 | } catch (ImsException e) { |
| 10957 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10958 | } finally { |
| 10959 | Binder.restoreCallingIdentity(identity); |
| 10960 | } |
| 10961 | } |
| 10962 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 10963 | /** |
| 10964 | * Remove UCE requests cannot be sent to the network status. |
| 10965 | */ |
| 10966 | // Used for SHELL command only right now. |
| 10967 | @Override |
| 10968 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 10969 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 10970 | final long identity = Binder.clearCallingIdentity(); |
| 10971 | try { |
| 10972 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 10973 | } catch (ImsException e) { |
| 10974 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10975 | } finally { |
| 10976 | Binder.restoreCallingIdentity(identity); |
| 10977 | } |
| 10978 | } |
| 10979 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 10980 | /** |
| 10981 | * Remove UCE requests cannot be sent to the network status. |
| 10982 | */ |
| 10983 | // Used for SHELL command only. |
| 10984 | @Override |
| 10985 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 10986 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 10987 | final long identity = Binder.clearCallingIdentity(); |
| 10988 | try { |
| 10989 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 10990 | } catch (ImsException e) { |
| 10991 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10992 | } finally { |
| 10993 | Binder.restoreCallingIdentity(identity); |
| 10994 | } |
| 10995 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10996 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10997 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10998 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10999 | String callingPackage) { |
| 11000 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11001 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11002 | |
| 11003 | final int callingUid = Binder.getCallingUid(); |
| 11004 | // Verify that tha callingPackage belongs to the calling UID |
| 11005 | mApp.getSystemService(AppOpsManager.class) |
| 11006 | .checkPackage(callingUid, callingPackage); |
| 11007 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11008 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11009 | |
| 11010 | final long identity = Binder.clearCallingIdentity(); |
| 11011 | try { |
| 11012 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11013 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11014 | |
| 11015 | if (result instanceof IllegalStateException) { |
| 11016 | throw (IllegalStateException) result; |
| 11017 | } |
| 11018 | } finally { |
| 11019 | Binder.restoreCallingIdentity(identity); |
| 11020 | } |
| 11021 | } |
| 11022 | |
| 11023 | @Override |
| 11024 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11025 | String callingPackage) { |
| 11026 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11027 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11028 | |
| 11029 | final int callingUid = Binder.getCallingUid(); |
| 11030 | // Verify that tha callingPackage belongs to the calling UID |
| 11031 | mApp.getSystemService(AppOpsManager.class) |
| 11032 | .checkPackage(callingUid, callingPackage); |
| 11033 | |
| 11034 | final long identity = Binder.clearCallingIdentity(); |
| 11035 | try { |
| 11036 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11037 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11038 | |
| 11039 | if (result instanceof IllegalStateException) { |
| 11040 | throw (IllegalStateException) result; |
| 11041 | } |
| 11042 | } finally { |
| 11043 | Binder.restoreCallingIdentity(identity); |
| 11044 | } |
| 11045 | } |
| 11046 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11047 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11048 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11049 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11050 | // phone/system process do not have further restriction on request |
| 11051 | return; |
| 11052 | } |
| 11053 | |
| 11054 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11055 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11056 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11057 | context.enforceCallingOrSelfPermission( |
| 11058 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11059 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11060 | } |
| 11061 | |
| 11062 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 11063 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 11064 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 11065 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 11066 | || info.isEnabled()) { |
| 11067 | throw new IllegalArgumentException( |
| 11068 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11069 | } |
| 11070 | |
| 11071 | // Thresholds length for each RAN need in range. This has been validated in |
| 11072 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11073 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11074 | final int[] thresholds = info.getThresholds(); |
| 11075 | Objects.requireNonNull(thresholds); |
| 11076 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11077 | || thresholds.length |
| 11078 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11079 | throw new IllegalArgumentException( |
| 11080 | "thresholds length is out of range: " + thresholds.length); |
| 11081 | } |
| 11082 | } |
| 11083 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11084 | |
| 11085 | /** |
| 11086 | * Gets the current phone capability. |
| 11087 | * |
| 11088 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11089 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11090 | * It's used to evaluate possible phone config change, for example from single |
| 11091 | * SIM device to multi-SIM device. |
| 11092 | */ |
| 11093 | @Override |
| 11094 | public PhoneCapability getPhoneCapability() { |
| 11095 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11096 | final long identity = Binder.clearCallingIdentity(); |
| 11097 | try { |
| 11098 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11099 | } finally { |
| 11100 | Binder.restoreCallingIdentity(identity); |
| 11101 | } |
| 11102 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11103 | |
| 11104 | /** |
| 11105 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11106 | * required to be done shortly after the API is invoked. |
| 11107 | */ |
| 11108 | @Override |
| 11109 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11110 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11111 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11112 | enforceRebootPermission(); |
| 11113 | |
| 11114 | final long identity = Binder.clearCallingIdentity(); |
| 11115 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11116 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11117 | } finally { |
| 11118 | Binder.restoreCallingIdentity(identity); |
| 11119 | } |
| 11120 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11121 | |
| 11122 | /** |
| 11123 | * Request to get the current slicing configuration including URSP rules and |
| 11124 | * NSSAIs (configured, allowed and rejected). |
| 11125 | * |
| 11126 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11127 | */ |
| 11128 | @Override |
| 11129 | public void getSlicingConfig(ResultReceiver callback) { |
| 11130 | enforceReadPrivilegedPermission("getSlicingConfig"); |
| 11131 | |
| 11132 | final long identity = Binder.clearCallingIdentity(); |
| 11133 | try { |
| 11134 | Phone phone = getDefaultPhone(); |
| 11135 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11136 | } finally { |
| 11137 | Binder.restoreCallingIdentity(identity); |
| 11138 | } |
| 11139 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11140 | |
| 11141 | /** |
| 11142 | * Register an IMS connection state callback |
| 11143 | */ |
| 11144 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11145 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11146 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11147 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11148 | // ImsMmTelManager |
| 11149 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11150 | TelephonyPermissions |
| 11151 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11152 | mApp, subId, "registerImsStateCallback"); |
| 11153 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11154 | // ImsRcsManager or SipDelegateManager |
| 11155 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11156 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11157 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11158 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11159 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11160 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11161 | } |
| 11162 | |
| 11163 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11164 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11165 | "IMS not available on device."); |
| 11166 | } |
| 11167 | |
| 11168 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11169 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11170 | } |
| 11171 | |
| 11172 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11173 | if (controller == null) { |
| 11174 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11175 | "IMS not available on device."); |
| 11176 | } |
| 11177 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11178 | if (callingPackage == null) { |
| 11179 | callingPackage = getCurrentPackageName(); |
| 11180 | } |
| 11181 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11182 | final long token = Binder.clearCallingIdentity(); |
| 11183 | try { |
| 11184 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11185 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11186 | } catch (ImsException e) { |
| 11187 | throw new ServiceSpecificException(e.getCode()); |
| 11188 | } finally { |
| 11189 | Binder.restoreCallingIdentity(token); |
| 11190 | } |
| 11191 | } |
| 11192 | |
| 11193 | /** |
| 11194 | * Unregister an IMS connection state callback |
| 11195 | */ |
| 11196 | @Override |
| 11197 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11198 | final long token = Binder.clearCallingIdentity(); |
| 11199 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11200 | if (controller == null) { |
| 11201 | return; |
| 11202 | } |
| 11203 | try { |
| 11204 | controller.unregisterImsStateCallback(cb); |
| 11205 | } finally { |
| 11206 | Binder.restoreCallingIdentity(token); |
| 11207 | } |
| 11208 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11209 | |
| 11210 | /** |
| 11211 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11212 | * |
| 11213 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11214 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11215 | * SecurityException. |
| 11216 | * If there is current registered network this value will be same as the registered cell |
| 11217 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11218 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11219 | * it will be cleared and null will be returned. |
| 11220 | * |
| 11221 | */ |
| 11222 | @Override |
| 11223 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11224 | String callingFeatureId) { |
| 11225 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11226 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11227 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11228 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11229 | .setCallingPackage(callingPackage) |
| 11230 | .setCallingFeatureId(callingFeatureId) |
| 11231 | .setCallingPid(Binder.getCallingPid()) |
| 11232 | .setCallingUid(Binder.getCallingUid()) |
| 11233 | .setMethod("getLastKnownCellIdentity") |
| 11234 | .setLogAsInfo(true) |
| 11235 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11236 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11237 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11238 | .build()); |
| 11239 | |
| 11240 | boolean hasFinePermission = |
| 11241 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11242 | if (!hasFinePermission |
| 11243 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11244 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
| 11245 | + "and BIND_CONNECTION_SERVICE permission."); |
| 11246 | } |
| 11247 | |
| 11248 | final long identity = Binder.clearCallingIdentity(); |
| 11249 | try { |
| 11250 | Phone phone = getPhone(subId); |
| 11251 | if (phone == null) return null; |
| 11252 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 11253 | if (sst == null) return null; |
| 11254 | return sst.getLastKnownCellIdentity(); |
| 11255 | } finally { |
| 11256 | Binder.restoreCallingIdentity(identity); |
| 11257 | } |
| 11258 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11259 | |
| 11260 | @Override |
| 11261 | public boolean isUsingNewDataStack() { |
| 11262 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack"); |
| 11263 | return getDefaultPhone().isUsingNewDataStack(); |
| 11264 | } |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame^] | 11265 | |
| 11266 | /** |
| 11267 | * Sets the modem service class Name that Telephony will bind to. |
| 11268 | * |
| 11269 | * @param serviceName The class name of the modem service. |
| 11270 | * @return true if the operation is succeed, otherwise false. |
| 11271 | */ |
| 11272 | public boolean setModemService(String serviceName) { |
| 11273 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11274 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11275 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 11276 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11277 | "setModemService"); |
| 11278 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11279 | } |
| 11280 | |
| 11281 | /** |
| 11282 | * Return the class name of the currently bounded modem service. |
| 11283 | * |
| 11284 | * @return the class name of the modem service. |
| 11285 | */ |
| 11286 | public String getModemService() { |
| 11287 | String result; |
| 11288 | Log.d(LOG_TAG, "getModemService"); |
| 11289 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11290 | TelephonyPermissions |
| 11291 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11292 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11293 | "getModemService"); |
| 11294 | result = mPhoneConfigurationManager.getModemService(); |
| 11295 | Log.d(LOG_TAG, "result = " + result); |
| 11296 | return result; |
| 11297 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 11298 | } |