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; |
| 25 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 26 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 27 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 28 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 29 | import android.annotation.Nullable; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame^] | 30 | import android.annotation.RequiresPermission; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 31 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 32 | import android.app.PendingIntent; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 33 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 34 | import android.app.role.RoleManager; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame^] | 35 | import android.compat.annotation.ChangeId; |
| 36 | import android.compat.annotation.EnabledSince; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 37 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 38 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 39 | import android.content.Context; |
| 40 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 41 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 42 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 43 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 44 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.net.Uri; |
| 46 | import android.os.AsyncResult; |
| 47 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 48 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 49 | import android.os.Bundle; |
| 50 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 51 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 52 | import android.os.Looper; |
| 53 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 54 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 55 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 56 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 57 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 58 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 59 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 60 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 61 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 62 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 63 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 64 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 65 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 66 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 67 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 68 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 69 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 70 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 71 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 72 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 73 | import android.telecom.TelecomManager; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 74 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 75 | import android.telephony.Annotation.ThermalMitigationResult; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 76 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 77 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 78 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 79 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 80 | import android.telephony.CellIdentityCdma; |
| 81 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 82 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 83 | import android.telephony.CellInfoGsm; |
| 84 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 85 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 86 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 87 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 88 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 89 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 90 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 91 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 92 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 93 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 94 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 95 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 96 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 97 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 98 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 99 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 100 | import android.telephony.SignalStrengthUpdateRequest; |
| 101 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 102 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 103 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 104 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 105 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 106 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 107 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 108 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 109 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame^] | 110 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 111 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame^] | 112 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 113 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 114 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 115 | import android.telephony.data.ApnSetting; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 116 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 117 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 118 | import android.telephony.gba.GbaAuthRequest; |
| 119 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 120 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 121 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 122 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 123 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 124 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 125 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 126 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 127 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 128 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 129 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 130 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 131 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 132 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 133 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 134 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 135 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 136 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 137 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 138 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 139 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 140 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 141 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 142 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 143 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 144 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 145 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 146 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.CallTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 157 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 161 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 163 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 166 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 169 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 174 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 175 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 179 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 180 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 181 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 183 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 185 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 187 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 188 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 189 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 191 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 192 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 193 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 194 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 195 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 196 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 197 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 198 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 199 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 200 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 201 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 202 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 203 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 204 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 205 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 206 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 207 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 208 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 209 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 210 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 211 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 212 | import com.android.services.telephony.TelecomAccountRegistry; |
| 213 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 214 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 215 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 216 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 217 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 218 | import java.io.IOException; |
| 219 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 220 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 221 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 222 | import java.util.Arrays; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame^] | 223 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 224 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 225 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 226 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 227 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 228 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 229 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 230 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 231 | import java.util.Set; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 232 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 233 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 234 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 235 | |
| 236 | /** |
| 237 | * Implementation of the ITelephony interface. |
| 238 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 239 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 240 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 241 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 242 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 243 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 244 | |
| 245 | // Message codes used with mMainThreadHandler |
| 246 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 247 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 248 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 249 | private static final int CMD_OPEN_CHANNEL = 9; |
| 250 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 251 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 252 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 253 | private static final int CMD_NV_READ_ITEM = 13; |
| 254 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 255 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 256 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 257 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 258 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 259 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 260 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 261 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 262 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 263 | private static final int CMD_SEND_ENVELOPE = 25; |
| 264 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 265 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 266 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 267 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 268 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 269 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 270 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 271 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 272 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 273 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 274 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 275 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 276 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 277 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 278 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 279 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 280 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 281 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 282 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 283 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 284 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 285 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 286 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 287 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 288 | private static final int CMD_SWITCH_SLOTS = 50; |
| 289 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 290 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 291 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 292 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 293 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 294 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 295 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 296 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 297 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 298 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 299 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 300 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 301 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 302 | private static final int CMD_MODEM_REBOOT = 64; |
| 303 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 304 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 305 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 306 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 307 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 308 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 309 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 310 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 311 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 312 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 313 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 314 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 315 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 316 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 317 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 318 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 319 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 320 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 321 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 322 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 323 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 324 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 325 | private static final int CMD_GET_CALL_WAITING = 87; |
| 326 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 327 | private static final int CMD_SET_CALL_WAITING = 89; |
| 328 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 329 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 330 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 331 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 332 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 333 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 334 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 335 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 336 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 337 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 338 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 339 | private static final int CMD_SET_SIM_POWER = 101; |
| 340 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 341 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 342 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 343 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 344 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 345 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 346 | 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] | 347 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 348 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 349 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 350 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 351 | private static final int CMD_ENABLE_VONR = 113; |
| 352 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 353 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 354 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 355 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 356 | // Parameters of select command. |
| 357 | private static final int SELECT_COMMAND = 0xA4; |
| 358 | private static final int SELECT_P1 = 0x04; |
| 359 | private static final int SELECT_P2 = 0; |
| 360 | private static final int SELECT_P3 = 0x10; |
| 361 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 362 | /** The singleton instance. */ |
| 363 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 364 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 365 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 366 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 367 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 368 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 369 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 370 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 371 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 372 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 373 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 374 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 375 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 376 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 377 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 378 | /** User Activity */ |
| 379 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 380 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 381 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 382 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 383 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 384 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 385 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 386 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 387 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 388 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 389 | // String to store multi SIM allowed |
| 390 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 391 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 392 | // The AID of ISD-R. |
| 393 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 394 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 395 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 396 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 397 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 398 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 399 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 400 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 401 | 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] | 402 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 403 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 404 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 405 | */ |
| 406 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 407 | "reset_network_erase_modem_config_enabled"; |
| 408 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 409 | 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^] | 410 | /** |
| 411 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 412 | * one ICCID active at the same time. |
| 413 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 414 | * |
| 415 | * @hide |
| 416 | */ |
| 417 | @ChangeId |
| 418 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 419 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 420 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 421 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 422 | * A request object to use for transmitting data to an ICC. |
| 423 | */ |
| 424 | private static final class IccAPDUArgument { |
| 425 | public int channel, cla, command, p1, p2, p3; |
| 426 | public String data; |
| 427 | |
| 428 | public IccAPDUArgument(int channel, int cla, int command, |
| 429 | int p1, int p2, int p3, String data) { |
| 430 | this.channel = channel; |
| 431 | this.cla = cla; |
| 432 | this.command = command; |
| 433 | this.p1 = p1; |
| 434 | this.p2 = p2; |
| 435 | this.p3 = p3; |
| 436 | this.data = data; |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 441 | * A request object to use for transmitting data to an ICC. |
| 442 | */ |
| 443 | private static final class ManualNetworkSelectionArgument { |
| 444 | public OperatorInfo operatorInfo; |
| 445 | public boolean persistSelection; |
| 446 | |
| 447 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 448 | this.operatorInfo = operatorInfo; |
| 449 | this.persistSelection = persistSelection; |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 454 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 455 | * request after sending. The main thread will notify the request when it is complete. |
| 456 | */ |
| 457 | private static final class MainThreadRequest { |
| 458 | /** The argument to use for the request */ |
| 459 | public Object argument; |
| 460 | /** The result of the request that is run on the main thread */ |
| 461 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 462 | // The subscriber id that this request applies to. Defaults to |
| 463 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 464 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 465 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 466 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 467 | public Phone phone; |
| 468 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 469 | public WorkSource workSource; |
| 470 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 471 | public MainThreadRequest(Object argument) { |
| 472 | this.argument = argument; |
| 473 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 474 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 475 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 476 | this.argument = argument; |
| 477 | if (phone != null) { |
| 478 | this.phone = phone; |
| 479 | } |
| 480 | this.workSource = workSource; |
| 481 | } |
| 482 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 483 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 484 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 485 | if (subId != null) { |
| 486 | this.subId = subId; |
| 487 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 488 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 489 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 492 | private static final class IncomingThirdPartyCallArgs { |
| 493 | public final ComponentName component; |
| 494 | public final String callId; |
| 495 | public final String callerDisplayName; |
| 496 | |
| 497 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 498 | String callerDisplayName) { |
| 499 | this.component = component; |
| 500 | this.callId = callId; |
| 501 | this.callerDisplayName = callerDisplayName; |
| 502 | } |
| 503 | } |
| 504 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 505 | /** |
| 506 | * A handler that processes messages on the main thread in the phone process. Since many |
| 507 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 508 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 509 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 510 | * on, which will be notified when the operation completes and will contain the result of the |
| 511 | * request. |
| 512 | * |
| 513 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 514 | * note that request.result must be set to something non-null for the calling thread to |
| 515 | * unblock. |
| 516 | */ |
| 517 | private final class MainThreadHandler extends Handler { |
| 518 | @Override |
| 519 | public void handleMessage(Message msg) { |
| 520 | MainThreadRequest request; |
| 521 | Message onCompleted; |
| 522 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 523 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 524 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 525 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 526 | |
| 527 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 528 | case CMD_HANDLE_USSD_REQUEST: { |
| 529 | request = (MainThreadRequest) msg.obj; |
| 530 | final Phone phone = getPhoneFromRequest(request); |
| 531 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 532 | String ussdRequest = ussdObject.first; |
| 533 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 534 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 535 | if (!isUssdApiAllowed(request.subId)) { |
| 536 | // Carrier does not support use of this API, return failure. |
| 537 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 538 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 539 | Bundle returnData = new Bundle(); |
| 540 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 541 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 542 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 543 | request.result = true; |
| 544 | notifyRequester(request); |
| 545 | return; |
| 546 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 547 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 548 | try { |
| 549 | request.result = phone != null |
| 550 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 551 | } catch (CallStateException cse) { |
| 552 | request.result = false; |
| 553 | } |
| 554 | // Wake up the requesting thread |
| 555 | notifyRequester(request); |
| 556 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 557 | } |
| 558 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 559 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 560 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 561 | final Phone phone = getPhoneFromRequest(request); |
| 562 | request.result = phone != null ? |
| 563 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 564 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 565 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 566 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 567 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 568 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 569 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 570 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 571 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 572 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 573 | uiccPort = getUiccPortFromRequest(request); |
| 574 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 575 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 576 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 577 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 578 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 579 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 580 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 581 | uiccPort.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 582 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 583 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 584 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 585 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 586 | break; |
| 587 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 588 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 589 | ar = (AsyncResult) msg.obj; |
| 590 | request = (MainThreadRequest) ar.userObj; |
| 591 | if (ar.exception == null && ar.result != null) { |
| 592 | request.result = ar.result; |
| 593 | } else { |
| 594 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 595 | if (ar.result == null) { |
| 596 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 597 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 598 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 599 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 600 | } else { |
| 601 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 602 | } |
| 603 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 604 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 605 | break; |
| 606 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 607 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 608 | request = (MainThreadRequest) msg.obj; |
| 609 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 610 | uiccPort = getUiccPortFromRequest(request); |
| 611 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 612 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 613 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 614 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 615 | } else { |
| 616 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 617 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 618 | uiccPort.iccTransmitApduBasicChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 619 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 620 | iccArgument.p3, iccArgument.data, onCompleted); |
| 621 | } |
| 622 | break; |
| 623 | |
| 624 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 625 | ar = (AsyncResult) msg.obj; |
| 626 | request = (MainThreadRequest) ar.userObj; |
| 627 | if (ar.exception == null && ar.result != null) { |
| 628 | request.result = ar.result; |
| 629 | } else { |
| 630 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 631 | if (ar.result == null) { |
| 632 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 633 | } else if (ar.exception instanceof CommandException) { |
| 634 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 635 | ar.exception); |
| 636 | } else { |
| 637 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 638 | } |
| 639 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 640 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 641 | break; |
| 642 | |
| 643 | case CMD_EXCHANGE_SIM_IO: |
| 644 | request = (MainThreadRequest) msg.obj; |
| 645 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 646 | uiccPort = getUiccPortFromRequest(request); |
| 647 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 648 | loge("iccExchangeSimIO: No UICC"); |
| 649 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 650 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 651 | } else { |
| 652 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 653 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 654 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 655 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 656 | iccArgument.data, onCompleted); |
| 657 | } |
| 658 | break; |
| 659 | |
| 660 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 661 | ar = (AsyncResult) msg.obj; |
| 662 | request = (MainThreadRequest) ar.userObj; |
| 663 | if (ar.exception == null && ar.result != null) { |
| 664 | request.result = ar.result; |
| 665 | } else { |
| 666 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 667 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 668 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 669 | break; |
| 670 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 671 | case CMD_SEND_ENVELOPE: |
| 672 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 673 | uiccPort = getUiccPortFromRequest(request); |
| 674 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 675 | loge("sendEnvelopeWithStatus: No UICC"); |
| 676 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 677 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 678 | } else { |
| 679 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 680 | uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 681 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 682 | break; |
| 683 | |
| 684 | case EVENT_SEND_ENVELOPE_DONE: |
| 685 | ar = (AsyncResult) msg.obj; |
| 686 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 687 | if (ar.exception == null && ar.result != null) { |
| 688 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 689 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 690 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 691 | if (ar.result == null) { |
| 692 | loge("sendEnvelopeWithStatus: Empty response"); |
| 693 | } else if (ar.exception instanceof CommandException) { |
| 694 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 695 | ar.exception); |
| 696 | } else { |
| 697 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 698 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 699 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 700 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 701 | break; |
| 702 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 703 | case CMD_OPEN_CHANNEL: |
| 704 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 705 | uiccPort = getUiccPortFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 706 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 707 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 708 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 709 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 710 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 711 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 712 | } else { |
| 713 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 714 | uiccPort.iccOpenLogicalChannel(openChannelArgs.first, |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 715 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 716 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 717 | break; |
| 718 | |
| 719 | case EVENT_OPEN_CHANNEL_DONE: |
| 720 | ar = (AsyncResult) msg.obj; |
| 721 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 722 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 723 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 724 | int[] result = (int[]) ar.result; |
| 725 | int channelId = result[0]; |
| 726 | byte[] selectResponse = null; |
| 727 | if (result.length > 1) { |
| 728 | selectResponse = new byte[result.length - 1]; |
| 729 | for (int i = 1; i < result.length; ++i) { |
| 730 | selectResponse[i - 1] = (byte) result[i]; |
| 731 | } |
| 732 | } |
| 733 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 734 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 735 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 736 | if (ar.result == null) { |
| 737 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 738 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 739 | if (ar.exception != null) { |
| 740 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 741 | } |
| 742 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 743 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 744 | if (ar.exception instanceof CommandException) { |
| 745 | CommandException.Error error = |
| 746 | ((CommandException) (ar.exception)).getCommandError(); |
| 747 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 748 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 749 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 750 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 751 | } |
| 752 | } |
| 753 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 754 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 755 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 756 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 757 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 758 | break; |
| 759 | |
| 760 | case CMD_CLOSE_CHANNEL: |
| 761 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 762 | uiccPort = getUiccPortFromRequest(request); |
| 763 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 764 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 765 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 766 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 767 | } else { |
| 768 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 769 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 770 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 771 | break; |
| 772 | |
| 773 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 774 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 775 | break; |
| 776 | |
| 777 | case CMD_NV_READ_ITEM: |
| 778 | request = (MainThreadRequest) msg.obj; |
| 779 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 780 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 781 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 782 | break; |
| 783 | |
| 784 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 785 | ar = (AsyncResult) msg.obj; |
| 786 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 787 | if (ar.exception == null && ar.result != null) { |
| 788 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 789 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 790 | request.result = ""; |
| 791 | if (ar.result == null) { |
| 792 | loge("nvReadItem: Empty response"); |
| 793 | } else if (ar.exception instanceof CommandException) { |
| 794 | loge("nvReadItem: CommandException: " + |
| 795 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 796 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 797 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 798 | } |
| 799 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 800 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 801 | break; |
| 802 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 803 | case CMD_NV_WRITE_ITEM: |
| 804 | request = (MainThreadRequest) msg.obj; |
| 805 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 806 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 807 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 808 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 809 | break; |
| 810 | |
| 811 | case EVENT_NV_WRITE_ITEM_DONE: |
| 812 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 813 | break; |
| 814 | |
| 815 | case CMD_NV_WRITE_CDMA_PRL: |
| 816 | request = (MainThreadRequest) msg.obj; |
| 817 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 818 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 819 | break; |
| 820 | |
| 821 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 822 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 823 | break; |
| 824 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 825 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 826 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 827 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 828 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 829 | break; |
| 830 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 831 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 832 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 833 | break; |
| 834 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 835 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 836 | request = (MainThreadRequest) msg.obj; |
| 837 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 838 | request); |
| 839 | Phone phone = getPhoneFromRequest(request); |
| 840 | if (phone != null) { |
| 841 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 842 | } else { |
| 843 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 844 | request.result = false; |
| 845 | notifyRequester(request); |
| 846 | } |
| 847 | break; |
| 848 | } |
| 849 | |
| 850 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 851 | ar = (AsyncResult) msg.obj; |
| 852 | request = (MainThreadRequest) ar.userObj; |
| 853 | if (ar.exception == null && ar.result != null) { |
| 854 | request.result = ar.result; |
| 855 | } else { |
| 856 | // request.result must be set to something non-null |
| 857 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 858 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 859 | request.result = ar.result; |
| 860 | } else { |
| 861 | request.result = false; |
| 862 | } |
| 863 | if (ar.result == null) { |
| 864 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 865 | } else if (ar.exception instanceof CommandException) { |
| 866 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 867 | + ar.exception); |
| 868 | } else { |
| 869 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 870 | } |
| 871 | } |
| 872 | notifyRequester(request); |
| 873 | break; |
| 874 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 875 | case CMD_IS_VONR_ENABLED: { |
| 876 | request = (MainThreadRequest) msg.obj; |
| 877 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 878 | request); |
| 879 | Phone phone = getPhoneFromRequest(request); |
| 880 | if (phone != null) { |
| 881 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 882 | } else { |
| 883 | loge("isVoNrEnabled: No phone object"); |
| 884 | request.result = false; |
| 885 | notifyRequester(request); |
| 886 | } |
| 887 | break; |
| 888 | } |
| 889 | |
| 890 | case EVENT_IS_VONR_ENABLED_DONE: |
| 891 | ar = (AsyncResult) msg.obj; |
| 892 | request = (MainThreadRequest) ar.userObj; |
| 893 | if (ar.exception == null && ar.result != null) { |
| 894 | request.result = ar.result; |
| 895 | } else { |
| 896 | // request.result must be set to something non-null |
| 897 | // for the calling thread to unblock |
| 898 | if (ar.result != null) { |
| 899 | request.result = ar.result; |
| 900 | } else { |
| 901 | request.result = false; |
| 902 | } |
| 903 | if (ar.result == null) { |
| 904 | loge("isVoNrEnabled: Empty response"); |
| 905 | } else if (ar.exception instanceof CommandException) { |
| 906 | loge("isVoNrEnabled: CommandException: " |
| 907 | + ar.exception); |
| 908 | } else { |
| 909 | loge("isVoNrEnabled: Unknown exception"); |
| 910 | } |
| 911 | } |
| 912 | notifyRequester(request); |
| 913 | break; |
| 914 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 915 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 916 | request = (MainThreadRequest) msg.obj; |
| 917 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 918 | Phone phone = getPhoneFromRequest(request); |
| 919 | if (phone != null) { |
| 920 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 921 | request.workSource); |
| 922 | } else { |
| 923 | loge("enableNrDualConnectivity: No phone object"); |
| 924 | request.result = |
| 925 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 926 | notifyRequester(request); |
| 927 | } |
| 928 | break; |
| 929 | } |
| 930 | |
| 931 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 932 | ar = (AsyncResult) msg.obj; |
| 933 | request = (MainThreadRequest) ar.userObj; |
| 934 | if (ar.exception == null) { |
| 935 | request.result = |
| 936 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 937 | } else { |
| 938 | request.result = |
| 939 | TelephonyManager |
| 940 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 941 | if (ar.exception instanceof CommandException) { |
| 942 | CommandException.Error error = |
| 943 | ((CommandException) (ar.exception)).getCommandError(); |
| 944 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 945 | request.result = |
| 946 | TelephonyManager |
| 947 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 948 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 949 | request.result = |
| 950 | TelephonyManager |
| 951 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 952 | } |
| 953 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 954 | + ar.exception); |
| 955 | } else { |
| 956 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 957 | } |
| 958 | } |
| 959 | notifyRequester(request); |
| 960 | break; |
| 961 | } |
| 962 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 963 | case CMD_ENABLE_VONR: { |
| 964 | request = (MainThreadRequest) msg.obj; |
| 965 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 966 | Phone phone = getPhoneFromRequest(request); |
| 967 | if (phone != null) { |
| 968 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 969 | request.workSource); |
| 970 | } else { |
| 971 | loge("setVoNrEnabled: No phone object"); |
| 972 | request.result = |
| 973 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 974 | notifyRequester(request); |
| 975 | } |
| 976 | break; |
| 977 | } |
| 978 | |
| 979 | case EVENT_ENABLE_VONR_DONE: { |
| 980 | ar = (AsyncResult) msg.obj; |
| 981 | request = (MainThreadRequest) ar.userObj; |
| 982 | if (ar.exception == null) { |
| 983 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 984 | } else { |
| 985 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 986 | if (ar.exception instanceof CommandException) { |
| 987 | CommandException.Error error = |
| 988 | ((CommandException) (ar.exception)).getCommandError(); |
| 989 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 990 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 991 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 992 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 993 | } else { |
| 994 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 995 | } |
| 996 | loge("setVoNrEnabled" + ": CommandException: " |
| 997 | + ar.exception); |
| 998 | } else { |
| 999 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1000 | } |
| 1001 | } |
| 1002 | notifyRequester(request); |
| 1003 | break; |
| 1004 | } |
| 1005 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1006 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1007 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1008 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1009 | request); |
| 1010 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1011 | break; |
| 1012 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1013 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1014 | ar = (AsyncResult) msg.obj; |
| 1015 | request = (MainThreadRequest) ar.userObj; |
| 1016 | if (ar.exception == null && ar.result != null) { |
| 1017 | request.result = ar.result; // Integer |
| 1018 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1019 | // request.result must be set to something non-null |
| 1020 | // for the calling thread to unblock |
| 1021 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1022 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1023 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1024 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1025 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1026 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1027 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1028 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1029 | } |
| 1030 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1031 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1032 | break; |
| 1033 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1034 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1035 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1036 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1037 | request); |
| 1038 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1039 | (Pair<Integer, Long>) request.argument; |
| 1040 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1041 | reasonWithNetworkTypes.first, |
| 1042 | reasonWithNetworkTypes.second, |
| 1043 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1044 | break; |
| 1045 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1046 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1047 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1048 | break; |
| 1049 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1050 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1051 | request = (MainThreadRequest)msg.obj; |
| 1052 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1053 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1054 | break; |
| 1055 | |
| 1056 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1057 | ar = (AsyncResult)msg.obj; |
| 1058 | request = (MainThreadRequest)ar.userObj; |
| 1059 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1060 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1061 | break; |
| 1062 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1063 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1064 | request = (MainThreadRequest) msg.obj; |
| 1065 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1066 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1067 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1068 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1069 | break; |
| 1070 | |
| 1071 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1072 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1073 | break; |
| 1074 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1075 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1076 | request = (MainThreadRequest) msg.obj; |
| 1077 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1078 | request); |
| 1079 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1080 | break; |
| 1081 | |
| 1082 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1083 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1084 | break; |
| 1085 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1086 | case CMD_PERFORM_NETWORK_SCAN: |
| 1087 | request = (MainThreadRequest) msg.obj; |
| 1088 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1089 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1090 | break; |
| 1091 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1092 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1093 | request = (MainThreadRequest) msg.obj; |
| 1094 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1095 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1096 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1097 | request.argument; |
| 1098 | int callForwardingReason = args.first; |
| 1099 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1100 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1101 | } |
| 1102 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1103 | ar = (AsyncResult) msg.obj; |
| 1104 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1105 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1106 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1107 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1108 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1109 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1110 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1111 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1112 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1113 | // any service for voice call. |
| 1114 | if ((callForwardInfo.serviceClass |
| 1115 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1116 | callForwardingInfo = new CallForwardingInfo(true, |
| 1117 | callForwardInfo.reason, |
| 1118 | callForwardInfo.number, |
| 1119 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1120 | break; |
| 1121 | } |
| 1122 | } |
| 1123 | // Didn't find a call forward info for voice call. |
| 1124 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1125 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1126 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1127 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1128 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1129 | } else { |
| 1130 | if (ar.result == null) { |
| 1131 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1132 | } |
| 1133 | if (ar.exception != null) { |
| 1134 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1135 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1136 | int errorCode = TelephonyManager |
| 1137 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1138 | if (ar.exception instanceof CommandException) { |
| 1139 | CommandException.Error error = |
| 1140 | ((CommandException) (ar.exception)).getCommandError(); |
| 1141 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1142 | errorCode = TelephonyManager |
| 1143 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1144 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1145 | errorCode = TelephonyManager |
| 1146 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1147 | } |
| 1148 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1149 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1150 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1151 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1152 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1153 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1154 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1155 | request = (MainThreadRequest) msg.obj; |
| 1156 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1157 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1158 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1159 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1160 | request.argument).first; |
| 1161 | request.phone.setCallForwardingOption( |
| 1162 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1163 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1164 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1165 | callForwardingInfoToSet.getReason(), |
| 1166 | callForwardingInfoToSet.getNumber(), |
| 1167 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1168 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1169 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1170 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1171 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1172 | ar = (AsyncResult) msg.obj; |
| 1173 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1174 | Consumer<Integer> callback = |
| 1175 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1176 | request.argument).second; |
| 1177 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1178 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1179 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1180 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1181 | if (ar.exception instanceof CommandException) { |
| 1182 | CommandException.Error error = |
| 1183 | ((CommandException) (ar.exception)).getCommandError(); |
| 1184 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1185 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1186 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1187 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1188 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1189 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1190 | } |
| 1191 | } |
| 1192 | callback.accept(errorCode); |
| 1193 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1194 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1195 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1196 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1197 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1198 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1199 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1200 | request = (MainThreadRequest) msg.obj; |
| 1201 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1202 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 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 EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1207 | ar = (AsyncResult) msg.obj; |
| 1208 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1209 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1210 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1211 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1212 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1213 | // Service Class is a bit mask per 3gpp 27.007. |
| 1214 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1215 | if (callForwardResults.length > 1 |
| 1216 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1217 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1218 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1219 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1220 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1221 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1222 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1223 | } |
| 1224 | } else { |
| 1225 | if (ar.result == null) { |
| 1226 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1227 | } |
| 1228 | if (ar.exception != null) { |
| 1229 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1230 | } |
| 1231 | if (ar.exception instanceof CommandException) { |
| 1232 | CommandException.Error error = |
| 1233 | ((CommandException) (ar.exception)).getCommandError(); |
| 1234 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1235 | callForwardingStatus = |
| 1236 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1237 | } |
| 1238 | } |
| 1239 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1240 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1241 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1242 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1243 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1244 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1245 | request = (MainThreadRequest) msg.obj; |
| 1246 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1247 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1248 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1249 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1250 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1251 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1252 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1253 | ar = (AsyncResult) msg.obj; |
| 1254 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1255 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1256 | Consumer<Integer> callback = |
| 1257 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1258 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1259 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1260 | if (ar.exception instanceof CommandException) { |
| 1261 | CommandException.Error error = |
| 1262 | ((CommandException) (ar.exception)).getCommandError(); |
| 1263 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1264 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1265 | } else { |
| 1266 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1267 | } |
| 1268 | } else { |
| 1269 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1270 | } |
| 1271 | } else { |
| 1272 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1273 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1274 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1275 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1276 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1277 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1278 | ar = (AsyncResult) msg.obj; |
| 1279 | request = (MainThreadRequest) ar.userObj; |
| 1280 | CellNetworkScanResult cellScanResult; |
| 1281 | if (ar.exception == null && ar.result != null) { |
| 1282 | cellScanResult = new CellNetworkScanResult( |
| 1283 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1284 | (List<OperatorInfo>) ar.result); |
| 1285 | } else { |
| 1286 | if (ar.result == null) { |
| 1287 | loge("getCellNetworkScanResults: Empty response"); |
| 1288 | } |
| 1289 | if (ar.exception != null) { |
| 1290 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1291 | } |
| 1292 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1293 | if (ar.exception instanceof CommandException) { |
| 1294 | CommandException.Error error = |
| 1295 | ((CommandException) (ar.exception)).getCommandError(); |
| 1296 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1297 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1298 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1299 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1300 | } |
| 1301 | } |
| 1302 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1303 | } |
| 1304 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1305 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1306 | break; |
| 1307 | |
| 1308 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1309 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1310 | ManualNetworkSelectionArgument selArg = |
| 1311 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1312 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1313 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1314 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1315 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1316 | break; |
| 1317 | |
| 1318 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1319 | ar = (AsyncResult) msg.obj; |
| 1320 | request = (MainThreadRequest) ar.userObj; |
| 1321 | if (ar.exception == null) { |
| 1322 | request.result = true; |
| 1323 | } else { |
| 1324 | request.result = false; |
| 1325 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1326 | } |
| 1327 | notifyRequester(request); |
| 1328 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1329 | break; |
| 1330 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1331 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1332 | request = (MainThreadRequest) msg.obj; |
| 1333 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1334 | if (defaultPhone != null) { |
| 1335 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1336 | } else { |
| 1337 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1338 | Bundle bundle = new Bundle(); |
| 1339 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1340 | new ModemActivityInfo(0, 0, 0, |
| 1341 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1342 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1343 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1344 | break; |
| 1345 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1346 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1347 | ar = (AsyncResult) msg.obj; |
| 1348 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1349 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1350 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1351 | ModemActivityInfo ret = null; |
| 1352 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1353 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1354 | // Update the last modem activity info and the result of the request. |
| 1355 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1356 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1357 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1358 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1359 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1360 | .getTransmitTimeMillis(); |
| 1361 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1362 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1363 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1364 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1365 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1366 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1367 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1368 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1369 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1370 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1371 | info.getReceiveTimeMillis() |
| 1372 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1373 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1374 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1375 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1376 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1377 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1378 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1379 | } else { |
| 1380 | if (ar.result == null) { |
| 1381 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1382 | error = TelephonyManager.ModemActivityInfoException |
| 1383 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1384 | } else if (ar.exception instanceof CommandException) { |
| 1385 | loge("queryModemActivityInfo: CommandException: " + |
| 1386 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1387 | error = TelephonyManager.ModemActivityInfoException |
| 1388 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1389 | } else { |
| 1390 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1391 | error = TelephonyManager.ModemActivityInfoException |
| 1392 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1393 | } |
| 1394 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1395 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1396 | if (ret != null) { |
| 1397 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1398 | } else { |
| 1399 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1400 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1401 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1402 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1403 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1404 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1405 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1406 | case CMD_SET_ALLOWED_CARRIERS: |
| 1407 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1408 | CarrierRestrictionRules argument = |
| 1409 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1410 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1411 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1412 | break; |
| 1413 | |
| 1414 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1415 | ar = (AsyncResult) msg.obj; |
| 1416 | request = (MainThreadRequest) ar.userObj; |
| 1417 | if (ar.exception == null && ar.result != null) { |
| 1418 | request.result = ar.result; |
| 1419 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1420 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1421 | if (ar.exception instanceof CommandException) { |
| 1422 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1423 | CommandException.Error error = |
| 1424 | ((CommandException) (ar.exception)).getCommandError(); |
| 1425 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1426 | request.result = |
| 1427 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1428 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1429 | } else { |
| 1430 | loge("setAllowedCarriers: Unknown exception"); |
| 1431 | } |
| 1432 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1433 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1434 | break; |
| 1435 | |
| 1436 | case CMD_GET_ALLOWED_CARRIERS: |
| 1437 | request = (MainThreadRequest) msg.obj; |
| 1438 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1439 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1440 | break; |
| 1441 | |
| 1442 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1443 | ar = (AsyncResult) msg.obj; |
| 1444 | request = (MainThreadRequest) ar.userObj; |
| 1445 | if (ar.exception == null && ar.result != null) { |
| 1446 | request.result = ar.result; |
| 1447 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1448 | request.result = new IllegalStateException( |
| 1449 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1450 | if (ar.result == null) { |
| 1451 | loge("getAllowedCarriers: Empty response"); |
| 1452 | } else if (ar.exception instanceof CommandException) { |
| 1453 | loge("getAllowedCarriers: CommandException: " + |
| 1454 | ar.exception); |
| 1455 | } else { |
| 1456 | loge("getAllowedCarriers: Unknown exception"); |
| 1457 | } |
| 1458 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1459 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1460 | break; |
| 1461 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1462 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1463 | ar = (AsyncResult) msg.obj; |
| 1464 | request = (MainThreadRequest) ar.userObj; |
| 1465 | if (ar.exception == null && ar.result != null) { |
| 1466 | request.result = ar.result; |
| 1467 | } else { |
| 1468 | request.result = new IllegalArgumentException( |
| 1469 | "Failed to retrieve Forbidden Plmns"); |
| 1470 | if (ar.result == null) { |
| 1471 | loge("getForbiddenPlmns: Empty response"); |
| 1472 | } else { |
| 1473 | loge("getForbiddenPlmns: Unknown exception"); |
| 1474 | } |
| 1475 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1476 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1477 | break; |
| 1478 | |
| 1479 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1480 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1481 | uiccPort = getUiccPortFromRequest(request); |
| 1482 | if (uiccPort == null) { |
| 1483 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1484 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1485 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1486 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1487 | break; |
| 1488 | } |
| 1489 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1490 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1491 | if (uiccApp == null) { |
| 1492 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1493 | + appType); |
| 1494 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1495 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1496 | break; |
| 1497 | } else { |
| 1498 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1499 | + " specified type -- " + appType); |
| 1500 | } |
| 1501 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1502 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1503 | onCompleted); |
| 1504 | break; |
| 1505 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1506 | case CMD_SWITCH_SLOTS: |
| 1507 | request = (MainThreadRequest) msg.obj; |
| 1508 | int[] physicalSlots = (int[]) request.argument; |
| 1509 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1510 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1511 | break; |
| 1512 | |
| 1513 | case EVENT_SWITCH_SLOTS_DONE: |
| 1514 | ar = (AsyncResult) msg.obj; |
| 1515 | request = (MainThreadRequest) ar.userObj; |
| 1516 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1517 | notifyRequester(request); |
| 1518 | break; |
| 1519 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1520 | request = (MainThreadRequest) msg.obj; |
| 1521 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1522 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1523 | break; |
| 1524 | |
| 1525 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1526 | ar = (AsyncResult) msg.obj; |
| 1527 | request = (MainThreadRequest) ar.userObj; |
| 1528 | if (ar.exception != null) { |
| 1529 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1530 | } else { |
| 1531 | int mode = ((int[]) ar.result)[0]; |
| 1532 | if (mode == 0) { |
| 1533 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1534 | } else { |
| 1535 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1536 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1537 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1538 | notifyRequester(request); |
| 1539 | break; |
| 1540 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1541 | request = (MainThreadRequest) msg.obj; |
| 1542 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1543 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1544 | break; |
| 1545 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1546 | ar = (AsyncResult) msg.obj; |
| 1547 | request = (MainThreadRequest) ar.userObj; |
| 1548 | if (ar.exception != null) { |
| 1549 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1550 | } else { |
| 1551 | request.result = ((int[]) ar.result)[0]; |
| 1552 | } |
| 1553 | notifyRequester(request); |
| 1554 | break; |
| 1555 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1556 | request = (MainThreadRequest) msg.obj; |
| 1557 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1558 | int mode = (int) request.argument; |
| 1559 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1560 | break; |
| 1561 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1562 | ar = (AsyncResult) msg.obj; |
| 1563 | request = (MainThreadRequest) ar.userObj; |
| 1564 | request.result = ar.exception == null; |
| 1565 | notifyRequester(request); |
| 1566 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1567 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1568 | request = (MainThreadRequest) msg.obj; |
| 1569 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1570 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1571 | break; |
| 1572 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1573 | ar = (AsyncResult) msg.obj; |
| 1574 | request = (MainThreadRequest) ar.userObj; |
| 1575 | if (ar.exception != null) { |
| 1576 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1577 | } else { |
| 1578 | request.result = ((int[]) ar.result)[0]; |
| 1579 | } |
| 1580 | notifyRequester(request); |
| 1581 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1582 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1583 | request = (MainThreadRequest) msg.obj; |
| 1584 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1585 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1586 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1587 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1588 | break; |
| 1589 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1590 | ar = (AsyncResult) msg.obj; |
| 1591 | request = (MainThreadRequest) ar.userObj; |
| 1592 | request.result = ar.exception == null; |
| 1593 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1594 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1595 | case CMD_GET_ALL_CELL_INFO: |
| 1596 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1597 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1598 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1599 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1600 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1601 | ar = (AsyncResult) msg.obj; |
| 1602 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1603 | // If a timeout occurs, the response will be null |
| 1604 | request.result = (ar.exception == null && ar.result != null) |
| 1605 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1606 | synchronized (request) { |
| 1607 | request.notifyAll(); |
| 1608 | } |
| 1609 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1610 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1611 | request = (MainThreadRequest) msg.obj; |
| 1612 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1613 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1614 | break; |
| 1615 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1616 | ar = (AsyncResult) msg.obj; |
| 1617 | request = (MainThreadRequest) ar.userObj; |
| 1618 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1619 | try { |
| 1620 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1621 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1622 | cb.onError( |
| 1623 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1624 | ar.exception.getClass().getName(), |
| 1625 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1626 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1627 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1628 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1629 | } else { |
| 1630 | // use the result as returned |
| 1631 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1632 | } |
| 1633 | } catch (RemoteException re) { |
| 1634 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1635 | } |
| 1636 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1637 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1638 | request = (MainThreadRequest) msg.obj; |
| 1639 | WorkSource ws = (WorkSource) request.argument; |
| 1640 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1641 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1642 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1643 | } |
| 1644 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1645 | ar = (AsyncResult) msg.obj; |
| 1646 | request = (MainThreadRequest) ar.userObj; |
| 1647 | if (ar.exception == null) { |
| 1648 | request.result = ar.result; |
| 1649 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1650 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1651 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1652 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1653 | } |
| 1654 | |
| 1655 | synchronized (request) { |
| 1656 | request.notifyAll(); |
| 1657 | } |
| 1658 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1659 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1660 | case CMD_MODEM_REBOOT: |
| 1661 | request = (MainThreadRequest) msg.obj; |
| 1662 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1663 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1664 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1665 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1666 | handleNullReturnEvent(msg, "rebootModem"); |
| 1667 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1668 | case CMD_REQUEST_ENABLE_MODEM: |
| 1669 | request = (MainThreadRequest) msg.obj; |
| 1670 | boolean enable = (boolean) request.argument; |
| 1671 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1672 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1673 | PhoneConfigurationManager.getInstance() |
| 1674 | .enablePhone(request.phone, enable, onCompleted); |
| 1675 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1676 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1677 | ar = (AsyncResult) msg.obj; |
| 1678 | request = (MainThreadRequest) ar.userObj; |
| 1679 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1680 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1681 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1682 | if ((boolean) request.result) { |
| 1683 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1684 | updateModemStateMetrics(); |
| 1685 | } else { |
| 1686 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1687 | + ar.exception); |
| 1688 | } |
| 1689 | notifyRequester(request); |
| 1690 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1691 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1692 | case CMD_GET_MODEM_STATUS: |
| 1693 | request = (MainThreadRequest) msg.obj; |
| 1694 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1695 | PhoneConfigurationManager.getInstance() |
| 1696 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1697 | break; |
| 1698 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1699 | ar = (AsyncResult) msg.obj; |
| 1700 | request = (MainThreadRequest) ar.userObj; |
| 1701 | int id = request.phone.getPhoneId(); |
| 1702 | if (ar.exception == null && ar.result != null) { |
| 1703 | request.result = ar.result; |
| 1704 | //update the cache as modem status has changed |
| 1705 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1706 | (boolean) request.result); |
| 1707 | } else { |
| 1708 | // Return true if modem status cannot be retrieved. For most cases, |
| 1709 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1710 | // and disable modem are not supported. Modem is always on. |
| 1711 | // TODO: this should be fixed in R to support a third |
| 1712 | // status UNKNOWN b/131631629 |
| 1713 | request.result = true; |
| 1714 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1715 | + ar.exception); |
| 1716 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1717 | notifyRequester(request); |
| 1718 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1719 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1720 | request = (MainThreadRequest) msg.obj; |
| 1721 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1722 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1723 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1724 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1725 | break; |
| 1726 | } |
| 1727 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1728 | ar = (AsyncResult) msg.obj; |
| 1729 | request = (MainThreadRequest) ar.userObj; |
| 1730 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1731 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1732 | args.second.accept(ar.exception == null); |
| 1733 | notifyRequester(request); |
| 1734 | break; |
| 1735 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1736 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1737 | request = (MainThreadRequest) msg.obj; |
| 1738 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1739 | Phone phone = getPhoneFromRequest(request); |
| 1740 | if (phone != null) { |
| 1741 | phone.getSystemSelectionChannels(onCompleted); |
| 1742 | } else { |
| 1743 | loge("getSystemSelectionChannels: No phone object"); |
| 1744 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1745 | notifyRequester(request); |
| 1746 | } |
| 1747 | break; |
| 1748 | } |
| 1749 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1750 | ar = (AsyncResult) msg.obj; |
| 1751 | request = (MainThreadRequest) ar.userObj; |
| 1752 | if (ar.exception == null && ar.result != null) { |
| 1753 | request.result = ar.result; |
| 1754 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1755 | request.result = new IllegalStateException( |
| 1756 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1757 | if (ar.result == null) { |
| 1758 | loge("getSystemSelectionChannels: Empty response"); |
| 1759 | } else { |
| 1760 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1761 | } |
| 1762 | } |
| 1763 | notifyRequester(request); |
| 1764 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1765 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1766 | ar = (AsyncResult) msg.obj; |
| 1767 | request = (MainThreadRequest) ar.userObj; |
| 1768 | if (ar.exception == null && ar.result != null) { |
| 1769 | request.result = ar.result; |
| 1770 | } else { |
| 1771 | request.result = -1; |
| 1772 | loge("Failed to set Forbidden Plmns"); |
| 1773 | if (ar.result == null) { |
| 1774 | loge("setForbidenPlmns: Empty response"); |
| 1775 | } else if (ar.exception != null) { |
| 1776 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1777 | request.result = -1; |
| 1778 | } else { |
| 1779 | loge("setForbiddenPlmns: Unknown exception"); |
| 1780 | } |
| 1781 | } |
| 1782 | notifyRequester(request); |
| 1783 | break; |
| 1784 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1785 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1786 | uiccPort = getUiccPortFromRequest(request); |
| 1787 | if (uiccPort == null) { |
| 1788 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1789 | request.result = -1; |
| 1790 | notifyRequester(request); |
| 1791 | break; |
| 1792 | } |
| 1793 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1794 | (Pair<Integer, List<String>>) request.argument; |
| 1795 | appType = setFplmnsArgs.first; |
| 1796 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1797 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1798 | if (uiccApp == null) { |
| 1799 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1800 | request.result = -1; |
| 1801 | loge("Failed to get UICC App"); |
| 1802 | notifyRequester(request); |
| 1803 | } else { |
| 1804 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1805 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1806 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1807 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1808 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1809 | case CMD_ERASE_MODEM_CONFIG: |
| 1810 | request = (MainThreadRequest) msg.obj; |
| 1811 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1812 | defaultPhone.eraseModemConfig(onCompleted); |
| 1813 | break; |
| 1814 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1815 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1816 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1817 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1818 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1819 | request = (MainThreadRequest) msg.obj; |
| 1820 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1821 | notifyRequester(request); |
| 1822 | break; |
| 1823 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1824 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1825 | request = (MainThreadRequest) msg.obj; |
| 1826 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1827 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1828 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1829 | changed.first, changed.second, onCompleted); |
| 1830 | break; |
| 1831 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1832 | ar = (AsyncResult) msg.obj; |
| 1833 | request = (MainThreadRequest) ar.userObj; |
| 1834 | if (ar.exception == null) { |
| 1835 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1836 | // If the operation is successful, update the PIN storage |
| 1837 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1838 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1839 | UiccController.getInstance().getPinStorage() |
| 1840 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1841 | } else { |
| 1842 | request.result = msg.arg1; |
| 1843 | } |
| 1844 | notifyRequester(request); |
| 1845 | break; |
| 1846 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1847 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1848 | request = (MainThreadRequest) msg.obj; |
| 1849 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1850 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1851 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1852 | enabled.first, enabled.second, onCompleted); |
| 1853 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1854 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1855 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1856 | ar = (AsyncResult) msg.obj; |
| 1857 | request = (MainThreadRequest) ar.userObj; |
| 1858 | if (ar.exception == null) { |
| 1859 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1860 | // If the operation is successful, update the PIN storage |
| 1861 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1862 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1863 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1864 | UiccController.getInstance().getPinStorage() |
| 1865 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1866 | } else { |
| 1867 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1868 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1869 | } else { |
| 1870 | request.result = msg.arg1; |
| 1871 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1872 | |
| 1873 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1874 | notifyRequester(request); |
| 1875 | break; |
| 1876 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1877 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1878 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1879 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1880 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1881 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1882 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1883 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1884 | |
| 1885 | case CMD_SET_DATA_THROTTLING: { |
| 1886 | request = (MainThreadRequest) msg.obj; |
| 1887 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1888 | DataThrottlingRequest dataThrottlingRequest = |
| 1889 | (DataThrottlingRequest) request.argument; |
| 1890 | Phone phone = getPhoneFromRequest(request); |
| 1891 | if (phone != null) { |
| 1892 | phone.setDataThrottling(onCompleted, |
| 1893 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1894 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1895 | } else { |
| 1896 | loge("setDataThrottling: No phone object"); |
| 1897 | request.result = |
| 1898 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1899 | notifyRequester(request); |
| 1900 | } |
| 1901 | |
| 1902 | break; |
| 1903 | } |
| 1904 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1905 | ar = (AsyncResult) msg.obj; |
| 1906 | request = (MainThreadRequest) ar.userObj; |
| 1907 | |
| 1908 | if (ar.exception == null) { |
| 1909 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1910 | } else if (ar.exception instanceof CommandException) { |
| 1911 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1912 | CommandException.Error error = |
| 1913 | ((CommandException) (ar.exception)).getCommandError(); |
| 1914 | |
| 1915 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1916 | request.result = TelephonyManager |
| 1917 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1918 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1919 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 1920 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1921 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1922 | } else { |
| 1923 | request.result = |
| 1924 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1925 | } |
| 1926 | } else { |
| 1927 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1928 | } |
| 1929 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1930 | notifyRequester(request); |
| 1931 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1932 | |
| 1933 | case CMD_SET_SIM_POWER: { |
| 1934 | request = (MainThreadRequest) msg.obj; |
| 1935 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1936 | request = (MainThreadRequest) msg.obj; |
| 1937 | int stateToSet = |
| 1938 | ((Pair<Integer, IIntegerConsumer>) |
| 1939 | request.argument).first; |
| 1940 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1941 | break; |
| 1942 | } |
| 1943 | case EVENT_SET_SIM_POWER_DONE: { |
| 1944 | ar = (AsyncResult) msg.obj; |
| 1945 | request = (MainThreadRequest) ar.userObj; |
| 1946 | IIntegerConsumer callback = |
| 1947 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1948 | if (ar.exception != null) { |
| 1949 | loge("setSimPower exception: " + ar.exception); |
| 1950 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1951 | .RESULT_ERROR_UNKNOWN; |
| 1952 | if (ar.exception instanceof CommandException) { |
| 1953 | CommandException.Error error = |
| 1954 | ((CommandException) (ar.exception)).getCommandError(); |
| 1955 | if (error == CommandException.Error.SIM_ERR) { |
| 1956 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1957 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1958 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1959 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1960 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1961 | } else { |
| 1962 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1963 | } |
| 1964 | } |
| 1965 | try { |
| 1966 | callback.accept(errorCode); |
| 1967 | } catch (RemoteException e) { |
| 1968 | // Ignore if the remote process is no longer available to call back. |
| 1969 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1970 | } |
| 1971 | } else { |
| 1972 | try { |
| 1973 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 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 | } |
| 1979 | break; |
| 1980 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1981 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1982 | request = (MainThreadRequest) msg.obj; |
| 1983 | |
| 1984 | final Phone phone = getPhoneFromRequest(request); |
| 1985 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1986 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1987 | notifyRequester(request); |
| 1988 | break; |
| 1989 | } |
| 1990 | |
| 1991 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1992 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1993 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1994 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 1995 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1996 | request.subId, pair.first /*callingUid*/, |
| 1997 | pair.second /*request*/, onCompleted); |
| 1998 | break; |
| 1999 | } |
| 2000 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2001 | ar = (AsyncResult) msg.obj; |
| 2002 | request = (MainThreadRequest) ar.userObj; |
| 2003 | // request.result will be the exception of ar if present, true otherwise. |
| 2004 | // Be cautious not to leave result null which will wait() forever |
| 2005 | request.result = ar.exception != null ? ar.exception : true; |
| 2006 | notifyRequester(request); |
| 2007 | break; |
| 2008 | } |
| 2009 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2010 | request = (MainThreadRequest) msg.obj; |
| 2011 | |
| 2012 | Phone phone = getPhoneFromRequest(request); |
| 2013 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2014 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2015 | notifyRequester(request); |
| 2016 | break; |
| 2017 | } |
| 2018 | |
| 2019 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2020 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2021 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2022 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2023 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2024 | request.subId, pair.first /*callingUid*/, |
| 2025 | pair.second /*request*/, onCompleted); |
| 2026 | break; |
| 2027 | } |
| 2028 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2029 | ar = (AsyncResult) msg.obj; |
| 2030 | request = (MainThreadRequest) ar.userObj; |
| 2031 | request.result = ar.exception != null ? ar.exception : true; |
| 2032 | notifyRequester(request); |
| 2033 | break; |
| 2034 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2035 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2036 | case CMD_GET_SLICING_CONFIG: { |
| 2037 | request = (MainThreadRequest) msg.obj; |
| 2038 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2039 | request.phone.getSlicingConfig(onCompleted); |
| 2040 | break; |
| 2041 | } |
| 2042 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2043 | ar = (AsyncResult) msg.obj; |
| 2044 | request = (MainThreadRequest) ar.userObj; |
| 2045 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2046 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2047 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2048 | Bundle bundle = new Bundle(); |
| 2049 | int resultCode = 0; |
| 2050 | if (ar.exception != null) { |
| 2051 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2052 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2053 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2054 | } else if (ar.result == null) { |
| 2055 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2056 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2057 | } else { |
| 2058 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2059 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2060 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2061 | } |
| 2062 | |
| 2063 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2064 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2065 | } |
| 2066 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2067 | result.send(resultCode, bundle); |
| 2068 | notifyRequester(request); |
| 2069 | break; |
| 2070 | } |
| 2071 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2072 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2073 | request = (MainThreadRequest) msg.obj; |
| 2074 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2075 | UiccController.getInstance().getPinStorage() |
| 2076 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2077 | notifyRequester(request); |
| 2078 | break; |
| 2079 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2080 | default: |
| 2081 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2082 | break; |
| 2083 | } |
| 2084 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2085 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2086 | private void notifyRequester(MainThreadRequest request) { |
| 2087 | synchronized (request) { |
| 2088 | request.notifyAll(); |
| 2089 | } |
| 2090 | } |
| 2091 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2092 | private void handleNullReturnEvent(Message msg, String command) { |
| 2093 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2094 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2095 | if (ar.exception == null) { |
| 2096 | request.result = true; |
| 2097 | } else { |
| 2098 | request.result = false; |
| 2099 | if (ar.exception instanceof CommandException) { |
| 2100 | loge(command + ": CommandException: " + ar.exception); |
| 2101 | } else { |
| 2102 | loge(command + ": Unknown exception"); |
| 2103 | } |
| 2104 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2105 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2106 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2107 | } |
| 2108 | |
| 2109 | /** |
| 2110 | * Posts the specified command to be executed on the main thread, |
| 2111 | * waits for the request to complete, and returns the result. |
| 2112 | * @see #sendRequestAsync |
| 2113 | */ |
| 2114 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2115 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2116 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2117 | } |
| 2118 | |
| 2119 | /** |
| 2120 | * Posts the specified command to be executed on the main thread, |
| 2121 | * waits for the request to complete, and returns the result. |
| 2122 | * @see #sendRequestAsync |
| 2123 | */ |
| 2124 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2125 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2126 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2127 | } |
| 2128 | |
| 2129 | /** |
| 2130 | * Posts the specified command to be executed on the main thread, |
| 2131 | * waits for the request to complete, and returns the result. |
| 2132 | * @see #sendRequestAsync |
| 2133 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2134 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2135 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2136 | } |
| 2137 | |
| 2138 | /** |
| 2139 | * Posts the specified command to be executed on the main thread, |
| 2140 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2141 | * if not timeout or null otherwise. |
| 2142 | * @see #sendRequestAsync |
| 2143 | */ |
| 2144 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2145 | long timeoutInMs) { |
| 2146 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2147 | } |
| 2148 | |
| 2149 | /** |
| 2150 | * Posts the specified command to be executed on the main thread, |
| 2151 | * waits for the request to complete, and returns the result. |
| 2152 | * @see #sendRequestAsync |
| 2153 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2154 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2155 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2156 | } |
| 2157 | |
| 2158 | /** |
| 2159 | * Posts the specified command to be executed on the main thread, |
| 2160 | * waits for the request to complete, and returns the result. |
| 2161 | * @see #sendRequestAsync |
| 2162 | */ |
| 2163 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2164 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2165 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2166 | } |
| 2167 | |
| 2168 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2169 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2170 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2171 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2172 | * @see #sendRequestAsync |
| 2173 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2174 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2175 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2176 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2177 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2178 | } |
| 2179 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2180 | MainThreadRequest request = null; |
| 2181 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2182 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2183 | } else if (phone != null) { |
| 2184 | request = new MainThreadRequest(argument, phone, workSource); |
| 2185 | } else { |
| 2186 | request = new MainThreadRequest(argument, subId, workSource); |
| 2187 | } |
| 2188 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2189 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2190 | msg.sendToTarget(); |
| 2191 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2192 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2193 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2194 | if (timeoutInMs >= 0) { |
| 2195 | // Wait for at least timeoutInMs before returning null request result |
| 2196 | long now = SystemClock.elapsedRealtime(); |
| 2197 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2198 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2199 | try { |
| 2200 | request.wait(deadline - now); |
| 2201 | } catch (InterruptedException e) { |
| 2202 | // Do nothing, go back and check if request is completed or timeout |
| 2203 | } finally { |
| 2204 | now = SystemClock.elapsedRealtime(); |
| 2205 | } |
| 2206 | } |
| 2207 | } else { |
| 2208 | // Wait for the request to complete |
| 2209 | while (request.result == null) { |
| 2210 | try { |
| 2211 | request.wait(); |
| 2212 | } catch (InterruptedException e) { |
| 2213 | // Do nothing, go back and wait until the request is complete |
| 2214 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2215 | } |
| 2216 | } |
| 2217 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2218 | if (request.result == null) { |
| 2219 | Log.wtf(LOG_TAG, |
| 2220 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2221 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2222 | return request.result; |
| 2223 | } |
| 2224 | |
| 2225 | /** |
| 2226 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2227 | * Posts the specified command to be executed on the main thread, and |
| 2228 | * returns immediately. |
| 2229 | * @see #sendRequest |
| 2230 | */ |
| 2231 | private void sendRequestAsync(int command) { |
| 2232 | mMainThreadHandler.sendEmptyMessage(command); |
| 2233 | } |
| 2234 | |
| 2235 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2236 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2237 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2238 | */ |
| 2239 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2240 | sendRequestAsync(command, argument, null, null); |
| 2241 | } |
| 2242 | |
| 2243 | /** |
| 2244 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2245 | * @see {@link #sendRequest(int,Object)} |
| 2246 | */ |
| 2247 | private void sendRequestAsync( |
| 2248 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2249 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2250 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2251 | msg.sendToTarget(); |
| 2252 | } |
| 2253 | |
| 2254 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2255 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2256 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2257 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2258 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2259 | synchronized (PhoneInterfaceManager.class) { |
| 2260 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2261 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2262 | } else { |
| 2263 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2264 | } |
| 2265 | return sInstance; |
| 2266 | } |
| 2267 | } |
| 2268 | |
| 2269 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2270 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2271 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2272 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2273 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2274 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2275 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2276 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2277 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2278 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2279 | mTelephonySharedPreferences = |
| 2280 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2281 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2282 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2283 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2284 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2285 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2286 | publish(); |
| 2287 | } |
| 2288 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2289 | private Phone getDefaultPhone() { |
| 2290 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2291 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2292 | } |
| 2293 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2294 | private void publish() { |
| 2295 | if (DBG) log("publish: " + this); |
| 2296 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2297 | TelephonyFrameworkInitializer |
| 2298 | .getTelephonyServiceManager() |
| 2299 | .getTelephonyServiceRegisterer() |
| 2300 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2301 | } |
| 2302 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2303 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2304 | if (request.phone != null) { |
| 2305 | return request.phone; |
| 2306 | } else { |
| 2307 | return getPhoneFromSubId(request.subId); |
| 2308 | } |
| 2309 | } |
| 2310 | |
| 2311 | private Phone getPhoneFromSubId(int subId) { |
| 2312 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2313 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2314 | } |
| 2315 | |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2316 | private UiccPort getUiccPortFromRequest(MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2317 | Phone phone = getPhoneFromRequest(request); |
| 2318 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2319 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2320 | } |
| 2321 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2322 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2323 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2324 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2325 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2326 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2327 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2328 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2329 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2330 | } |
| 2331 | |
| 2332 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2333 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2334 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2335 | } |
| 2336 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2337 | private boolean isImsAvailableOnDevice() { |
| 2338 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2339 | if (pm == null) { |
| 2340 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2341 | // so do not throw error and allow. |
| 2342 | return true; |
| 2343 | } |
| 2344 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2345 | } |
| 2346 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2347 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2348 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2349 | } |
| 2350 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2351 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2352 | if (DBG) log("dial: " + number); |
| 2353 | // No permission check needed here: This is just a wrapper around the |
| 2354 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2355 | // the UI before it does anything. |
| 2356 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2357 | final long identity = Binder.clearCallingIdentity(); |
| 2358 | try { |
| 2359 | String url = createTelUrl(number); |
| 2360 | if (url == null) { |
| 2361 | return; |
| 2362 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2363 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2364 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2365 | PhoneConstants.State state = mCM.getState(subId); |
| 2366 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2367 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2368 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2369 | mApp.startActivity(intent); |
| 2370 | } |
| 2371 | } finally { |
| 2372 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2373 | } |
| 2374 | } |
| 2375 | |
| 2376 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2377 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2378 | } |
| 2379 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2380 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2381 | if (DBG) log("call: " + number); |
| 2382 | |
| 2383 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2384 | // need to do a permission check since we're calling startActivity() |
| 2385 | // from the context of the phone app. |
| 2386 | enforceCallPermission(); |
| 2387 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2388 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2389 | != AppOpsManager.MODE_ALLOWED) { |
| 2390 | return; |
| 2391 | } |
| 2392 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2393 | final long identity = Binder.clearCallingIdentity(); |
| 2394 | try { |
| 2395 | String url = createTelUrl(number); |
| 2396 | if (url == null) { |
| 2397 | return; |
| 2398 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2399 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2400 | boolean isValid = false; |
| 2401 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2402 | if (slist != null) { |
| 2403 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2404 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2405 | isValid = true; |
| 2406 | break; |
| 2407 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2408 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2409 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2410 | if (!isValid) { |
| 2411 | return; |
| 2412 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2413 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2414 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2415 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2416 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2417 | mApp.startActivity(intent); |
| 2418 | } finally { |
| 2419 | Binder.restoreCallingIdentity(identity); |
| 2420 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2421 | } |
| 2422 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2423 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2424 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2425 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2426 | } |
| 2427 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2428 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2429 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2430 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2431 | } |
| 2432 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2433 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2434 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2435 | |
| 2436 | final long identity = Binder.clearCallingIdentity(); |
| 2437 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2438 | Phone phone = getPhone(subId); |
| 2439 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2440 | checkSimPin.start(); |
| 2441 | return checkSimPin.unlockSim(null, pin); |
| 2442 | } finally { |
| 2443 | Binder.restoreCallingIdentity(identity); |
| 2444 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2445 | } |
| 2446 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2447 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2448 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2449 | |
| 2450 | final long identity = Binder.clearCallingIdentity(); |
| 2451 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2452 | Phone phone = getPhone(subId); |
| 2453 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2454 | checkSimPuk.start(); |
| 2455 | return checkSimPuk.unlockSim(puk, pin); |
| 2456 | } finally { |
| 2457 | Binder.restoreCallingIdentity(identity); |
| 2458 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2459 | } |
| 2460 | |
| 2461 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2462 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2463 | * a synchronous one. |
| 2464 | */ |
| 2465 | private static class UnlockSim extends Thread { |
| 2466 | |
| 2467 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2468 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2469 | |
| 2470 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2471 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2472 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2473 | |
| 2474 | // For replies from SimCard interface |
| 2475 | private Handler mHandler; |
| 2476 | |
| 2477 | // For async handler to identify request type |
| 2478 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2479 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2480 | UnlockSim(int phoneId, IccCard simCard) { |
| 2481 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2482 | mSimCard = simCard; |
| 2483 | } |
| 2484 | |
| 2485 | @Override |
| 2486 | public void run() { |
| 2487 | Looper.prepare(); |
| 2488 | synchronized (UnlockSim.this) { |
| 2489 | mHandler = new Handler() { |
| 2490 | @Override |
| 2491 | public void handleMessage(Message msg) { |
| 2492 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2493 | switch (msg.what) { |
| 2494 | case SUPPLY_PIN_COMPLETE: |
| 2495 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2496 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2497 | mRetryCount = msg.arg1; |
| 2498 | if (ar.exception != null) { |
| 2499 | if (ar.exception instanceof CommandException && |
| 2500 | ((CommandException)(ar.exception)).getCommandError() |
| 2501 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2502 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2503 | } //When UiccCardApp dispose,handle message and return exception |
| 2504 | else if (ar.exception instanceof CommandException && |
| 2505 | ((CommandException) (ar.exception)).getCommandError() |
| 2506 | == CommandException.Error.ABORTED) { |
| 2507 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2508 | } else { |
| 2509 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2510 | } |
| 2511 | } else { |
| 2512 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2513 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2514 | mDone = true; |
| 2515 | UnlockSim.this.notifyAll(); |
| 2516 | } |
| 2517 | break; |
| 2518 | } |
| 2519 | } |
| 2520 | }; |
| 2521 | UnlockSim.this.notifyAll(); |
| 2522 | } |
| 2523 | Looper.loop(); |
| 2524 | } |
| 2525 | |
| 2526 | /* |
| 2527 | * Use PIN or PUK to unlock SIM card |
| 2528 | * |
| 2529 | * If PUK is null, unlock SIM card with PIN |
| 2530 | * |
| 2531 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2532 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2533 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2534 | |
| 2535 | while (mHandler == null) { |
| 2536 | try { |
| 2537 | wait(); |
| 2538 | } catch (InterruptedException e) { |
| 2539 | Thread.currentThread().interrupt(); |
| 2540 | } |
| 2541 | } |
| 2542 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2543 | |
| 2544 | if (puk == null) { |
| 2545 | mSimCard.supplyPin(pin, callback); |
| 2546 | } else { |
| 2547 | mSimCard.supplyPuk(puk, pin, callback); |
| 2548 | } |
| 2549 | |
| 2550 | while (!mDone) { |
| 2551 | try { |
| 2552 | Log.d(LOG_TAG, "wait for done"); |
| 2553 | wait(); |
| 2554 | } catch (InterruptedException e) { |
| 2555 | // Restore the interrupted status |
| 2556 | Thread.currentThread().interrupt(); |
| 2557 | } |
| 2558 | } |
| 2559 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2560 | int[] resultArray = new int[2]; |
| 2561 | resultArray[0] = mResult; |
| 2562 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2563 | |
| 2564 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2565 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2566 | } |
| 2567 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2568 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2569 | } |
| 2570 | } |
| 2571 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2572 | /** |
| 2573 | * This method has been removed due to privacy and stability concerns. |
| 2574 | */ |
| 2575 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2576 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2577 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2578 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2579 | } |
| 2580 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2581 | @Override |
| 2582 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2583 | mApp.getSystemService(AppOpsManager.class) |
| 2584 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2585 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2586 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2587 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2588 | // Callers targeting S have no business invoking this method. |
| 2589 | return; |
| 2590 | } |
| 2591 | |
| 2592 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2593 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2594 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2595 | .setCallingPackage(callingPackage) |
| 2596 | .setCallingFeatureId(null) |
| 2597 | .setCallingPid(Binder.getCallingPid()) |
| 2598 | .setCallingUid(Binder.getCallingUid()) |
| 2599 | .setMethod("updateServiceLocation") |
| 2600 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2601 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2602 | .build()); |
| 2603 | // Apps that lack location permission have no business calling this method; |
| 2604 | // however, because no permission was declared in the public API, denials must |
| 2605 | // all be "soft". |
| 2606 | switch (locationResult) { |
| 2607 | case DENIED_HARD: /* fall through */ |
| 2608 | case DENIED_SOFT: |
| 2609 | return; |
| 2610 | } |
| 2611 | |
| 2612 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2613 | final long identity = Binder.clearCallingIdentity(); |
| 2614 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2615 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2616 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2617 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2618 | } |
| 2619 | } finally { |
| 2620 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2621 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2622 | } |
| 2623 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2624 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2625 | @Override |
| 2626 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2627 | return isRadioOnWithFeature(callingPackage, null); |
| 2628 | } |
| 2629 | |
| 2630 | |
| 2631 | @Override |
| 2632 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2633 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2634 | callingFeatureId); |
| 2635 | } |
| 2636 | |
| 2637 | @Deprecated |
| 2638 | @Override |
| 2639 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2640 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2641 | } |
| 2642 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2643 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2644 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2645 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2646 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2647 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2648 | return false; |
| 2649 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2650 | |
| 2651 | final long identity = Binder.clearCallingIdentity(); |
| 2652 | try { |
| 2653 | return isRadioOnForSubscriber(subId); |
| 2654 | } finally { |
| 2655 | Binder.restoreCallingIdentity(identity); |
| 2656 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2657 | } |
| 2658 | |
| 2659 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2660 | final long identity = Binder.clearCallingIdentity(); |
| 2661 | try { |
| 2662 | final Phone phone = getPhone(subId); |
| 2663 | if (phone != null) { |
| 2664 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2665 | } else { |
| 2666 | return false; |
| 2667 | } |
| 2668 | } finally { |
| 2669 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2670 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2671 | } |
| 2672 | |
| 2673 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2674 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2675 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2676 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2677 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2678 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2679 | |
| 2680 | final long identity = Binder.clearCallingIdentity(); |
| 2681 | try { |
| 2682 | final Phone phone = getPhone(subId); |
| 2683 | if (phone != null) { |
| 2684 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2685 | } |
| 2686 | } finally { |
| 2687 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2688 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2689 | } |
| 2690 | |
| 2691 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2692 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2693 | } |
| 2694 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2695 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2696 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2697 | |
| 2698 | final long identity = Binder.clearCallingIdentity(); |
| 2699 | try { |
| 2700 | final Phone phone = getPhone(subId); |
| 2701 | if (phone == null) { |
| 2702 | return false; |
| 2703 | } |
| 2704 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2705 | toggleRadioOnOffForSubscriber(subId); |
| 2706 | } |
| 2707 | return true; |
| 2708 | } finally { |
| 2709 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2710 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2711 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2712 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2713 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2714 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2715 | /* |
| 2716 | * If any of the Radios are available, it will need to be |
| 2717 | * shutdown. So return true if any Radio is available. |
| 2718 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2719 | final long identity = Binder.clearCallingIdentity(); |
| 2720 | try { |
| 2721 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2722 | Phone phone = PhoneFactory.getPhone(i); |
| 2723 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2724 | } |
| 2725 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2726 | return false; |
| 2727 | } finally { |
| 2728 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2729 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2730 | } |
| 2731 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2732 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2733 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2734 | enforceModifyPermission(); |
| 2735 | |
| 2736 | final long identity = Binder.clearCallingIdentity(); |
| 2737 | try { |
| 2738 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2739 | logv("Shutting down Phone " + i); |
| 2740 | shutdownRadioUsingPhoneId(i); |
| 2741 | } |
| 2742 | } finally { |
| 2743 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2744 | } |
| 2745 | } |
| 2746 | |
| 2747 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2748 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2749 | if (phone != null && phone.isRadioAvailable()) { |
| 2750 | phone.shutdownRadio(); |
| 2751 | } |
| 2752 | } |
| 2753 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2754 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2755 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2756 | |
| 2757 | final long identity = Binder.clearCallingIdentity(); |
| 2758 | try { |
| 2759 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2760 | if (defaultPhone != null) { |
| 2761 | defaultPhone.setRadioPower(turnOn); |
| 2762 | return true; |
| 2763 | } else { |
| 2764 | loge("There's no default phone."); |
| 2765 | return false; |
| 2766 | } |
| 2767 | } finally { |
| 2768 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2769 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2770 | } |
| 2771 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2772 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2773 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2774 | |
| 2775 | final long identity = Binder.clearCallingIdentity(); |
| 2776 | try { |
| 2777 | final Phone phone = getPhone(subId); |
| 2778 | if (phone != null) { |
| 2779 | phone.setRadioPower(turnOn); |
| 2780 | return true; |
| 2781 | } else { |
| 2782 | return false; |
| 2783 | } |
| 2784 | } finally { |
| 2785 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2786 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2787 | } |
| 2788 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2789 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2790 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2791 | public boolean enableDataConnectivity() { |
| 2792 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2793 | |
| 2794 | final long identity = Binder.clearCallingIdentity(); |
| 2795 | try { |
| 2796 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2797 | final Phone phone = getPhone(subId); |
| 2798 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2799 | phone.getDataEnabledSettings().setDataEnabled( |
| 2800 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2801 | return true; |
| 2802 | } else { |
| 2803 | return false; |
| 2804 | } |
| 2805 | } finally { |
| 2806 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2807 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2808 | } |
| 2809 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2810 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2811 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2812 | public boolean disableDataConnectivity() { |
| 2813 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2814 | |
| 2815 | final long identity = Binder.clearCallingIdentity(); |
| 2816 | try { |
| 2817 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2818 | final Phone phone = getPhone(subId); |
| 2819 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2820 | phone.getDataEnabledSettings().setDataEnabled( |
| 2821 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2822 | return true; |
| 2823 | } else { |
| 2824 | return false; |
| 2825 | } |
| 2826 | } finally { |
| 2827 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2828 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2829 | } |
| 2830 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2831 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2832 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2833 | final long identity = Binder.clearCallingIdentity(); |
| 2834 | try { |
| 2835 | final Phone phone = getPhone(subId); |
| 2836 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2837 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2838 | } else { |
| 2839 | return false; |
| 2840 | } |
| 2841 | } finally { |
| 2842 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2843 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2844 | } |
| 2845 | |
| 2846 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2847 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2848 | } |
| 2849 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2850 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2851 | enforceCallPermission(); |
| 2852 | |
| 2853 | final long identity = Binder.clearCallingIdentity(); |
| 2854 | try { |
| 2855 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2856 | return; |
| 2857 | } |
| 2858 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2859 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2860 | } finally { |
| 2861 | Binder.restoreCallingIdentity(identity); |
| 2862 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2863 | }; |
| 2864 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2865 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2866 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2867 | |
| 2868 | final long identity = Binder.clearCallingIdentity(); |
| 2869 | try { |
| 2870 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2871 | return false; |
| 2872 | } |
| 2873 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2874 | } finally { |
| 2875 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2876 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2877 | } |
| 2878 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2879 | /** |
| 2880 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 2881 | * tag on getCallState Binder call. |
| 2882 | */ |
| 2883 | @Deprecated |
| 2884 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2885 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2886 | if (CompatChanges.isChangeEnabled( |
| 2887 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2888 | Binder.getCallingUid())) { |
| 2889 | // Do not allow this API to be called on API version 31+, it should only be |
| 2890 | // called on old apps using this Binder call directly. |
| 2891 | throw new SecurityException("This method can only be used for applications " |
| 2892 | + "targeting API version 30 or less."); |
| 2893 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2894 | final long identity = Binder.clearCallingIdentity(); |
| 2895 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2896 | Phone phone = getPhone(getDefaultSubscription()); |
| 2897 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2898 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2899 | } finally { |
| 2900 | Binder.restoreCallingIdentity(identity); |
| 2901 | } |
| 2902 | } |
| 2903 | |
| 2904 | @Override |
| 2905 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 2906 | if (CompatChanges.isChangeEnabled( |
| 2907 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2908 | Binder.getCallingUid())) { |
| 2909 | // Check READ_PHONE_STATE for API version 31+ |
| 2910 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2911 | featureId, "getCallStateForSubscription")) { |
| 2912 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 2913 | + "targeting API level 31+."); |
| 2914 | } |
| 2915 | } |
| 2916 | final long identity = Binder.clearCallingIdentity(); |
| 2917 | try { |
| 2918 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2919 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2920 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2921 | } finally { |
| 2922 | Binder.restoreCallingIdentity(identity); |
| 2923 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2924 | } |
| 2925 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2926 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2927 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2928 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2929 | } |
| 2930 | |
| 2931 | @Override |
| 2932 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2933 | final long identity = Binder.clearCallingIdentity(); |
| 2934 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2935 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2936 | if (phone != null) { |
| 2937 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2938 | } else { |
| 2939 | return PhoneConstantConversions.convertDataState( |
| 2940 | PhoneConstants.DataState.DISCONNECTED); |
| 2941 | } |
| 2942 | } finally { |
| 2943 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2944 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2945 | } |
| 2946 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2947 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2948 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2949 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2950 | } |
| 2951 | |
| 2952 | @Override |
| 2953 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2954 | final long identity = Binder.clearCallingIdentity(); |
| 2955 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2956 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2957 | if (phone != null) { |
| 2958 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2959 | } else { |
| 2960 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2961 | } |
| 2962 | } finally { |
| 2963 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2964 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2965 | } |
| 2966 | |
| 2967 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2968 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2969 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2970 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2971 | |
| 2972 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2973 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2974 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2975 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2976 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2977 | .setCallingPid(Binder.getCallingPid()) |
| 2978 | .setCallingUid(Binder.getCallingUid()) |
| 2979 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2980 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2981 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2982 | .build()); |
| 2983 | switch (locationResult) { |
| 2984 | case DENIED_HARD: |
| 2985 | throw new SecurityException("Not allowed to access cell location"); |
| 2986 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2987 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2988 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2989 | } |
| 2990 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2991 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2992 | final long identity = Binder.clearCallingIdentity(); |
| 2993 | try { |
| 2994 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2995 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2996 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2997 | } finally { |
| 2998 | Binder.restoreCallingIdentity(identity); |
| 2999 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3000 | } |
| 3001 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3002 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3003 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3004 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3005 | // registered cell info, so return a NULL country instead. |
| 3006 | final long identity = Binder.clearCallingIdentity(); |
| 3007 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3008 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3009 | // Get default phone in this case. |
| 3010 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3011 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3012 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3013 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3014 | if (phone == null) return ""; |
| 3015 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3016 | if (sst == null) return ""; |
| 3017 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3018 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3019 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3020 | } finally { |
| 3021 | Binder.restoreCallingIdentity(identity); |
| 3022 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3023 | } |
| 3024 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3025 | /** |
| 3026 | * This method was removed due to potential issues caused by performing partial |
| 3027 | * updates of service state, and lack of a credible use case. |
| 3028 | * |
| 3029 | * This has the ability to break the telephony implementation by disabling notification of |
| 3030 | * changes in device connectivity. DO NOT USE THIS! |
| 3031 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3032 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3033 | public void enableLocationUpdates() { |
| 3034 | mApp.enforceCallingOrSelfPermission( |
| 3035 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3036 | } |
| 3037 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3038 | /** |
| 3039 | * This method was removed due to potential issues caused by performing partial |
| 3040 | * updates of service state, and lack of a credible use case. |
| 3041 | * |
| 3042 | * This has the ability to break the telephony implementation by disabling notification of |
| 3043 | * changes in device connectivity. DO NOT USE THIS! |
| 3044 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3045 | @Override |
| 3046 | public void disableLocationUpdates() { |
| 3047 | mApp.enforceCallingOrSelfPermission( |
| 3048 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3049 | } |
| 3050 | |
| 3051 | @Override |
| 3052 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3053 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3054 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3055 | try { |
| 3056 | mApp.getSystemService(AppOpsManager.class) |
| 3057 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3058 | } catch (SecurityException e) { |
| 3059 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3060 | throw e; |
| 3061 | } |
| 3062 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3063 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3064 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3065 | throw new SecurityException( |
| 3066 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3067 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3068 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3069 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3070 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3071 | return null; |
| 3072 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3073 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3074 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3075 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3076 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3077 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3078 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3079 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3080 | for (CellInfo ci : info) { |
| 3081 | if (ci instanceof CellInfoGsm) { |
| 3082 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3083 | } else if (ci instanceof CellInfoWcdma) { |
| 3084 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3085 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3086 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3087 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3088 | } |
| 3089 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3090 | private List<CellInfo> getCachedCellInfo() { |
| 3091 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3092 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3093 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3094 | if (info != null) cellInfos.addAll(info); |
| 3095 | } |
| 3096 | return cellInfos; |
| 3097 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3098 | |
| 3099 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3100 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3101 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3102 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3103 | |
| 3104 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3105 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3106 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3107 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3108 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3109 | .setCallingPid(Binder.getCallingPid()) |
| 3110 | .setCallingUid(Binder.getCallingUid()) |
| 3111 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3112 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3113 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3114 | .build()); |
| 3115 | switch (locationResult) { |
| 3116 | case DENIED_HARD: |
| 3117 | throw new SecurityException("Not allowed to access cell info"); |
| 3118 | case DENIED_SOFT: |
| 3119 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3120 | } |
| 3121 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3122 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3123 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3124 | return getCachedCellInfo(); |
| 3125 | } |
| 3126 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3127 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3128 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3129 | final long identity = Binder.clearCallingIdentity(); |
| 3130 | try { |
| 3131 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3132 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3133 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3134 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3135 | if (info != null) cellInfos.addAll(info); |
| 3136 | } |
| 3137 | return cellInfos; |
| 3138 | } finally { |
| 3139 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3140 | } |
| 3141 | } |
| 3142 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3143 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3144 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3145 | String callingFeatureId) { |
| 3146 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3147 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3148 | } |
| 3149 | |
| 3150 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3151 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3152 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3153 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3154 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3155 | } |
| 3156 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3157 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3158 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3159 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3160 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3161 | |
| 3162 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3163 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3164 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3165 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3166 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3167 | .setCallingPid(Binder.getCallingPid()) |
| 3168 | .setCallingUid(Binder.getCallingUid()) |
| 3169 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3170 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3171 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3172 | .build()); |
| 3173 | switch (locationResult) { |
| 3174 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3175 | if (TelephonyPermissions |
| 3176 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3177 | // Safetynet logging for b/154934934 |
| 3178 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3179 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3180 | throw new SecurityException("Not allowed to access cell info"); |
| 3181 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3182 | if (TelephonyPermissions |
| 3183 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3184 | // Safetynet logging for b/154934934 |
| 3185 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3186 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3187 | try { |
| 3188 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3189 | } catch (RemoteException re) { |
| 3190 | // Drop without consequences |
| 3191 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3192 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3193 | } |
| 3194 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3195 | |
| 3196 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3197 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3198 | |
| 3199 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3200 | } |
| 3201 | |
| 3202 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3203 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3204 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3205 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3206 | |
| 3207 | final long identity = Binder.clearCallingIdentity(); |
| 3208 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3209 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3210 | } finally { |
| 3211 | Binder.restoreCallingIdentity(identity); |
| 3212 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3213 | } |
| 3214 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3215 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3216 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3217 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3218 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3219 | return null; |
| 3220 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3221 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3222 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3223 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3224 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3225 | return null; |
| 3226 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3227 | |
| 3228 | final long identity = Binder.clearCallingIdentity(); |
| 3229 | try { |
| 3230 | return phone.getImei(); |
| 3231 | } finally { |
| 3232 | Binder.restoreCallingIdentity(identity); |
| 3233 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3234 | } |
| 3235 | |
| 3236 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3237 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3238 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3239 | String tac = null; |
| 3240 | if (phone != null) { |
| 3241 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3242 | try { |
| 3243 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3244 | } catch (IndexOutOfBoundsException e) { |
| 3245 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3246 | return null; |
| 3247 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3248 | } |
| 3249 | return tac; |
| 3250 | } |
| 3251 | |
| 3252 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3253 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3254 | try { |
| 3255 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3256 | } catch (SecurityException se) { |
| 3257 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3258 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3259 | + Binder.getCallingUid()); |
| 3260 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3261 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3262 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3263 | return null; |
| 3264 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3265 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3266 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3267 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3268 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3269 | return null; |
| 3270 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3271 | |
| 3272 | final long identity = Binder.clearCallingIdentity(); |
| 3273 | try { |
| 3274 | return phone.getMeid(); |
| 3275 | } finally { |
| 3276 | Binder.restoreCallingIdentity(identity); |
| 3277 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3278 | } |
| 3279 | |
| 3280 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3281 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3282 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3283 | String manufacturerCode = null; |
| 3284 | if (phone != null) { |
| 3285 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3286 | try { |
| 3287 | manufacturerCode = |
| 3288 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3289 | } catch (IndexOutOfBoundsException e) { |
| 3290 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3291 | return null; |
| 3292 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3293 | } |
| 3294 | return manufacturerCode; |
| 3295 | } |
| 3296 | |
| 3297 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3298 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3299 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3300 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3301 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3302 | return null; |
| 3303 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3304 | int subId = phone.getSubId(); |
| 3305 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3306 | mApp, subId, callingPackage, callingFeatureId, |
| 3307 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3308 | return null; |
| 3309 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3310 | |
| 3311 | final long identity = Binder.clearCallingIdentity(); |
| 3312 | try { |
| 3313 | return phone.getDeviceSvn(); |
| 3314 | } finally { |
| 3315 | Binder.restoreCallingIdentity(identity); |
| 3316 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3317 | } |
| 3318 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3319 | @Override |
| 3320 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3321 | final long identity = Binder.clearCallingIdentity(); |
| 3322 | try { |
| 3323 | final Phone phone = getPhone(subId); |
| 3324 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3325 | } finally { |
| 3326 | Binder.restoreCallingIdentity(identity); |
| 3327 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3328 | } |
| 3329 | |
| 3330 | @Override |
| 3331 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3332 | final long identity = Binder.clearCallingIdentity(); |
| 3333 | try { |
| 3334 | final Phone phone = getPhone(subId); |
| 3335 | return phone == null ? null : phone.getCarrierName(); |
| 3336 | } finally { |
| 3337 | Binder.restoreCallingIdentity(identity); |
| 3338 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3339 | } |
| 3340 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3341 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3342 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3343 | final long identity = Binder.clearCallingIdentity(); |
| 3344 | try { |
| 3345 | final Phone phone = getPhone(subId); |
| 3346 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3347 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3348 | } finally { |
| 3349 | Binder.restoreCallingIdentity(identity); |
| 3350 | } |
| 3351 | } |
| 3352 | |
| 3353 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3354 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3355 | final long identity = Binder.clearCallingIdentity(); |
| 3356 | try { |
| 3357 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3358 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3359 | } finally { |
| 3360 | Binder.restoreCallingIdentity(identity); |
| 3361 | } |
| 3362 | } |
| 3363 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3364 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3365 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3366 | if (!isSubscriptionMccMnc) { |
| 3367 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3368 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3369 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3370 | if (phone == null) { |
| 3371 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3372 | } |
| 3373 | final long identity = Binder.clearCallingIdentity(); |
| 3374 | try { |
| 3375 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3376 | } finally { |
| 3377 | Binder.restoreCallingIdentity(identity); |
| 3378 | } |
| 3379 | } |
| 3380 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3381 | // |
| 3382 | // Internal helper methods. |
| 3383 | // |
| 3384 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3385 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3386 | * Make sure the caller is the calling package itself |
| 3387 | * |
| 3388 | * @throws SecurityException if the caller is not the calling package |
| 3389 | */ |
| 3390 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3391 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3392 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3393 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3394 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3395 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3396 | } catch (PackageManager.NameNotFoundException e) { |
| 3397 | // packageUid is -1 |
| 3398 | } |
| 3399 | if (packageUid != callingUid) { |
| 3400 | throw new SecurityException(message + ": Package " + callingPackage |
| 3401 | + " does not belong to " + callingUid); |
| 3402 | } |
| 3403 | } |
| 3404 | |
| 3405 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3406 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3407 | * |
| 3408 | * @throws SecurityException if the caller does not have the required permission |
| 3409 | */ |
| 3410 | private void enforceModifyPermission() { |
| 3411 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3412 | } |
| 3413 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3414 | /** |
| 3415 | * Make sure the caller is system. |
| 3416 | * |
| 3417 | * @throws SecurityException if the caller is not system. |
| 3418 | */ |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 3419 | private static void enforceSystemCaller() { |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3420 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3421 | throw new SecurityException("Caller must be system"); |
| 3422 | } |
| 3423 | } |
| 3424 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3425 | private void enforceActiveEmergencySessionPermission() { |
| 3426 | mApp.enforceCallingOrSelfPermission( |
| 3427 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3428 | } |
| 3429 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3430 | /** |
| 3431 | * Make sure the caller has the CALL_PHONE permission. |
| 3432 | * |
| 3433 | * @throws SecurityException if the caller does not have the required permission |
| 3434 | */ |
| 3435 | private void enforceCallPermission() { |
| 3436 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3437 | } |
| 3438 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3439 | private void enforceSettingsPermission() { |
| 3440 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3441 | } |
| 3442 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3443 | private void enforceRebootPermission() { |
| 3444 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3445 | } |
| 3446 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3447 | private String createTelUrl(String number) { |
| 3448 | if (TextUtils.isEmpty(number)) { |
| 3449 | return null; |
| 3450 | } |
| 3451 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3452 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3453 | } |
| 3454 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3455 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3456 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3457 | } |
| 3458 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3459 | private static void logv(String msg) { |
| 3460 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3461 | } |
| 3462 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3463 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3464 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3465 | } |
| 3466 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3467 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3468 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3469 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3470 | } |
| 3471 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3472 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3473 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3474 | final long identity = Binder.clearCallingIdentity(); |
| 3475 | try { |
| 3476 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3477 | if (phone == null) { |
| 3478 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3479 | } else { |
| 3480 | return phone.getPhoneType(); |
| 3481 | } |
| 3482 | } finally { |
| 3483 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3484 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3485 | } |
| 3486 | |
| 3487 | /** |
| 3488 | * Returns the CDMA ERI icon index to display |
| 3489 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3490 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3491 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3492 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3493 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3494 | } |
| 3495 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3496 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3497 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3498 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3499 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3500 | mApp, subId, callingPackage, callingFeatureId, |
| 3501 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3502 | return -1; |
| 3503 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3504 | |
| 3505 | final long identity = Binder.clearCallingIdentity(); |
| 3506 | try { |
| 3507 | final Phone phone = getPhone(subId); |
| 3508 | if (phone != null) { |
| 3509 | return phone.getCdmaEriIconIndex(); |
| 3510 | } else { |
| 3511 | return -1; |
| 3512 | } |
| 3513 | } finally { |
| 3514 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3515 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3516 | } |
| 3517 | |
| 3518 | /** |
| 3519 | * Returns the CDMA ERI icon mode, |
| 3520 | * 0 - ON |
| 3521 | * 1 - FLASHING |
| 3522 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3523 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3524 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3525 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3526 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3527 | } |
| 3528 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3529 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3530 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3531 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3532 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3533 | mApp, subId, callingPackage, callingFeatureId, |
| 3534 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3535 | return -1; |
| 3536 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3537 | |
| 3538 | final long identity = Binder.clearCallingIdentity(); |
| 3539 | try { |
| 3540 | final Phone phone = getPhone(subId); |
| 3541 | if (phone != null) { |
| 3542 | return phone.getCdmaEriIconMode(); |
| 3543 | } else { |
| 3544 | return -1; |
| 3545 | } |
| 3546 | } finally { |
| 3547 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3548 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3549 | } |
| 3550 | |
| 3551 | /** |
| 3552 | * Returns the CDMA ERI text, |
| 3553 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3554 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3555 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3556 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3557 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3558 | } |
| 3559 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3560 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3561 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3562 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3563 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3564 | mApp, subId, callingPackage, callingFeatureId, |
| 3565 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3566 | return null; |
| 3567 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3568 | |
| 3569 | final long identity = Binder.clearCallingIdentity(); |
| 3570 | try { |
| 3571 | final Phone phone = getPhone(subId); |
| 3572 | if (phone != null) { |
| 3573 | return phone.getCdmaEriText(); |
| 3574 | } else { |
| 3575 | return null; |
| 3576 | } |
| 3577 | } finally { |
| 3578 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3579 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3580 | } |
| 3581 | |
| 3582 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3583 | * Returns the CDMA MDN. |
| 3584 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3585 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3586 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3587 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3588 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3589 | |
| 3590 | final long identity = Binder.clearCallingIdentity(); |
| 3591 | try { |
| 3592 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3593 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3594 | return phone.getLine1Number(); |
| 3595 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3596 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3597 | return null; |
| 3598 | } |
| 3599 | } finally { |
| 3600 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3601 | } |
| 3602 | } |
| 3603 | |
| 3604 | /** |
| 3605 | * Returns the CDMA MIN. |
| 3606 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3607 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3608 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3609 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3610 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3611 | |
| 3612 | final long identity = Binder.clearCallingIdentity(); |
| 3613 | try { |
| 3614 | final Phone phone = getPhone(subId); |
| 3615 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3616 | return phone.getCdmaMin(); |
| 3617 | } else { |
| 3618 | return null; |
| 3619 | } |
| 3620 | } finally { |
| 3621 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3622 | } |
| 3623 | } |
| 3624 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3625 | @Override |
| 3626 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3627 | INumberVerificationCallback callback, String callingPackage) { |
| 3628 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3629 | != PERMISSION_GRANTED) { |
| 3630 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3631 | } |
| 3632 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3633 | |
| 3634 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3635 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3636 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3637 | + "calling package: " + callingPackage |
| 3638 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3639 | } |
| 3640 | |
| 3641 | if (range == null) { |
| 3642 | throw new NullPointerException("Range must be non-null"); |
| 3643 | } |
| 3644 | |
| 3645 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3646 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3647 | |
| 3648 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3649 | } |
| 3650 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3651 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3652 | * Returns true if CDMA provisioning needs to run. |
| 3653 | */ |
| 3654 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3655 | final long identity = Binder.clearCallingIdentity(); |
| 3656 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3657 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3658 | } finally { |
| 3659 | Binder.restoreCallingIdentity(identity); |
| 3660 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3661 | } |
| 3662 | |
| 3663 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3664 | * Sets the voice mail number of a given subId. |
| 3665 | */ |
| 3666 | @Override |
| 3667 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3668 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3669 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3670 | |
| 3671 | final long identity = Binder.clearCallingIdentity(); |
| 3672 | try { |
| 3673 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3674 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3675 | return success; |
| 3676 | } finally { |
| 3677 | Binder.restoreCallingIdentity(identity); |
| 3678 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3679 | } |
| 3680 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3681 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3682 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3683 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3684 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3685 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3686 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3687 | throw new SecurityException("caller must be system dialer"); |
| 3688 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3689 | |
| 3690 | final long identity = Binder.clearCallingIdentity(); |
| 3691 | try { |
| 3692 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3693 | if (phoneAccountHandle == null) { |
| 3694 | return null; |
| 3695 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3696 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3697 | } finally { |
| 3698 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3699 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3700 | } |
| 3701 | |
| 3702 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3703 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3704 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3705 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3706 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3707 | mApp, subId, callingPackage, callingFeatureId, |
| 3708 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3709 | return null; |
| 3710 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3711 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3712 | final long identity = Binder.clearCallingIdentity(); |
| 3713 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3714 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3715 | } finally { |
| 3716 | Binder.restoreCallingIdentity(identity); |
| 3717 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3718 | } |
| 3719 | |
| 3720 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3721 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3722 | VisualVoicemailSmsFilterSettings settings) { |
| 3723 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3724 | |
| 3725 | final long identity = Binder.clearCallingIdentity(); |
| 3726 | try { |
| 3727 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3728 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3729 | } finally { |
| 3730 | Binder.restoreCallingIdentity(identity); |
| 3731 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3732 | } |
| 3733 | |
| 3734 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3735 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3736 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3737 | |
| 3738 | final long identity = Binder.clearCallingIdentity(); |
| 3739 | try { |
| 3740 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3741 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3742 | } finally { |
| 3743 | Binder.restoreCallingIdentity(identity); |
| 3744 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3745 | } |
| 3746 | |
| 3747 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3748 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3749 | String callingPackage, int subId) { |
| 3750 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3751 | |
| 3752 | final long identity = Binder.clearCallingIdentity(); |
| 3753 | try { |
| 3754 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3755 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3756 | } finally { |
| 3757 | Binder.restoreCallingIdentity(identity); |
| 3758 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3759 | } |
| 3760 | |
| 3761 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3762 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3763 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3764 | |
| 3765 | final long identity = Binder.clearCallingIdentity(); |
| 3766 | try { |
| 3767 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3768 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3769 | } finally { |
| 3770 | Binder.restoreCallingIdentity(identity); |
| 3771 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3772 | } |
| 3773 | |
| 3774 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3775 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3776 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3777 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3778 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3779 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3780 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3781 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3782 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3783 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3784 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3785 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3786 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3787 | * Sets the voice activation state of a given subId. |
| 3788 | */ |
| 3789 | @Override |
| 3790 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3791 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3792 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3793 | |
| 3794 | final long identity = Binder.clearCallingIdentity(); |
| 3795 | try { |
| 3796 | final Phone phone = getPhone(subId); |
| 3797 | if (phone != null) { |
| 3798 | phone.setVoiceActivationState(activationState); |
| 3799 | } else { |
| 3800 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3801 | } |
| 3802 | } finally { |
| 3803 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3804 | } |
| 3805 | } |
| 3806 | |
| 3807 | /** |
| 3808 | * Sets the data activation state of a given subId. |
| 3809 | */ |
| 3810 | @Override |
| 3811 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3812 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3813 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3814 | |
| 3815 | final long identity = Binder.clearCallingIdentity(); |
| 3816 | try { |
| 3817 | final Phone phone = getPhone(subId); |
| 3818 | if (phone != null) { |
| 3819 | phone.setDataActivationState(activationState); |
| 3820 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3821 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3822 | } |
| 3823 | } finally { |
| 3824 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3825 | } |
| 3826 | } |
| 3827 | |
| 3828 | /** |
| 3829 | * Returns the voice activation state of a given subId. |
| 3830 | */ |
| 3831 | @Override |
| 3832 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3833 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3834 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3835 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3836 | final long identity = Binder.clearCallingIdentity(); |
| 3837 | try { |
| 3838 | if (phone != null) { |
| 3839 | return phone.getVoiceActivationState(); |
| 3840 | } else { |
| 3841 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3842 | } |
| 3843 | } finally { |
| 3844 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3845 | } |
| 3846 | } |
| 3847 | |
| 3848 | /** |
| 3849 | * Returns the data activation state of a given subId. |
| 3850 | */ |
| 3851 | @Override |
| 3852 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3853 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3854 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3855 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3856 | final long identity = Binder.clearCallingIdentity(); |
| 3857 | try { |
| 3858 | if (phone != null) { |
| 3859 | return phone.getDataActivationState(); |
| 3860 | } else { |
| 3861 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3862 | } |
| 3863 | } finally { |
| 3864 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3865 | } |
| 3866 | } |
| 3867 | |
| 3868 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3869 | * Returns the unread count of voicemails for a subId |
| 3870 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3871 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3872 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3873 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3874 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3875 | mApp, subId, callingPackage, callingFeatureId, |
| 3876 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3877 | return 0; |
| 3878 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3879 | final long identity = Binder.clearCallingIdentity(); |
| 3880 | try { |
| 3881 | final Phone phone = getPhone(subId); |
| 3882 | if (phone != null) { |
| 3883 | return phone.getVoiceMessageCount(); |
| 3884 | } else { |
| 3885 | return 0; |
| 3886 | } |
| 3887 | } finally { |
| 3888 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3889 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3890 | } |
| 3891 | |
| 3892 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3893 | * returns true, if the device is in a state where both voice and data |
| 3894 | * are supported simultaneously. This can change based on location or network condition. |
| 3895 | */ |
| 3896 | @Override |
| 3897 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3898 | final long identity = Binder.clearCallingIdentity(); |
| 3899 | try { |
| 3900 | final Phone phone = getPhone(subId); |
| 3901 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3902 | } finally { |
| 3903 | Binder.restoreCallingIdentity(identity); |
| 3904 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3905 | } |
| 3906 | |
| 3907 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3908 | * Send the dialer code if called from the current default dialer or the caller has |
| 3909 | * carrier privilege. |
| 3910 | * @param inputCode The dialer code to send |
| 3911 | */ |
| 3912 | @Override |
| 3913 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3914 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3915 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3916 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3917 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3918 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3919 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3920 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3921 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3922 | |
| 3923 | final long identity = Binder.clearCallingIdentity(); |
| 3924 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3925 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3926 | } finally { |
| 3927 | Binder.restoreCallingIdentity(identity); |
| 3928 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3929 | } |
| 3930 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3931 | @Override |
| 3932 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3933 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3934 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3935 | mApp, subId, "getNetworkSelectionMode"); |
| 3936 | final long identity = Binder.clearCallingIdentity(); |
| 3937 | try { |
| 3938 | if (!isActiveSubscription(subId)) { |
| 3939 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3940 | } |
| 3941 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3942 | } finally { |
| 3943 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3944 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3945 | } |
| 3946 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3947 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3948 | public boolean isInEmergencySmsMode() { |
| 3949 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3950 | final long identity = Binder.clearCallingIdentity(); |
| 3951 | try { |
| 3952 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3953 | if (phone.isInEmergencySmsMode()) { |
| 3954 | return true; |
| 3955 | } |
| 3956 | } |
| 3957 | } finally { |
| 3958 | Binder.restoreCallingIdentity(identity); |
| 3959 | } |
| 3960 | return false; |
| 3961 | } |
| 3962 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3963 | /** |
| 3964 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3965 | * @param subId The subscription to use to check the configuration. |
| 3966 | * @param c The callback that will be used to send the result. |
| 3967 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3968 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3969 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3970 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3971 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3972 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3973 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3974 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3975 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3976 | "IMS not available on device."); |
| 3977 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3978 | final long token = Binder.clearCallingIdentity(); |
| 3979 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 3980 | int slotId = getSlotIndexOrException(subId); |
| 3981 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 3982 | ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3983 | } catch (ImsException e) { |
| 3984 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3985 | } finally { |
| 3986 | Binder.restoreCallingIdentity(token); |
| 3987 | } |
| 3988 | } |
| 3989 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3990 | /** |
| 3991 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3992 | * @param subId The subscription to use to check the configuration. |
| 3993 | * @param c The callback that will be used to send the result. |
| 3994 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3995 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3996 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3997 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3998 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3999 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4000 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4001 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4002 | final long token = Binder.clearCallingIdentity(); |
| 4003 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4004 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 4005 | .removeRegistrationCallbackForSubscription(c, subId); |
| 4006 | } catch (ImsException e) { |
| 4007 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4008 | + "is inactive, ignoring unregister."); |
| 4009 | // If the subscription is no longer active, just return, since the callback |
| 4010 | // will already have been removed internally. |
| 4011 | } finally { |
| 4012 | Binder.restoreCallingIdentity(token); |
| 4013 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4014 | } |
| 4015 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4016 | /** |
| 4017 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4018 | */ |
| 4019 | @Override |
| 4020 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4021 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4022 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4023 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4024 | "IMS not available on device."); |
| 4025 | } |
| 4026 | final long token = Binder.clearCallingIdentity(); |
| 4027 | try { |
| 4028 | Phone phone = getPhone(subId); |
| 4029 | if (phone == null) { |
| 4030 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4031 | + subId + "'"); |
| 4032 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4033 | } |
| 4034 | phone.getImsRegistrationState(regState -> { |
| 4035 | try { |
| 4036 | consumer.accept((regState == null) |
| 4037 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4038 | } catch (RemoteException e) { |
| 4039 | // Ignore if the remote process is no longer available to call back. |
| 4040 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4041 | } |
| 4042 | }); |
| 4043 | } finally { |
| 4044 | Binder.restoreCallingIdentity(token); |
| 4045 | } |
| 4046 | } |
| 4047 | |
| 4048 | /** |
| 4049 | * Get the transport type for the IMS service registration state. |
| 4050 | */ |
| 4051 | @Override |
| 4052 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4053 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4054 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4055 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4056 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4057 | "IMS not available on device."); |
| 4058 | } |
| 4059 | final long token = Binder.clearCallingIdentity(); |
| 4060 | try { |
| 4061 | Phone phone = getPhone(subId); |
| 4062 | if (phone == null) { |
| 4063 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4064 | + subId + "'"); |
| 4065 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4066 | } |
| 4067 | phone.getImsRegistrationTech(regTech -> { |
| 4068 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4069 | int regTechConverted = (regTech == null) |
| 4070 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4071 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4072 | regTechConverted); |
| 4073 | try { |
| 4074 | consumer.accept(regTechConverted); |
| 4075 | } catch (RemoteException e) { |
| 4076 | // Ignore if the remote process is no longer available to call back. |
| 4077 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4078 | } |
| 4079 | }); |
| 4080 | } finally { |
| 4081 | Binder.restoreCallingIdentity(token); |
| 4082 | } |
| 4083 | } |
| 4084 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4085 | /** |
| 4086 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4087 | * @param subId The subscription to use to check the configuration. |
| 4088 | * @param c The callback that will be used to send the result. |
| 4089 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4090 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4091 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4092 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4093 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4094 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4095 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4096 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4097 | "IMS not available on device."); |
| 4098 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4099 | final long token = Binder.clearCallingIdentity(); |
| 4100 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4101 | int slotId = getSlotIndexOrException(subId); |
| 4102 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4103 | ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4104 | } catch (ImsException e) { |
| 4105 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4106 | } finally { |
| 4107 | Binder.restoreCallingIdentity(token); |
| 4108 | } |
| 4109 | } |
| 4110 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4111 | /** |
| 4112 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4113 | * @param subId The subscription to use to check the configuration. |
| 4114 | * @param c The callback that will be used to send the result. |
| 4115 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4116 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4117 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4118 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4119 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4120 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4121 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4122 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4123 | |
| 4124 | final long token = Binder.clearCallingIdentity(); |
| 4125 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4126 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4127 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4128 | } catch (ImsException e) { |
| 4129 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4130 | + "is inactive, ignoring unregister."); |
| 4131 | // If the subscription is no longer active, just return, since the callback |
| 4132 | // will already have been removed internally. |
| 4133 | } finally { |
| 4134 | Binder.restoreCallingIdentity(token); |
| 4135 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4136 | } |
| 4137 | |
| 4138 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4139 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4140 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4141 | final long token = Binder.clearCallingIdentity(); |
| 4142 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4143 | int slotId = getSlotIndexOrException(subId); |
| 4144 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4145 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4146 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4147 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4148 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4149 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4150 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4151 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4152 | } finally { |
| 4153 | Binder.restoreCallingIdentity(token); |
| 4154 | } |
| 4155 | } |
| 4156 | |
| 4157 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4158 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4159 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4160 | final long token = Binder.clearCallingIdentity(); |
| 4161 | try { |
| 4162 | Phone phone = getPhone(subId); |
| 4163 | if (phone == null) return false; |
| 4164 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4165 | } catch (com.android.ims.ImsException e) { |
| 4166 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4167 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4168 | } finally { |
| 4169 | Binder.restoreCallingIdentity(token); |
| 4170 | } |
| 4171 | } |
| 4172 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4173 | /** |
| 4174 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4175 | * subscription. |
| 4176 | * @param subId The subscription to use to check the configuration. |
| 4177 | * @param callback The callback that will be used to send the result. |
| 4178 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4179 | * @param transportType The transport type of the MmTelFeature capability. |
| 4180 | */ |
| 4181 | @Override |
| 4182 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4183 | int transportType) { |
| 4184 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 4185 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4186 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4187 | "IMS not available on device."); |
| 4188 | } |
| 4189 | final long token = Binder.clearCallingIdentity(); |
| 4190 | try { |
| 4191 | int slotId = getSlotIndex(subId); |
| 4192 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4193 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4194 | + subId + "'"); |
| 4195 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4196 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4197 | verifyImsMmTelConfiguredOrThrow(slotId); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4198 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4199 | transportType, aBoolean -> { |
| 4200 | try { |
| 4201 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4202 | } catch (RemoteException e) { |
| 4203 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4204 | + "running. Ignore"); |
| 4205 | } |
| 4206 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4207 | } catch (ImsException e) { |
| 4208 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4209 | } finally { |
| 4210 | Binder.restoreCallingIdentity(token); |
| 4211 | } |
| 4212 | } |
| 4213 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4214 | /** |
| 4215 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4216 | * @param subId The subscription to use to check the configuration. |
| 4217 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4218 | @Override |
| 4219 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4220 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4221 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4222 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4223 | final long token = Binder.clearCallingIdentity(); |
| 4224 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4225 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4226 | // 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] | 4227 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4228 | } catch (ImsException e) { |
| 4229 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4230 | } finally { |
| 4231 | Binder.restoreCallingIdentity(token); |
| 4232 | } |
| 4233 | } |
| 4234 | |
| 4235 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4236 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4237 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4238 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4239 | final long identity = Binder.clearCallingIdentity(); |
| 4240 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4241 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4242 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4243 | // 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] | 4244 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4245 | } catch (ImsException e) { |
| 4246 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4247 | } finally { |
| 4248 | Binder.restoreCallingIdentity(identity); |
| 4249 | } |
| 4250 | } |
| 4251 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4252 | /** |
| 4253 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4254 | * @param subId The subscription to use to check the configuration. |
| 4255 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4256 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4257 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4258 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4259 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4260 | final long identity = Binder.clearCallingIdentity(); |
| 4261 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4262 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4263 | // 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] | 4264 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4265 | } catch (ImsException e) { |
| 4266 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4267 | } finally { |
| 4268 | Binder.restoreCallingIdentity(identity); |
| 4269 | } |
| 4270 | } |
| 4271 | |
| 4272 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4273 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4274 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4275 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4276 | final long identity = Binder.clearCallingIdentity(); |
| 4277 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4278 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4279 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4280 | // 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] | 4281 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4282 | } catch (ImsException e) { |
| 4283 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4284 | } finally { |
| 4285 | Binder.restoreCallingIdentity(identity); |
| 4286 | } |
| 4287 | } |
| 4288 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4289 | /** |
| 4290 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4291 | * @param subId The subscription to use to check the configuration. |
| 4292 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4293 | @Override |
| 4294 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4295 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4296 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4297 | final long identity = Binder.clearCallingIdentity(); |
| 4298 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4299 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4300 | // 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] | 4301 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4302 | } catch (ImsException e) { |
| 4303 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4304 | } finally { |
| 4305 | Binder.restoreCallingIdentity(identity); |
| 4306 | } |
| 4307 | } |
| 4308 | |
| 4309 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4310 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4311 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4312 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4313 | final long identity = Binder.clearCallingIdentity(); |
| 4314 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4315 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4316 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4317 | // 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] | 4318 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4319 | } catch (ImsException e) { |
| 4320 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4321 | } finally { |
| 4322 | Binder.restoreCallingIdentity(identity); |
| 4323 | } |
| 4324 | } |
| 4325 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4326 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4327 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4328 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4329 | * @param subId The subscription to use to check the configuration. |
| 4330 | */ |
| 4331 | @Override |
| 4332 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4333 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4334 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4335 | final long identity = Binder.clearCallingIdentity(); |
| 4336 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4337 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4338 | // 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] | 4339 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4340 | } catch (ImsException e) { |
| 4341 | throw new ServiceSpecificException(e.getCode()); |
| 4342 | } finally { |
| 4343 | Binder.restoreCallingIdentity(identity); |
| 4344 | } |
| 4345 | } |
| 4346 | |
| 4347 | /** |
| 4348 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4349 | * Requires MODIFY_PHONE_STATE permission. |
| 4350 | * @param subId The subscription to use to check the configuration. |
| 4351 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4352 | * false otherwise |
| 4353 | */ |
| 4354 | @Override |
| 4355 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4356 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4357 | "setCrossSimCallingEnabled"); |
| 4358 | final long identity = Binder.clearCallingIdentity(); |
| 4359 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4360 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4361 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4362 | // 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] | 4363 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4364 | } catch (ImsException e) { |
| 4365 | throw new ServiceSpecificException(e.getCode()); |
| 4366 | } finally { |
| 4367 | Binder.restoreCallingIdentity(identity); |
| 4368 | } |
| 4369 | } |
| 4370 | |
| 4371 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4372 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4373 | * @param subId The subscription to use to check the configuration. |
| 4374 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4375 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4376 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4377 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4378 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4379 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4380 | final long identity = Binder.clearCallingIdentity(); |
| 4381 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4382 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4383 | // 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] | 4384 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4385 | } catch (ImsException e) { |
| 4386 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4387 | } finally { |
| 4388 | Binder.restoreCallingIdentity(identity); |
| 4389 | } |
| 4390 | } |
| 4391 | |
| 4392 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4393 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4394 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4395 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4396 | final long identity = Binder.clearCallingIdentity(); |
| 4397 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4398 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4399 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4400 | // 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] | 4401 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4402 | } catch (ImsException e) { |
| 4403 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4404 | } finally { |
| 4405 | Binder.restoreCallingIdentity(identity); |
| 4406 | } |
| 4407 | } |
| 4408 | |
| 4409 | @Override |
| 4410 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4411 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4412 | "setVoWiFiNonPersistent"); |
| 4413 | final long identity = Binder.clearCallingIdentity(); |
| 4414 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4415 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4416 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4417 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4418 | } catch (ImsException e) { |
| 4419 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4420 | } finally { |
| 4421 | Binder.restoreCallingIdentity(identity); |
| 4422 | } |
| 4423 | } |
| 4424 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4425 | /** |
| 4426 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4427 | * @param subId The subscription to use to check the configuration. |
| 4428 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4429 | @Override |
| 4430 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4431 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4432 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4433 | final long identity = Binder.clearCallingIdentity(); |
| 4434 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4435 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4436 | // 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] | 4437 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4438 | } catch (ImsException e) { |
| 4439 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4440 | } finally { |
| 4441 | Binder.restoreCallingIdentity(identity); |
| 4442 | } |
| 4443 | } |
| 4444 | |
| 4445 | @Override |
| 4446 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4447 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4448 | "setVoWiFiModeSetting"); |
| 4449 | final long identity = Binder.clearCallingIdentity(); |
| 4450 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4451 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4452 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4453 | // 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] | 4454 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4455 | } catch (ImsException e) { |
| 4456 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4457 | } finally { |
| 4458 | Binder.restoreCallingIdentity(identity); |
| 4459 | } |
| 4460 | } |
| 4461 | |
| 4462 | @Override |
| 4463 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4464 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4465 | final long identity = Binder.clearCallingIdentity(); |
| 4466 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4467 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4468 | // 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] | 4469 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4470 | } catch (ImsException e) { |
| 4471 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4472 | } finally { |
| 4473 | Binder.restoreCallingIdentity(identity); |
| 4474 | } |
| 4475 | } |
| 4476 | |
| 4477 | @Override |
| 4478 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4479 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4480 | "setVoWiFiRoamingModeSetting"); |
| 4481 | final long identity = Binder.clearCallingIdentity(); |
| 4482 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4483 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4484 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4485 | // 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] | 4486 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4487 | } catch (ImsException e) { |
| 4488 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4489 | } finally { |
| 4490 | Binder.restoreCallingIdentity(identity); |
| 4491 | } |
| 4492 | } |
| 4493 | |
| 4494 | @Override |
| 4495 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4496 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4497 | "setRttCapabilityEnabled"); |
| 4498 | final long identity = Binder.clearCallingIdentity(); |
| 4499 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4500 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4501 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4502 | // 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] | 4503 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4504 | } catch (ImsException e) { |
| 4505 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4506 | } finally { |
| 4507 | Binder.restoreCallingIdentity(identity); |
| 4508 | } |
| 4509 | } |
| 4510 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4511 | /** |
| 4512 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4513 | * @param subId The subscription to use to check the configuration. |
| 4514 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4515 | @Override |
| 4516 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4517 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4518 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4519 | final long identity = Binder.clearCallingIdentity(); |
| 4520 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4521 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4522 | // 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] | 4523 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4524 | } catch (ImsException e) { |
| 4525 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4526 | } finally { |
| 4527 | Binder.restoreCallingIdentity(identity); |
| 4528 | } |
| 4529 | } |
| 4530 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4531 | @Override |
| 4532 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4533 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4534 | final long identity = Binder.clearCallingIdentity(); |
| 4535 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4536 | if (!isImsAvailableOnDevice()) { |
| 4537 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4538 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4539 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4540 | int slotId = getSlotIndexOrException(subId); |
| 4541 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4542 | ImsManager.getInstance(mApp, slotId) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4543 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4544 | } catch (ImsException e) { |
| 4545 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4546 | } finally { |
| 4547 | Binder.restoreCallingIdentity(identity); |
| 4548 | } |
| 4549 | } |
| 4550 | |
| 4551 | @Override |
| 4552 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4553 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4554 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4555 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4556 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4557 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4558 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4559 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4560 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4561 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4562 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4563 | + "is inactive, ignoring unregister."); |
| 4564 | // If the subscription is no longer active, just return, since the callback will already |
| 4565 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4566 | } finally { |
| 4567 | Binder.restoreCallingIdentity(identity); |
| 4568 | } |
| 4569 | } |
| 4570 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4571 | |
| 4572 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4573 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4574 | message); |
| 4575 | } |
| 4576 | |
| 4577 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4578 | boolean isMmtelCapability) { |
| 4579 | Phone phone = getPhone(subId); |
| 4580 | if (phone == null) { |
| 4581 | loge("phone instance null for subid " + subId); |
| 4582 | return false; |
| 4583 | } |
| 4584 | if (isMmtelCapability) { |
| 4585 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4586 | return false; |
| 4587 | } |
| 4588 | } else { |
| 4589 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4590 | return false; |
| 4591 | } |
| 4592 | } |
| 4593 | return true; |
| 4594 | } |
| 4595 | |
| 4596 | @Override |
| 4597 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4598 | boolean isProvisioned) { |
| 4599 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4600 | |
| 4601 | final long identity = Binder.clearCallingIdentity(); |
| 4602 | try { |
| 4603 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4604 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4605 | return; |
| 4606 | } |
| 4607 | |
| 4608 | // this capability requires provisioning, route to the correct API. |
| 4609 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4610 | switch (capability) { |
| 4611 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4612 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4613 | ims.setEabProvisioned(isProvisioned); |
| 4614 | break; |
| 4615 | default: { |
| 4616 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4617 | + "rcs capability '" + capability + "', which does not require " |
| 4618 | + "provisioning."); |
| 4619 | } |
| 4620 | } |
| 4621 | } finally { |
| 4622 | Binder.restoreCallingIdentity(identity); |
| 4623 | } |
| 4624 | |
| 4625 | } |
| 4626 | |
| 4627 | |
| 4628 | @Override |
| 4629 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4630 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4631 | final long identity = Binder.clearCallingIdentity(); |
| 4632 | try { |
| 4633 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4634 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4635 | return true; |
| 4636 | } |
| 4637 | |
| 4638 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4639 | switch (capability) { |
| 4640 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4641 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4642 | return ims.isEabProvisionedOnDevice(); |
| 4643 | |
| 4644 | default: { |
| 4645 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4646 | + "capability '" + capability + "', which does not require " |
| 4647 | + "provisioning."); |
| 4648 | } |
| 4649 | } |
| 4650 | |
| 4651 | } finally { |
| 4652 | Binder.restoreCallingIdentity(identity); |
| 4653 | } |
| 4654 | } |
| 4655 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4656 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4657 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4658 | boolean isProvisioned) { |
| 4659 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4660 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE |
| 4661 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4662 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4663 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4664 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4665 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4666 | final long identity = Binder.clearCallingIdentity(); |
| 4667 | try { |
| 4668 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4669 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4670 | return; |
| 4671 | } |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4672 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4673 | || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
| 4674 | loge("setImsProvisioningStatusForCapability: called for technology that does " |
| 4675 | + "not support provisioning - " + tech); |
| 4676 | return; |
| 4677 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4678 | |
| 4679 | // this capability requires provisioning, route to the correct API. |
| 4680 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4681 | switch (capability) { |
| 4682 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4683 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4684 | ims.setVolteProvisioned(isProvisioned); |
| 4685 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4686 | ims.setWfcProvisioned(isProvisioned); |
| 4687 | } |
| 4688 | break; |
| 4689 | } |
| 4690 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4691 | // There is currently no difference in VT provisioning type. |
| 4692 | ims.setVtProvisioned(isProvisioned); |
| 4693 | break; |
| 4694 | } |
| 4695 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4696 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4697 | // change the capability of the feature instead if needed. |
| 4698 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4699 | == isProvisioned) { |
| 4700 | // No change in provisioning. |
| 4701 | return; |
| 4702 | } |
| 4703 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4704 | try { |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4705 | ims.changeMmTelCapability(isProvisioned, capability, tech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4706 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4707 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4708 | + ", Exception" + e.getMessage()); |
| 4709 | } |
| 4710 | break; |
| 4711 | } |
| 4712 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4713 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4714 | + "MmTel capability '" + capability + "', which does not require " |
| 4715 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4716 | } |
| 4717 | } |
| 4718 | |
| 4719 | } finally { |
| 4720 | Binder.restoreCallingIdentity(identity); |
| 4721 | } |
| 4722 | } |
| 4723 | |
| 4724 | @Override |
| 4725 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4726 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4727 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE |
| 4728 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4729 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4730 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4731 | } |
| 4732 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4733 | final long identity = Binder.clearCallingIdentity(); |
| 4734 | try { |
| 4735 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4736 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4737 | return true; |
| 4738 | } |
| 4739 | |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4740 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4741 | || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
| 4742 | loge("getImsProvisioningStatusForCapability: called for technology that does " |
| 4743 | + "not support provisioning - " + tech); |
| 4744 | return true; |
| 4745 | } |
| 4746 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4747 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4748 | switch (capability) { |
| 4749 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4750 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4751 | return ims.isVolteProvisionedOnDevice(); |
| 4752 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4753 | return ims.isWfcProvisionedOnDevice(); |
| 4754 | } |
| 4755 | // This should never happen, since we are checking tech above to make sure it |
| 4756 | // is either LTE or IWLAN. |
| 4757 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4758 | + "capability."); |
| 4759 | } |
| 4760 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4761 | // There is currently no difference in VT provisioning type. |
| 4762 | return ims.isVtProvisionedOnDevice(); |
| 4763 | } |
| 4764 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4765 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4766 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4767 | } |
| 4768 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4769 | throw new IllegalArgumentException( |
| 4770 | "Tried to get provisioning for MmTel capability '" + capability |
| 4771 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4772 | } |
| 4773 | } |
| 4774 | |
| 4775 | } finally { |
| 4776 | Binder.restoreCallingIdentity(identity); |
| 4777 | } |
| 4778 | } |
| 4779 | |
| 4780 | @Override |
| 4781 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4782 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4783 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4784 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4785 | } |
| 4786 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4787 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4788 | return (provisionedBits & capability) > 0; |
| 4789 | } |
| 4790 | |
| 4791 | @Override |
| 4792 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4793 | boolean isProvisioned) { |
| 4794 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4795 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4796 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4797 | } |
| 4798 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4799 | "setProvisioningStatusForCapability"); |
| 4800 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4801 | // If the current provisioning status for capability already matches isProvisioned, |
| 4802 | // do nothing. |
| 4803 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4804 | return; |
| 4805 | } |
| 4806 | if (isProvisioned) { |
| 4807 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4808 | } else { |
| 4809 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4810 | } |
| 4811 | } |
| 4812 | |
| 4813 | /** |
| 4814 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4815 | * technology. The bitfield should mirror the bitfield defined by |
| 4816 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4817 | */ |
| 4818 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4819 | String key = getMmTelProvisioningKey(subId, tech); |
| 4820 | // Default is no capabilities are provisioned. |
| 4821 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4822 | } |
| 4823 | |
| 4824 | /** |
| 4825 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4826 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4827 | * technology specified. |
| 4828 | * |
| 4829 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4830 | */ |
| 4831 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4832 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4833 | String key = getMmTelProvisioningKey(subId, tech); |
| 4834 | editor.putInt(key, newField); |
| 4835 | editor.commit(); |
| 4836 | } |
| 4837 | |
| 4838 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4839 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4840 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4841 | } |
| 4842 | |
| 4843 | /** |
| 4844 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4845 | * carrier associated with the subscription id. |
| 4846 | */ |
| 4847 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4848 | int capability) { |
| 4849 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4850 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4851 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4852 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4853 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4854 | false); |
| 4855 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4856 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4857 | |
| 4858 | // First check to make sure that the capability requires provisioning. |
| 4859 | switch (capability) { |
| 4860 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4861 | // intentional fallthrough |
| 4862 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4863 | if (requireVoiceVtProvisioning) { |
| 4864 | // Voice and Video requires provisioning |
| 4865 | return true; |
| 4866 | } |
| 4867 | break; |
| 4868 | } |
| 4869 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4870 | if (requireUtProvisioning) { |
| 4871 | // UT requires provisioning |
| 4872 | return true; |
| 4873 | } |
| 4874 | break; |
| 4875 | } |
| 4876 | } |
| 4877 | return false; |
| 4878 | } |
| 4879 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4880 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4881 | int capability) { |
| 4882 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4883 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4884 | |
| 4885 | boolean requireRcsProvisioning = c.getBoolean( |
| 4886 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4887 | |
| 4888 | // First check to make sure that the capability requires provisioning. |
| 4889 | switch (capability) { |
| 4890 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4891 | // intentional fallthrough |
| 4892 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4893 | if (requireRcsProvisioning) { |
| 4894 | // OPTION or PRESENCE requires provisioning |
| 4895 | return true; |
| 4896 | } |
| 4897 | break; |
| 4898 | } |
| 4899 | } |
| 4900 | return false; |
| 4901 | } |
| 4902 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4903 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4904 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4905 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4906 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4907 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4908 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4909 | final long identity = Binder.clearCallingIdentity(); |
| 4910 | try { |
| 4911 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4912 | int slotId = getSlotIndex(subId); |
| 4913 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4914 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4915 | + subId + "' for key:" + key); |
| 4916 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4917 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4918 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4919 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4920 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4921 | + subId + "' for key:" + key); |
| 4922 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4923 | } finally { |
| 4924 | Binder.restoreCallingIdentity(identity); |
| 4925 | } |
| 4926 | } |
| 4927 | |
| 4928 | @Override |
| 4929 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4930 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4931 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4932 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4933 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4934 | final long identity = Binder.clearCallingIdentity(); |
| 4935 | try { |
| 4936 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4937 | int slotId = getSlotIndex(subId); |
| 4938 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4939 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4940 | + subId + "' for key:" + key); |
| 4941 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4942 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4943 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4944 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4945 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4946 | + subId + "' for key:" + key); |
| 4947 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4948 | } finally { |
| 4949 | Binder.restoreCallingIdentity(identity); |
| 4950 | } |
| 4951 | } |
| 4952 | |
| 4953 | @Override |
| 4954 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4955 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4956 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4957 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4958 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4959 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4960 | final long identity = Binder.clearCallingIdentity(); |
| 4961 | try { |
| 4962 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4963 | int slotId = getSlotIndex(subId); |
| 4964 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4965 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4966 | + subId + "' for key:" + key); |
| 4967 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4968 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4969 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4970 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4971 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4972 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4973 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4974 | } finally { |
| 4975 | Binder.restoreCallingIdentity(identity); |
| 4976 | } |
| 4977 | } |
| 4978 | |
| 4979 | @Override |
| 4980 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4981 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4982 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4983 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4984 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4985 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4986 | final long identity = Binder.clearCallingIdentity(); |
| 4987 | try { |
| 4988 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4989 | int slotId = getSlotIndex(subId); |
| 4990 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4991 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4992 | + subId + "' for key:" + key); |
| 4993 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4994 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4995 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4996 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4997 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4998 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4999 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5000 | } finally { |
| 5001 | Binder.restoreCallingIdentity(identity); |
| 5002 | } |
| 5003 | } |
| 5004 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5005 | /** |
| 5006 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5007 | * for the given slot ID or no ImsResolver instance has been created. |
| 5008 | * @param slotId The slot ID that the IMS service is created for. |
| 5009 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5010 | */ |
| 5011 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5012 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5013 | ImsFeature.FEATURE_MMTEL)) { |
| 5014 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5015 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5016 | } |
| 5017 | } |
| 5018 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5019 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5020 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5021 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5022 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5023 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5024 | } |
| 5025 | return slotId; |
| 5026 | } |
| 5027 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5028 | private int getSlotIndex(int subId) { |
| 5029 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5030 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5031 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5032 | } |
| 5033 | return slotId; |
| 5034 | } |
| 5035 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5036 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5037 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5038 | */ |
| 5039 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5040 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5041 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5042 | try { |
| 5043 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5044 | } catch (SecurityException se) { |
| 5045 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5046 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5047 | + Binder.getCallingUid()); |
| 5048 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5049 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5050 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5051 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5052 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5053 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5054 | mApp, subId, callingPackage, callingFeatureId, |
| 5055 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5056 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5057 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5058 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5059 | final long identity = Binder.clearCallingIdentity(); |
| 5060 | try { |
| 5061 | final Phone phone = getPhone(subId); |
| 5062 | if (phone != null) { |
| 5063 | return phone.getServiceState().getDataNetworkType(); |
| 5064 | } else { |
| 5065 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5066 | } |
| 5067 | } finally { |
| 5068 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5069 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5070 | } |
| 5071 | |
| 5072 | /** |
| 5073 | * Returns the data network type |
| 5074 | */ |
| 5075 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5076 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5077 | return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(), |
| 5078 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5079 | } |
| 5080 | |
| 5081 | /** |
| 5082 | * Returns the data network type for a subId |
| 5083 | */ |
| 5084 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5085 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5086 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5087 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5088 | mApp, subId, callingPackage, callingFeatureId, |
| 5089 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5090 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5091 | } |
| 5092 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5093 | final long identity = Binder.clearCallingIdentity(); |
| 5094 | try { |
| 5095 | final Phone phone = getPhone(subId); |
| 5096 | if (phone != null) { |
| 5097 | return phone.getServiceState().getDataNetworkType(); |
| 5098 | } else { |
| 5099 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5100 | } |
| 5101 | } finally { |
| 5102 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5103 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5104 | } |
| 5105 | |
| 5106 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5107 | * Returns the Voice network type for a subId |
| 5108 | */ |
| 5109 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5110 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5111 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5112 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5113 | mApp, subId, callingPackage, callingFeatureId, |
| 5114 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5115 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5116 | } |
| 5117 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5118 | final long identity = Binder.clearCallingIdentity(); |
| 5119 | try { |
| 5120 | final Phone phone = getPhone(subId); |
| 5121 | if (phone != null) { |
| 5122 | return phone.getServiceState().getVoiceNetworkType(); |
| 5123 | } else { |
| 5124 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5125 | } |
| 5126 | } finally { |
| 5127 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5128 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5129 | } |
| 5130 | |
| 5131 | /** |
| 5132 | * @return true if a ICC card is present |
| 5133 | */ |
| 5134 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5135 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5136 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 5137 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5138 | } |
| 5139 | |
| 5140 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5141 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5142 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5143 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5144 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5145 | final long identity = Binder.clearCallingIdentity(); |
| 5146 | try { |
| 5147 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5148 | if (phone != null) { |
| 5149 | return phone.getIccCard().hasIccCard(); |
| 5150 | } else { |
| 5151 | return false; |
| 5152 | } |
| 5153 | } finally { |
| 5154 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5155 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5156 | } |
| 5157 | |
| 5158 | /** |
| 5159 | * Return if the current radio is LTE on CDMA. This |
| 5160 | * is a tri-state return value as for a period of time |
| 5161 | * the mode may be unknown. |
| 5162 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5163 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5164 | * @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] | 5165 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5166 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5167 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5168 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5169 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5170 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5171 | } |
| 5172 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5173 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5174 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5175 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5176 | try { |
| 5177 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5178 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5179 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5180 | } |
| 5181 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5182 | final long identity = Binder.clearCallingIdentity(); |
| 5183 | try { |
| 5184 | final Phone phone = getPhone(subId); |
| 5185 | if (phone == null) { |
| 5186 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5187 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5188 | return TelephonyProperties.lte_on_cdma_device() |
| 5189 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5190 | } |
| 5191 | } finally { |
| 5192 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5193 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5194 | } |
| 5195 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5196 | /** |
| 5197 | * {@hide} |
| 5198 | * Returns Default subId, 0 in the case of single standby. |
| 5199 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5200 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5201 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5202 | } |
| 5203 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5204 | private int getSlotForDefaultSubscription() { |
| 5205 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 5206 | } |
| 5207 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5208 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5209 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5210 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5211 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5212 | private boolean isActiveSubscription(int subId) { |
| 5213 | return mSubscriptionController.isActiveSubId(subId); |
| 5214 | } |
| 5215 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5216 | /** |
| 5217 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5218 | */ |
| 5219 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5220 | final long identity = Binder.clearCallingIdentity(); |
| 5221 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5222 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5223 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5224 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5225 | } finally { |
| 5226 | Binder.restoreCallingIdentity(identity); |
| 5227 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5228 | } |
| 5229 | |
| 5230 | /** |
| 5231 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5232 | */ |
| 5233 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5234 | final long identity = Binder.clearCallingIdentity(); |
| 5235 | try { |
| 5236 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5237 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5238 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5239 | } finally { |
| 5240 | Binder.restoreCallingIdentity(identity); |
| 5241 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5242 | } |
| 5243 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5244 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5245 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5246 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5247 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5248 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5249 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 5250 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 5251 | if (phoneId == -1) { |
| 5252 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 5253 | + " does not correspond to an active phone"); |
| 5254 | } |
| 5255 | return PhoneFactory.getPhone(phoneId); |
| 5256 | } |
| 5257 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5258 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5259 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 5260 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5261 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5262 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5263 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5264 | if (DBG) { |
| 5265 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 5266 | } |
| 5267 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 5268 | p2); |
| 5269 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5270 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5271 | |
| 5272 | @Override |
| 5273 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 5274 | int slotIndex, String callingPackage, String aid, int p2) { |
| 5275 | enforceModifyPermission(); |
| 5276 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5277 | if (DBG) { |
| 5278 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 5279 | } |
| 5280 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 5281 | callingPackage, aid, p2); |
| 5282 | } |
| 5283 | |
| 5284 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 5285 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5286 | final long identity = Binder.clearCallingIdentity(); |
| 5287 | try { |
| 5288 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 5289 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5290 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5291 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5292 | if (bestComponent == null |
| 5293 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5294 | loge("The calling package is not allowed to access ISD-R."); |
| 5295 | throw new SecurityException( |
| 5296 | "The calling package is not allowed to access ISD-R."); |
| 5297 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5298 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5299 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5300 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5301 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 5302 | null /* workSource */); |
| 5303 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5304 | return response; |
| 5305 | } finally { |
| 5306 | Binder.restoreCallingIdentity(identity); |
| 5307 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5308 | } |
| 5309 | |
| 5310 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5311 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5312 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5313 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5314 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 5315 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 5316 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5317 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5318 | @Override |
| 5319 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 5320 | enforceModifyPermission(); |
| 5321 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 5322 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 5323 | channel); |
| 5324 | } |
| 5325 | |
| 5326 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5327 | final long identity = Binder.clearCallingIdentity(); |
| 5328 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5329 | if (channel < 0) { |
| 5330 | return false; |
| 5331 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5332 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 5333 | null /* workSource */); |
| 5334 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5335 | return success; |
| 5336 | } finally { |
| 5337 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5338 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5339 | } |
| 5340 | |
| 5341 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5342 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5343 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5344 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5345 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5346 | if (DBG) { |
| 5347 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5348 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5349 | + p3 + " data=" + data); |
| 5350 | } |
| 5351 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5352 | command, p1, p2, p3, data); |
| 5353 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5354 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5355 | @Override |
| 5356 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 5357 | int command, int p1, int p2, int p3, String data) { |
| 5358 | enforceModifyPermission(); |
| 5359 | if (DBG) { |
| 5360 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 5361 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5362 | + p3 + " data=" + data); |
| 5363 | } |
| 5364 | return iccTransmitApduLogicalChannelWithPermission( |
| 5365 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 5366 | data); |
| 5367 | } |
| 5368 | |
| 5369 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5370 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5371 | final long identity = Binder.clearCallingIdentity(); |
| 5372 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5373 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5374 | return ""; |
| 5375 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5376 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5377 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5378 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5379 | null /* workSource */); |
| 5380 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5381 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5382 | // Append the returned status code to the end of the response payload. |
| 5383 | String s = Integer.toHexString( |
| 5384 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5385 | if (response.payload != null) { |
| 5386 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5387 | } |
| 5388 | return s; |
| 5389 | } finally { |
| 5390 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5391 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5392 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5393 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5394 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5395 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5396 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5397 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5398 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5399 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5400 | if (DBG) { |
| 5401 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5402 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5403 | } |
| 5404 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5405 | cla, command, p1, p2, p3, data); |
| 5406 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5407 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5408 | @Override |
| 5409 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 5410 | int command, int p1, int p2, int p3, String data) { |
| 5411 | enforceModifyPermission(); |
| 5412 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5413 | if (DBG) { |
| 5414 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 5415 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 5416 | + " data=" + data); |
| 5417 | } |
| 5418 | |
| 5419 | return iccTransmitApduBasicChannelWithPermission( |
| 5420 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 5421 | p2, p3, data); |
| 5422 | } |
| 5423 | |
| 5424 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5425 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5426 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5427 | final long identity = Binder.clearCallingIdentity(); |
| 5428 | try { |
| 5429 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5430 | && TextUtils.equals(ISDR_AID, data)) { |
| 5431 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5432 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5433 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5434 | if (bestComponent == null |
| 5435 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5436 | loge("The calling package is not allowed to select ISD-R."); |
| 5437 | throw new SecurityException( |
| 5438 | "The calling package is not allowed to select ISD-R."); |
| 5439 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5440 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5441 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5442 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5443 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5444 | null /* workSource */); |
| 5445 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5446 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5447 | // Append the returned status code to the end of the response payload. |
| 5448 | String s = Integer.toHexString( |
| 5449 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5450 | if (response.payload != null) { |
| 5451 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5452 | } |
| 5453 | return s; |
| 5454 | } finally { |
| 5455 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5456 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5457 | } |
| 5458 | |
| 5459 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5460 | 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] | 5461 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5462 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5463 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5464 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5465 | final long identity = Binder.clearCallingIdentity(); |
| 5466 | try { |
| 5467 | if (DBG) { |
| 5468 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5469 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5470 | } |
| 5471 | |
| 5472 | IccIoResult response = |
| 5473 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5474 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5475 | subId); |
| 5476 | |
| 5477 | if (DBG) { |
| 5478 | log("Exchange SIM_IO [R]" + response); |
| 5479 | } |
| 5480 | |
| 5481 | byte[] result = null; |
| 5482 | int length = 2; |
| 5483 | if (response.payload != null) { |
| 5484 | length = 2 + response.payload.length; |
| 5485 | result = new byte[length]; |
| 5486 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5487 | } else { |
| 5488 | result = new byte[length]; |
| 5489 | } |
| 5490 | |
| 5491 | result[length - 1] = (byte) response.sw2; |
| 5492 | result[length - 2] = (byte) response.sw1; |
| 5493 | return result; |
| 5494 | } finally { |
| 5495 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5496 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5497 | } |
| 5498 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5499 | /** |
| 5500 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5501 | * on a particular subscription |
| 5502 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5503 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5504 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5505 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5506 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5507 | return null; |
| 5508 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5509 | |
| 5510 | final long identity = Binder.clearCallingIdentity(); |
| 5511 | try { |
| 5512 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5513 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5514 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5515 | return null; |
| 5516 | } |
| 5517 | Object response = sendRequest( |
| 5518 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5519 | if (response instanceof String[]) { |
| 5520 | return (String[]) response; |
| 5521 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5522 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5523 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5524 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5525 | } finally { |
| 5526 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5527 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5528 | } |
| 5529 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5530 | /** |
| 5531 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5532 | * subscription. |
| 5533 | * |
| 5534 | * @param subId the id of the subscription. |
| 5535 | * @param appType the uicc app type, must be USIM or SIM. |
| 5536 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5537 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5538 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5539 | * @return number of fplmns that is successfully written to the SIM. |
| 5540 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5541 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5542 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5543 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5544 | mApp, subId, "setForbiddenPlmns"); |
| 5545 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5546 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5547 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5548 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5549 | } |
| 5550 | if (fplmns == null) { |
| 5551 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5552 | } |
| 5553 | for (String fplmn : fplmns) { |
| 5554 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5555 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5556 | } |
| 5557 | } |
| 5558 | final long identity = Binder.clearCallingIdentity(); |
| 5559 | try { |
| 5560 | Object response = sendRequest( |
| 5561 | CMD_SET_FORBIDDEN_PLMNS, |
| 5562 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5563 | subId); |
| 5564 | return (int) response; |
| 5565 | } finally { |
| 5566 | Binder.restoreCallingIdentity(identity); |
| 5567 | } |
| 5568 | } |
| 5569 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5570 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5571 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5572 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5573 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5574 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5575 | final long identity = Binder.clearCallingIdentity(); |
| 5576 | try { |
| 5577 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5578 | if (response.payload == null) { |
| 5579 | return ""; |
| 5580 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5581 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5582 | // Append the returned status code to the end of the response payload. |
| 5583 | String s = Integer.toHexString( |
| 5584 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5585 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5586 | return s; |
| 5587 | } finally { |
| 5588 | Binder.restoreCallingIdentity(identity); |
| 5589 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5590 | } |
| 5591 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5592 | /** |
| 5593 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5594 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5595 | * |
| 5596 | * @param itemID the ID of the item to read |
| 5597 | * @return the NV item as a String, or null on error. |
| 5598 | */ |
| 5599 | @Override |
| 5600 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5601 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5602 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5603 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5604 | |
| 5605 | final long identity = Binder.clearCallingIdentity(); |
| 5606 | try { |
| 5607 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5608 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5609 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5610 | return value; |
| 5611 | } finally { |
| 5612 | Binder.restoreCallingIdentity(identity); |
| 5613 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5614 | } |
| 5615 | |
| 5616 | /** |
| 5617 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5618 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5619 | * |
| 5620 | * @param itemID the ID of the item to read |
| 5621 | * @param itemValue the value to write, as a String |
| 5622 | * @return true on success; false on any failure |
| 5623 | */ |
| 5624 | @Override |
| 5625 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5626 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5627 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5628 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5629 | |
| 5630 | final long identity = Binder.clearCallingIdentity(); |
| 5631 | try { |
| 5632 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5633 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5634 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5635 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5636 | return success; |
| 5637 | } finally { |
| 5638 | Binder.restoreCallingIdentity(identity); |
| 5639 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5640 | } |
| 5641 | |
| 5642 | /** |
| 5643 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5644 | * Used for device configuration by some CDMA operators. |
| 5645 | * |
| 5646 | * @param preferredRoamingList byte array containing the new PRL |
| 5647 | * @return true on success; false on any failure |
| 5648 | */ |
| 5649 | @Override |
| 5650 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5651 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5652 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5653 | |
| 5654 | final long identity = Binder.clearCallingIdentity(); |
| 5655 | try { |
| 5656 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5657 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5658 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5659 | return success; |
| 5660 | } finally { |
| 5661 | Binder.restoreCallingIdentity(identity); |
| 5662 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5663 | } |
| 5664 | |
| 5665 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5666 | * 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] | 5667 | * Used for device configuration by some CDMA operators. |
| 5668 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5669 | * @param slotIndex - device slot. |
| 5670 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5671 | * @return true on success; false on any failure |
| 5672 | */ |
| 5673 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5674 | public boolean resetModemConfig(int slotIndex) { |
| 5675 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5676 | if (phone != null) { |
| 5677 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5678 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5679 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5680 | final long identity = Binder.clearCallingIdentity(); |
| 5681 | try { |
| 5682 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5683 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5684 | return success; |
| 5685 | } finally { |
| 5686 | Binder.restoreCallingIdentity(identity); |
| 5687 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5688 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5689 | return false; |
| 5690 | } |
| 5691 | |
| 5692 | /** |
| 5693 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5694 | * |
| 5695 | * @param slotIndex - device slot. |
| 5696 | * |
| 5697 | * @return true on success; false on any failure |
| 5698 | */ |
| 5699 | @Override |
| 5700 | public boolean rebootModem(int slotIndex) { |
| 5701 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5702 | if (phone != null) { |
| 5703 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5704 | mApp, phone.getSubId(), "rebootModem"); |
| 5705 | |
| 5706 | final long identity = Binder.clearCallingIdentity(); |
| 5707 | try { |
| 5708 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5709 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5710 | return success; |
| 5711 | } finally { |
| 5712 | Binder.restoreCallingIdentity(identity); |
| 5713 | } |
| 5714 | } |
| 5715 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5716 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5717 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5718 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5719 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5720 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5721 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5722 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5723 | return new String[0]; |
| 5724 | } |
| 5725 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5726 | final long identity = Binder.clearCallingIdentity(); |
| 5727 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5728 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5729 | } finally { |
| 5730 | Binder.restoreCallingIdentity(identity); |
| 5731 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5732 | } |
| 5733 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5734 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5735 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5736 | * {@link #disableIms(int)}. |
| 5737 | * @param slotIndex device slot. |
| 5738 | */ |
| 5739 | public void resetIms(int slotIndex) { |
| 5740 | enforceModifyPermission(); |
| 5741 | |
| 5742 | final long identity = Binder.clearCallingIdentity(); |
| 5743 | try { |
| 5744 | if (mImsResolver == null) { |
| 5745 | // may happen if the does not support IMS. |
| 5746 | return; |
| 5747 | } |
| 5748 | mImsResolver.disableIms(slotIndex); |
| 5749 | mImsResolver.enableIms(slotIndex); |
| 5750 | } finally { |
| 5751 | Binder.restoreCallingIdentity(identity); |
| 5752 | } |
| 5753 | } |
| 5754 | |
| 5755 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5756 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5757 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5758 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5759 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5760 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5761 | |
| 5762 | final long identity = Binder.clearCallingIdentity(); |
| 5763 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5764 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5765 | // may happen if the device does not support IMS. |
| 5766 | return; |
| 5767 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5768 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5769 | } finally { |
| 5770 | Binder.restoreCallingIdentity(identity); |
| 5771 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5772 | } |
| 5773 | |
| 5774 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5775 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5776 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5777 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5778 | public void disableIms(int slotId) { |
| 5779 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5780 | |
| 5781 | final long identity = Binder.clearCallingIdentity(); |
| 5782 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5783 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5784 | // may happen if the device does not support IMS. |
| 5785 | return; |
| 5786 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5787 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5788 | } finally { |
| 5789 | Binder.restoreCallingIdentity(identity); |
| 5790 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5791 | } |
| 5792 | |
| 5793 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5794 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5795 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5796 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5797 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5798 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5799 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5800 | |
| 5801 | final long identity = Binder.clearCallingIdentity(); |
| 5802 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5803 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5804 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5805 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5806 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5807 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5808 | } finally { |
| 5809 | Binder.restoreCallingIdentity(identity); |
| 5810 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5811 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5812 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5813 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5814 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5815 | @Override |
| 5816 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5817 | enforceModifyPermission(); |
| 5818 | |
| 5819 | final long identity = Binder.clearCallingIdentity(); |
| 5820 | try { |
| 5821 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5822 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5823 | } finally { |
| 5824 | Binder.restoreCallingIdentity(identity); |
| 5825 | } |
| 5826 | } |
| 5827 | |
| 5828 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5829 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5830 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5831 | */ |
| 5832 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5833 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5834 | |
| 5835 | final long identity = Binder.clearCallingIdentity(); |
| 5836 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5837 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5838 | // may happen if the device does not support IMS. |
| 5839 | return null; |
| 5840 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5841 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5842 | } finally { |
| 5843 | Binder.restoreCallingIdentity(identity); |
| 5844 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5845 | } |
| 5846 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5847 | /** |
| 5848 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5849 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5850 | */ |
| 5851 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5852 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5853 | |
| 5854 | final long identity = Binder.clearCallingIdentity(); |
| 5855 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5856 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5857 | // may happen if the device does not support IMS. |
| 5858 | return null; |
| 5859 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5860 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5861 | } finally { |
| 5862 | Binder.restoreCallingIdentity(identity); |
| 5863 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5864 | } |
| 5865 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5866 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5867 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5868 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5869 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5870 | * @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] | 5871 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5872 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5873 | * @param packageName The name of the package that the current configuration will be replaced |
| 5874 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5875 | * @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] | 5876 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5877 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5878 | int[] featureTypes, String packageName) { |
| 5879 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5880 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5881 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5882 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5883 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5884 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5885 | final long identity = Binder.clearCallingIdentity(); |
| 5886 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5887 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5888 | // may happen if the device does not support IMS. |
| 5889 | return false; |
| 5890 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5891 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5892 | for (int featureType : featureTypes) { |
| 5893 | featureConfig.put(featureType, packageName); |
| 5894 | } |
| 5895 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5896 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5897 | } finally { |
| 5898 | Binder.restoreCallingIdentity(identity); |
| 5899 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5900 | } |
| 5901 | |
| 5902 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5903 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5904 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5905 | * |
| 5906 | * This should only be used for testing. |
| 5907 | * |
| 5908 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5909 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5910 | */ |
| 5911 | @Override |
| 5912 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5913 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5914 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5915 | "clearCarrierImsServiceOverride"); |
| 5916 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5917 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5918 | "clearCarrierImsServiceOverride"); |
| 5919 | |
| 5920 | final long identity = Binder.clearCallingIdentity(); |
| 5921 | try { |
| 5922 | if (mImsResolver == null) { |
| 5923 | // may happen if the device does not support IMS. |
| 5924 | return false; |
| 5925 | } |
| 5926 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5927 | } finally { |
| 5928 | Binder.restoreCallingIdentity(identity); |
| 5929 | } |
| 5930 | } |
| 5931 | |
| 5932 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5933 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5934 | * |
| 5935 | * @param slotId The slot that the ImsService is associated with. |
| 5936 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5937 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5938 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5939 | * @return the package name of the ImsService configuration. |
| 5940 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5941 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5942 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5943 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5944 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5945 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5946 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5947 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5948 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5949 | final long identity = Binder.clearCallingIdentity(); |
| 5950 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5951 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5952 | // may happen if the device does not support IMS. |
| 5953 | return ""; |
| 5954 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5955 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5956 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5957 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5958 | } finally { |
| 5959 | Binder.restoreCallingIdentity(identity); |
| 5960 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5961 | } |
| 5962 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5963 | /** |
| 5964 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5965 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5966 | * @param callback A callback with an integer containing the |
| 5967 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5968 | */ |
| 5969 | @Override |
| 5970 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5971 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5972 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5973 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5974 | "IMS not available on device."); |
| 5975 | } |
| 5976 | final long token = Binder.clearCallingIdentity(); |
| 5977 | try { |
| 5978 | int slotId = getSlotIndex(subId); |
| 5979 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5980 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5981 | + subId + "'"); |
| 5982 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5983 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5984 | verifyImsMmTelConfiguredOrThrow(slotId); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5985 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5986 | try { |
| 5987 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5988 | } catch (RemoteException e) { |
| 5989 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5990 | + "Ignore"); |
| 5991 | } |
| 5992 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5993 | } catch (ImsException e) { |
| 5994 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5995 | } finally { |
| 5996 | Binder.restoreCallingIdentity(token); |
| 5997 | } |
| 5998 | } |
| 5999 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6000 | /** |
| 6001 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6002 | */ |
| 6003 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6004 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6005 | |
| 6006 | final long identity = Binder.clearCallingIdentity(); |
| 6007 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6008 | // NOTE: Before S, this method only set the default phone. |
| 6009 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6010 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6011 | phone.setImsRegistrationState(registered); |
| 6012 | } |
| 6013 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6014 | } finally { |
| 6015 | Binder.restoreCallingIdentity(identity); |
| 6016 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6017 | } |
| 6018 | |
| 6019 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6020 | * Set the network selection mode to automatic. |
| 6021 | * |
| 6022 | */ |
| 6023 | @Override |
| 6024 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6025 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6026 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6027 | |
| 6028 | final long identity = Binder.clearCallingIdentity(); |
| 6029 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6030 | if (!isActiveSubscription(subId)) { |
| 6031 | return; |
| 6032 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6033 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6034 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6035 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6036 | } finally { |
| 6037 | Binder.restoreCallingIdentity(identity); |
| 6038 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6039 | } |
| 6040 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6041 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6042 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6043 | * |
| 6044 | * @param subId the id of the subscription. |
| 6045 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6046 | * the operator to attach to. |
| 6047 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6048 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6049 | * normal network selection next time. |
| 6050 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6051 | */ |
| 6052 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6053 | public boolean setNetworkSelectionModeManual( |
| 6054 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6055 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6056 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6057 | |
| 6058 | if (!isActiveSubscription(subId)) { |
| 6059 | return false; |
| 6060 | } |
| 6061 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6062 | final long identity = Binder.clearCallingIdentity(); |
| 6063 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6064 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6065 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6066 | if (DBG) { |
| 6067 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6068 | + " operator: " + operatorInfo); |
| 6069 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6070 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6071 | } finally { |
| 6072 | Binder.restoreCallingIdentity(identity); |
| 6073 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6074 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6075 | /** |
| 6076 | * Get the manual network selection |
| 6077 | * |
| 6078 | * @param subId the id of the subscription. |
| 6079 | * |
| 6080 | * @return the previously saved user selected PLMN |
| 6081 | */ |
| 6082 | @Override |
| 6083 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6084 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6085 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6086 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 6087 | |
| 6088 | final long identity = Binder.clearCallingIdentity(); |
| 6089 | try { |
| 6090 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6091 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6092 | } |
| 6093 | |
| 6094 | final Phone phone = getPhone(subId); |
| 6095 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6096 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6097 | } |
| 6098 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6099 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6100 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6101 | } finally { |
| 6102 | Binder.restoreCallingIdentity(identity); |
| 6103 | } |
| 6104 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6105 | |
| 6106 | /** |
| 6107 | * Scans for available networks. |
| 6108 | */ |
| 6109 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6110 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6111 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6112 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6113 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6114 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6115 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6116 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6117 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6118 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6119 | .setCallingPid(Binder.getCallingPid()) |
| 6120 | .setCallingUid(Binder.getCallingUid()) |
| 6121 | .setMethod("getCellNetworkScanResults") |
| 6122 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6123 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6124 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6125 | .build()); |
| 6126 | switch (locationResult) { |
| 6127 | case DENIED_HARD: |
| 6128 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6129 | case DENIED_SOFT: |
| 6130 | return null; |
| 6131 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6132 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6133 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6134 | try { |
| 6135 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6136 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6137 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6138 | } finally { |
| 6139 | Binder.restoreCallingIdentity(identity); |
| 6140 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6141 | } |
| 6142 | |
| 6143 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6144 | * Get the call forwarding info, given the call forwarding reason. |
| 6145 | */ |
| 6146 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6147 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6148 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6149 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6150 | long identity = Binder.clearCallingIdentity(); |
| 6151 | try { |
| 6152 | if (DBG) { |
| 6153 | log("getCallForwarding: subId " + subId |
| 6154 | + " callForwardingReason" + callForwardingReason); |
| 6155 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6156 | |
| 6157 | Phone phone = getPhone(subId); |
| 6158 | if (phone == null) { |
| 6159 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6160 | callback.onError( |
| 6161 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6162 | } catch (RemoteException e) { |
| 6163 | // ignore |
| 6164 | } |
| 6165 | return; |
| 6166 | } |
| 6167 | |
| 6168 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6169 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6170 | @Override |
| 6171 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6172 | try { |
| 6173 | callback.onCallForwardingInfoAvailable(info); |
| 6174 | } catch (RemoteException e) { |
| 6175 | // ignore |
| 6176 | } |
| 6177 | } |
| 6178 | |
| 6179 | @Override |
| 6180 | public void onError(int error) { |
| 6181 | try { |
| 6182 | callback.onError(error); |
| 6183 | } catch (RemoteException e) { |
| 6184 | // ignore |
| 6185 | } |
| 6186 | } |
| 6187 | }); |
| 6188 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6189 | } finally { |
| 6190 | Binder.restoreCallingIdentity(identity); |
| 6191 | } |
| 6192 | } |
| 6193 | |
| 6194 | /** |
| 6195 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6196 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6197 | */ |
| 6198 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6199 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6200 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6201 | enforceModifyPermission(); |
| 6202 | long identity = Binder.clearCallingIdentity(); |
| 6203 | try { |
| 6204 | if (DBG) { |
| 6205 | log("setCallForwarding: subId " + subId |
| 6206 | + " callForwardingInfo" + callForwardingInfo); |
| 6207 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6208 | |
| 6209 | Phone phone = getPhone(subId); |
| 6210 | if (phone == null) { |
| 6211 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6212 | callback.accept( |
| 6213 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6214 | } catch (RemoteException e) { |
| 6215 | // ignore |
| 6216 | } |
| 6217 | return; |
| 6218 | } |
| 6219 | |
| 6220 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6221 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6222 | |
| 6223 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6224 | } finally { |
| 6225 | Binder.restoreCallingIdentity(identity); |
| 6226 | } |
| 6227 | } |
| 6228 | |
| 6229 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6230 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6231 | */ |
| 6232 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6233 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6234 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6235 | long identity = Binder.clearCallingIdentity(); |
| 6236 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6237 | Phone phone = getPhone(subId); |
| 6238 | if (phone == null) { |
| 6239 | try { |
| 6240 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6241 | } catch (RemoteException e) { |
| 6242 | // ignore |
| 6243 | } |
| 6244 | return; |
| 6245 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6246 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6247 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6248 | boolean requireUssd = c.getBoolean( |
| 6249 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6250 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6251 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6252 | if (requireUssd) { |
| 6253 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6254 | getSubscriptionCarrierId(subId)); |
| 6255 | String newUssdCommand = ""; |
| 6256 | try { |
| 6257 | newUssdCommand = carrierXmlParser.getFeature( |
| 6258 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6259 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6260 | } catch (NullPointerException e) { |
| 6261 | loge("Failed to generate USSD number" + e); |
| 6262 | } |
| 6263 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6264 | mMainThreadHandler, callback, carrierXmlParser, |
| 6265 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6266 | final String ussdCommand = newUssdCommand; |
| 6267 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6268 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6269 | }); |
| 6270 | } else { |
| 6271 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6272 | callback::accept); |
| 6273 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6274 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6275 | } finally { |
| 6276 | Binder.restoreCallingIdentity(identity); |
| 6277 | } |
| 6278 | } |
| 6279 | |
| 6280 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6281 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6282 | */ |
| 6283 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6284 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6285 | enforceModifyPermission(); |
| 6286 | long identity = Binder.clearCallingIdentity(); |
| 6287 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6288 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6289 | |
| 6290 | Phone phone = getPhone(subId); |
| 6291 | if (phone == null) { |
| 6292 | try { |
| 6293 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6294 | } catch (RemoteException e) { |
| 6295 | // ignore |
| 6296 | } |
| 6297 | return; |
| 6298 | } |
| 6299 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6300 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6301 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6302 | boolean requireUssd = c.getBoolean( |
| 6303 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6304 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6305 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6306 | if (requireUssd) { |
| 6307 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6308 | getSubscriptionCarrierId(subId)); |
| 6309 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6310 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6311 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6312 | String newUssdCommand = ""; |
| 6313 | try { |
| 6314 | newUssdCommand = carrierXmlParser.getFeature( |
| 6315 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6316 | .makeCommand(ssAction, null); |
| 6317 | } catch (NullPointerException e) { |
| 6318 | loge("Failed to generate USSD number" + e); |
| 6319 | } |
| 6320 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6321 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6322 | final String ussdCommand = newUssdCommand; |
| 6323 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6324 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6325 | }); |
| 6326 | } else { |
| 6327 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6328 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6329 | |
| 6330 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6331 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6332 | } finally { |
| 6333 | Binder.restoreCallingIdentity(identity); |
| 6334 | } |
| 6335 | } |
| 6336 | |
| 6337 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6338 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6339 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6340 | * @param subId id of the subscription |
| 6341 | * @param request contains the radio access networks with bands/channels to scan |
| 6342 | * @param messenger callback messenger for scan results or errors |
| 6343 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6344 | * @return the id of the requested scan which can be used to stop the scan. |
| 6345 | */ |
| 6346 | @Override |
| 6347 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6348 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6349 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6350 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6351 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6352 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6353 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6354 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6355 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6356 | .setCallingPid(Binder.getCallingPid()) |
| 6357 | .setCallingUid(Binder.getCallingUid()) |
| 6358 | .setMethod("requestNetworkScan") |
| 6359 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
James.cf Lin | 1d4d739 | 2020-07-03 18:22:53 +0800 | [diff] [blame] | 6360 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6361 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6362 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6363 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6364 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6365 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6366 | if (e != null) { |
| 6367 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6368 | throw e; |
| 6369 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6370 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6371 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6372 | } |
| 6373 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6374 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6375 | int callingUid = Binder.getCallingUid(); |
| 6376 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6377 | final long identity = Binder.clearCallingIdentity(); |
| 6378 | try { |
| 6379 | return mNetworkScanRequestTracker.startNetworkScan( |
| 6380 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6381 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6382 | } finally { |
| 6383 | Binder.restoreCallingIdentity(identity); |
| 6384 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6385 | } |
| 6386 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6387 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6388 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6389 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6390 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6391 | boolean hasNetworkScanPermission = |
| 6392 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6393 | == PERMISSION_GRANTED; |
| 6394 | |
| 6395 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6396 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6397 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6398 | } |
| 6399 | |
| 6400 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6401 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6402 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6403 | return new SecurityException("Specific channels must not be" |
| 6404 | + " scanned without location access."); |
| 6405 | } |
| 6406 | } |
| 6407 | } |
| 6408 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6409 | return null; |
| 6410 | } |
| 6411 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6412 | /** |
| 6413 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6414 | * |
| 6415 | * @param subId id of the subscription |
| 6416 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6417 | */ |
| 6418 | @Override |
| 6419 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6420 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6421 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6422 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6423 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6424 | final long identity = Binder.clearCallingIdentity(); |
| 6425 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6426 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6427 | } finally { |
| 6428 | Binder.restoreCallingIdentity(identity); |
| 6429 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6430 | } |
| 6431 | |
| 6432 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6433 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6434 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6435 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6436 | */ |
| 6437 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6438 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6439 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6440 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6441 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6442 | |
| 6443 | final long identity = Binder.clearCallingIdentity(); |
| 6444 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6445 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6446 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6447 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6448 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6449 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6450 | } finally { |
| 6451 | Binder.restoreCallingIdentity(identity); |
| 6452 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6453 | } |
| 6454 | |
| 6455 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6456 | * Get the allowed network types for certain reason. |
| 6457 | * |
| 6458 | * @param subId the id of the subscription. |
| 6459 | * @param reason the reason the allowed network type change is taking place |
| 6460 | * @return the allowed network types. |
| 6461 | */ |
| 6462 | @Override |
| 6463 | public long getAllowedNetworkTypesForReason(int subId, |
| 6464 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6465 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6466 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6467 | final long identity = Binder.clearCallingIdentity(); |
| 6468 | try { |
| 6469 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6470 | } finally { |
| 6471 | Binder.restoreCallingIdentity(identity); |
| 6472 | } |
| 6473 | } |
| 6474 | |
| 6475 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6476 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6477 | * @param subId subscription id of the sim card |
| 6478 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6479 | * This can be passed following states |
| 6480 | * <ol> |
| 6481 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6482 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6483 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6484 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6485 | * </ol> |
| 6486 | * @return operation result. |
| 6487 | */ |
| 6488 | @Override |
| 6489 | public int setNrDualConnectivityState(int subId, |
| 6490 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6491 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6492 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6493 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6494 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6495 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6496 | } |
| 6497 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6498 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6499 | final long identity = Binder.clearCallingIdentity(); |
| 6500 | try { |
| 6501 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6502 | nrDualConnectivityState, subId, |
| 6503 | workSource); |
| 6504 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6505 | return result; |
| 6506 | } finally { |
| 6507 | Binder.restoreCallingIdentity(identity); |
| 6508 | } |
| 6509 | } |
| 6510 | |
| 6511 | /** |
| 6512 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6513 | * @return true if dual connectivity is enabled else false |
| 6514 | */ |
| 6515 | @Override |
| 6516 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6517 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6518 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6519 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6520 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6521 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6522 | return false; |
| 6523 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6524 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6525 | final long identity = Binder.clearCallingIdentity(); |
| 6526 | try { |
| 6527 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6528 | null, subId, workSource); |
| 6529 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6530 | return isEnabled; |
| 6531 | } finally { |
| 6532 | Binder.restoreCallingIdentity(identity); |
| 6533 | } |
| 6534 | } |
| 6535 | |
| 6536 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6537 | * Set the allowed network types of the device and |
| 6538 | * provide the reason triggering the allowed network change. |
| 6539 | * |
| 6540 | * @param subId the id of the subscription. |
| 6541 | * @param reason the reason the allowed network type change is taking place |
| 6542 | * @param allowedNetworkTypes the allowed network types. |
| 6543 | * @return true on success; false on any failure. |
| 6544 | */ |
| 6545 | @Override |
| 6546 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6547 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6548 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6549 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6550 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6551 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6552 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6553 | return false; |
| 6554 | } |
| 6555 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6556 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6557 | return false; |
| 6558 | } |
| 6559 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6560 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6561 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6562 | |
| 6563 | |
| 6564 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6565 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6566 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6567 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6568 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6569 | final long identity = Binder.clearCallingIdentity(); |
| 6570 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6571 | Boolean success = (Boolean) sendRequest( |
| 6572 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6573 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6574 | |
| 6575 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6576 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6577 | } finally { |
| 6578 | Binder.restoreCallingIdentity(identity); |
| 6579 | } |
| 6580 | } |
| 6581 | |
| 6582 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6583 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6584 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6585 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6586 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6587 | * @hide |
| 6588 | */ |
| 6589 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6590 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6591 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6592 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6593 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6594 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6595 | if (phone != null) { |
| 6596 | return phone.hasMatchedTetherApnSetting(); |
| 6597 | } else { |
| 6598 | return false; |
| 6599 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6600 | } finally { |
| 6601 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6602 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6603 | } |
| 6604 | |
| 6605 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6606 | * Enable or disable always reporting signal strength changes from radio. |
| 6607 | * |
| 6608 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6609 | */ |
| 6610 | @Override |
| 6611 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6612 | enforceModifyPermission(); |
| 6613 | enforceSystemCaller(); |
| 6614 | |
| 6615 | final long identity = Binder.clearCallingIdentity(); |
| 6616 | final Phone phone = getPhone(subId); |
| 6617 | try { |
| 6618 | if (phone != null) { |
| 6619 | if (DBG) { |
| 6620 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6621 | + " isEnable=" + isEnable); |
| 6622 | } |
| 6623 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6624 | } else { |
| 6625 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6626 | + subId); |
| 6627 | } |
| 6628 | } finally { |
| 6629 | Binder.restoreCallingIdentity(identity); |
| 6630 | } |
| 6631 | } |
| 6632 | |
| 6633 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6634 | * Get the user enabled state of Mobile Data. |
| 6635 | * |
| 6636 | * TODO: remove and use isUserDataEnabled. |
| 6637 | * This can't be removed now because some vendor codes |
| 6638 | * calls through ITelephony directly while they should |
| 6639 | * use TelephonyManager. |
| 6640 | * |
| 6641 | * @return true on enabled |
| 6642 | */ |
| 6643 | @Override |
| 6644 | public boolean getDataEnabled(int subId) { |
| 6645 | return isUserDataEnabled(subId); |
| 6646 | } |
| 6647 | |
| 6648 | /** |
| 6649 | * Get whether mobile data is enabled per user setting. |
| 6650 | * |
| 6651 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6652 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6653 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6654 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6655 | * |
| 6656 | * @return {@code true} if data is enabled else {@code false} |
| 6657 | */ |
| 6658 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6659 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6660 | try { |
| 6661 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6662 | null); |
| 6663 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6664 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6665 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6666 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6667 | |
| 6668 | final long identity = Binder.clearCallingIdentity(); |
| 6669 | try { |
| 6670 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6671 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6672 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6673 | if (phone != null) { |
| 6674 | boolean retVal = phone.isUserDataEnabled(); |
| 6675 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6676 | return retVal; |
| 6677 | } else { |
| 6678 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6679 | return false; |
| 6680 | } |
| 6681 | } finally { |
| 6682 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6683 | } |
| 6684 | } |
| 6685 | |
| 6686 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6687 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6688 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6689 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6690 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6691 | * @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] | 6692 | */ |
| 6693 | @Override |
| 6694 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6695 | try { |
| 6696 | try { |
| 6697 | mApp.enforceCallingOrSelfPermission( |
| 6698 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6699 | null); |
| 6700 | } catch (Exception e) { |
| 6701 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6702 | "isDataEnabled"); |
| 6703 | } |
| 6704 | } catch (Exception e) { |
| 6705 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6706 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6707 | |
| 6708 | final long identity = Binder.clearCallingIdentity(); |
| 6709 | try { |
| 6710 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6711 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6712 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6713 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6714 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6715 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6716 | return retVal; |
| 6717 | } else { |
| 6718 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6719 | return false; |
| 6720 | } |
| 6721 | } finally { |
| 6722 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6723 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6724 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6725 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6726 | /** |
| 6727 | * Check if data is enabled for a specific reason |
| 6728 | * @param subId Subscription index |
| 6729 | * @param reason the reason the data enable change is taking place |
| 6730 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6731 | */ |
| 6732 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6733 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6734 | @TelephonyManager.DataEnabledReason int reason) { |
| 6735 | try { |
| 6736 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6737 | null); |
| 6738 | } catch (Exception e) { |
| 6739 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6740 | "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6741 | } |
| 6742 | |
| 6743 | |
| 6744 | final long identity = Binder.clearCallingIdentity(); |
| 6745 | try { |
| 6746 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6747 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6748 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6749 | + " reason=" + reason); |
| 6750 | } |
| 6751 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6752 | if (phone != null) { |
| 6753 | boolean retVal; |
| 6754 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6755 | retVal = phone.isUserDataEnabled(); |
| 6756 | } else { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6757 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6758 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6759 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6760 | return retVal; |
| 6761 | } else { |
| 6762 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6763 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6764 | + subId + " retVal=false"); |
| 6765 | } |
| 6766 | return false; |
| 6767 | } |
| 6768 | } finally { |
| 6769 | Binder.restoreCallingIdentity(identity); |
| 6770 | } |
| 6771 | } |
| 6772 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6773 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6774 | Phone phone) { |
Sarah Chin | 3394efe | 2021-04-09 10:37:15 -0700 | [diff] [blame] | 6775 | if (uid == Process.PHONE_UID) { |
| 6776 | // Skip the check if it's the phone UID (system UID removed in b/184713596) |
| 6777 | // 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] | 6778 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6779 | } |
| 6780 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6781 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6782 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6783 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6784 | || subController == null) return privilegeFromSim; |
| 6785 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6786 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6787 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6788 | |
| 6789 | final long identity = Binder.clearCallingIdentity(); |
| 6790 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6791 | int subId = phone.getSubId(); |
| 6792 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6793 | // A test override is in place for the privileges for this subId, so don't try to |
| 6794 | // read the subscription privileges. |
| 6795 | return privilegeFromSim; |
| 6796 | } |
| 6797 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6798 | SubscriptionManager subManager = (SubscriptionManager) |
| 6799 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6800 | for (String pkg : packages) { |
| 6801 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6802 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6803 | } |
| 6804 | } |
| 6805 | return privilegeFromSim; |
| 6806 | } finally { |
| 6807 | Binder.restoreCallingIdentity(identity); |
| 6808 | } |
| 6809 | } |
| 6810 | |
| 6811 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6812 | String pkgName) { |
| 6813 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6814 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6815 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6816 | || subController == null) return privilegeFromSim; |
| 6817 | |
| 6818 | final long identity = Binder.clearCallingIdentity(); |
| 6819 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6820 | int subId = phone.getSubId(); |
| 6821 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6822 | // A test override is in place for the privileges for this subId, so don't try to |
| 6823 | // read the subscription privileges. |
| 6824 | return privilegeFromSim; |
| 6825 | } |
| 6826 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6827 | SubscriptionManager subManager = (SubscriptionManager) |
| 6828 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6829 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6830 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6831 | } finally { |
| 6832 | Binder.restoreCallingIdentity(identity); |
| 6833 | } |
| 6834 | } |
| 6835 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6836 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6837 | public int getCarrierPrivilegeStatus(int subId) { |
| 6838 | final Phone phone = getPhone(subId); |
| 6839 | if (phone == null) { |
| 6840 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6841 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6842 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6843 | UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
| 6844 | if (port == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6845 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6846 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6847 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6848 | |
| 6849 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6850 | port.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6851 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6852 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6853 | |
| 6854 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6855 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6856 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6857 | final Phone phone = getPhone(subId); |
| 6858 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6859 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6860 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6861 | } |
| 6862 | UiccProfile profile = |
| 6863 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6864 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6865 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6866 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6867 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6868 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6869 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6870 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6871 | } |
| 6872 | |
| 6873 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6874 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6875 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6876 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6877 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6878 | } |
| 6879 | |
| 6880 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6881 | UiccPort port = UiccController.getInstance().getUiccPort(phoneId); |
| 6882 | if (port == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6883 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6884 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6885 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6886 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6887 | port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6888 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6889 | } |
| 6890 | |
| 6891 | @Override |
| 6892 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Sarah Chin | fc3169b | 2021-04-28 20:21:03 -0700 | [diff] [blame] | 6893 | // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6894 | if (TextUtils.isEmpty(pkgName)) |
| 6895 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6896 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6897 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6898 | UiccPort port = UiccController.getInstance().getUiccPort(i); |
| 6899 | if (port == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6900 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6901 | continue; |
| 6902 | } |
| 6903 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6904 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6905 | port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6906 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6907 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6908 | break; |
| 6909 | } |
| 6910 | } |
| 6911 | |
| 6912 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6913 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6914 | |
| 6915 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6916 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6917 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6918 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6919 | loge("phoneId " + phoneId + " is not valid."); |
| 6920 | return null; |
| 6921 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6922 | UiccPort port = UiccController.getInstance().getUiccPort(phoneId); |
| 6923 | if (port == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6924 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6925 | return null ; |
| 6926 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6927 | return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6928 | } |
| 6929 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6930 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6931 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6932 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6933 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6934 | List<String> privilegedPackages = new ArrayList<>(); |
| 6935 | List<PackageInfo> packages = null; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6936 | UiccPort port = UiccController.getInstance().getUiccPort(phoneId); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6937 | // has UICC in that slot. |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6938 | if (port != null) { |
| 6939 | if (port.hasCarrierPrivilegeRules()) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6940 | if (packages == null) { |
| 6941 | // Only check packages in user 0 for now |
| 6942 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6943 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6944 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6945 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6946 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6947 | } |
| 6948 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6949 | PackageInfo pkgInfo = packages.get(p); |
| 6950 | if (pkgInfo != null && pkgInfo.packageName != null |
Sooraj Sasindran | 97bce6f | 2021-09-28 21:37:29 +0000 | [diff] [blame] | 6951 | && getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6952 | port.getCarrierPrivilegeStatus(pkgInfo), |
| 6953 | getPhone(phoneId), pkgInfo.packageName) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6954 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6955 | privilegedPackages.add(pkgInfo.packageName); |
| 6956 | } |
| 6957 | } |
| 6958 | } |
| 6959 | } |
| 6960 | return privilegedPackages; |
| 6961 | } |
| 6962 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6963 | @Override |
| 6964 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6965 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6966 | |
| 6967 | final long identity = Binder.clearCallingIdentity(); |
| 6968 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6969 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6970 | try { |
| 6971 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6972 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6973 | } |
| 6974 | } finally { |
| 6975 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6976 | } |
| 6977 | return privilegedPackages; |
| 6978 | } |
| 6979 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6980 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6981 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6982 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 6983 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6984 | return null; |
| 6985 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6986 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6987 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6988 | return null; |
| 6989 | } |
| 6990 | return iccId; |
| 6991 | } |
| 6992 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6993 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6994 | public void setCallComposerStatus(int subId, int status) { |
| 6995 | enforceModifyPermission(); |
| 6996 | |
| 6997 | final long identity = Binder.clearCallingIdentity(); |
| 6998 | try { |
| 6999 | Phone phone = getPhone(subId); |
| 7000 | if (phone != null) { |
| 7001 | Phone defaultPhone = phone.getImsPhone(); |
| 7002 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7003 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7004 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7005 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7006 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7007 | } |
| 7008 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7009 | } catch (ImsException e) { |
| 7010 | throw new ServiceSpecificException(e.getCode()); |
| 7011 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7012 | Binder.restoreCallingIdentity(identity); |
| 7013 | } |
| 7014 | } |
| 7015 | |
| 7016 | @Override |
| 7017 | public int getCallComposerStatus(int subId) { |
| 7018 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7019 | |
| 7020 | final long identity = Binder.clearCallingIdentity(); |
| 7021 | try { |
| 7022 | Phone phone = getPhone(subId); |
| 7023 | if (phone != null) { |
| 7024 | Phone defaultPhone = phone.getImsPhone(); |
| 7025 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7026 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7027 | return imsPhone.getCallComposerStatus(); |
| 7028 | } |
| 7029 | } |
| 7030 | } finally { |
| 7031 | Binder.restoreCallingIdentity(identity); |
| 7032 | } |
| 7033 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7034 | } |
| 7035 | |
| 7036 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7037 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7038 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7039 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7040 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7041 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7042 | final long identity = Binder.clearCallingIdentity(); |
| 7043 | try { |
| 7044 | final String iccId = getIccId(subId); |
| 7045 | final Phone phone = getPhone(subId); |
| 7046 | if (phone == null) { |
| 7047 | return false; |
| 7048 | } |
| 7049 | final String subscriberId = phone.getSubscriberId(); |
| 7050 | |
| 7051 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7052 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7053 | + subscriberId + " to " + number); |
| 7054 | } |
| 7055 | |
| 7056 | if (TextUtils.isEmpty(iccId)) { |
| 7057 | return false; |
| 7058 | } |
| 7059 | |
| 7060 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7061 | |
| 7062 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7063 | if (alphaTag == null) { |
| 7064 | editor.remove(alphaTagPrefKey); |
| 7065 | } else { |
| 7066 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7067 | } |
| 7068 | |
| 7069 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7070 | // track all merged IMSIs based on line number |
| 7071 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7072 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7073 | if (number == null) { |
| 7074 | editor.remove(numberPrefKey); |
| 7075 | editor.remove(subscriberPrefKey); |
| 7076 | } else { |
| 7077 | editor.putString(numberPrefKey, number); |
| 7078 | editor.putString(subscriberPrefKey, subscriberId); |
| 7079 | } |
| 7080 | |
| 7081 | editor.commit(); |
| 7082 | return true; |
| 7083 | } finally { |
| 7084 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7085 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7086 | } |
| 7087 | |
| 7088 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7089 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7090 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7091 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7092 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7093 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7094 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7095 | return null; |
| 7096 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7097 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7098 | final long identity = Binder.clearCallingIdentity(); |
| 7099 | try { |
| 7100 | String iccId = getIccId(subId); |
| 7101 | if (iccId != null) { |
| 7102 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7103 | if (DBG_MERGE) { |
| 7104 | log("getLine1NumberForDisplay returning " |
| 7105 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7106 | } |
| 7107 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7108 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7109 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7110 | return null; |
| 7111 | } finally { |
| 7112 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7113 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7114 | } |
| 7115 | |
| 7116 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7117 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7118 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7119 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7120 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7121 | return null; |
| 7122 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7123 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7124 | final long identity = Binder.clearCallingIdentity(); |
| 7125 | try { |
| 7126 | String iccId = getIccId(subId); |
| 7127 | if (iccId != null) { |
| 7128 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7129 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7130 | } |
| 7131 | return null; |
| 7132 | } finally { |
| 7133 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7134 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7135 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7136 | |
| 7137 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7138 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7139 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7140 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7141 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7142 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7143 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7144 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7145 | return null; |
| 7146 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7147 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7148 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7149 | // the process, where TelephonyManager was instantiated. |
| 7150 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7151 | final long identity = Binder.clearCallingIdentity(); |
| 7152 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7153 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7154 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7155 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7156 | |
| 7157 | // Figure out what subscribers are currently active |
| 7158 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7159 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7160 | // Only consider subs which match the current subId |
| 7161 | // This logic can be simplified. See b/131189269 for progress. |
| 7162 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7163 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7164 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7165 | |
| 7166 | // First pass, find a number override for an active subscriber |
| 7167 | String mergeNumber = null; |
| 7168 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7169 | for (String key : prefs.keySet()) { |
| 7170 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7171 | final String subscriberId = (String) prefs.get(key); |
| 7172 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7173 | final String iccId = key.substring( |
| 7174 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7175 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7176 | mergeNumber = (String) prefs.get(numberKey); |
| 7177 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7178 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7179 | + " for active subscriber " + subscriberId); |
| 7180 | } |
| 7181 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7182 | break; |
| 7183 | } |
| 7184 | } |
| 7185 | } |
| 7186 | } |
| 7187 | |
| 7188 | // Shortcut when no active merged subscribers |
| 7189 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7190 | return null; |
| 7191 | } |
| 7192 | |
| 7193 | // Second pass, find all subscribers under that line override |
| 7194 | final ArraySet<String> result = new ArraySet<>(); |
| 7195 | for (String key : prefs.keySet()) { |
| 7196 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7197 | final String number = (String) prefs.get(key); |
| 7198 | if (mergeNumber.equals(number)) { |
| 7199 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7200 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7201 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7202 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7203 | result.add(subscriberId); |
| 7204 | } |
| 7205 | } |
| 7206 | } |
| 7207 | } |
| 7208 | |
| 7209 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7210 | Arrays.sort(resultArray); |
| 7211 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7212 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7213 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7214 | } |
| 7215 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7216 | } finally { |
| 7217 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7218 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7219 | } |
| 7220 | |
| 7221 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7222 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7223 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7224 | |
| 7225 | final long identity = Binder.clearCallingIdentity(); |
| 7226 | try { |
| 7227 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7228 | TelephonyManager.class); |
| 7229 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7230 | if (subscriberId == null) { |
| 7231 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7232 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7233 | + subId); |
| 7234 | } |
| 7235 | return null; |
| 7236 | } |
| 7237 | |
| 7238 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 7239 | .getSubscriptionInfo(subId); |
| 7240 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 7241 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7242 | if (groupUuid == null) { |
| 7243 | return new String[]{subscriberId}; |
| 7244 | } |
| 7245 | |
| 7246 | // Get all subscriberIds from the group. |
| 7247 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 7248 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7249 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7250 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7251 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7252 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7253 | if (subscriberId != null) { |
| 7254 | mergedSubscriberIds.add(subscriberId); |
| 7255 | } |
| 7256 | } |
| 7257 | |
| 7258 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7259 | } finally { |
| 7260 | Binder.restoreCallingIdentity(identity); |
| 7261 | |
| 7262 | } |
| 7263 | } |
| 7264 | |
| 7265 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7266 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7267 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7268 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7269 | |
| 7270 | final long identity = Binder.clearCallingIdentity(); |
| 7271 | try { |
| 7272 | final Phone phone = getPhone(subId); |
| 7273 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7274 | } finally { |
| 7275 | Binder.restoreCallingIdentity(identity); |
| 7276 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7277 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7278 | |
| 7279 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7280 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7281 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7282 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7283 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7284 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7285 | |
| 7286 | final long identity = Binder.clearCallingIdentity(); |
| 7287 | try { |
| 7288 | final Phone phone = getPhone(subId); |
| 7289 | if (phone == null) { |
| 7290 | return false; |
| 7291 | } |
| 7292 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7293 | cdmaNonRoamingList); |
| 7294 | } finally { |
| 7295 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7296 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7297 | } |
| 7298 | |
| 7299 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7300 | @Deprecated |
| 7301 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7302 | enforceModifyPermission(); |
| 7303 | |
| 7304 | int returnValue = 0; |
| 7305 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7306 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7307 | if(result.exception == null) { |
| 7308 | if (result.result != null) { |
| 7309 | byte[] responseData = (byte[])(result.result); |
| 7310 | if(responseData.length > oemResp.length) { |
| 7311 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7312 | responseData.length + "bytes. Buffer Size is " + |
| 7313 | oemResp.length + "bytes."); |
| 7314 | } |
| 7315 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7316 | returnValue = responseData.length; |
| 7317 | } |
| 7318 | } else { |
| 7319 | CommandException ex = (CommandException) result.exception; |
| 7320 | returnValue = ex.getCommandError().ordinal(); |
| 7321 | if(returnValue > 0) returnValue *= -1; |
| 7322 | } |
| 7323 | } catch (RuntimeException e) { |
| 7324 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7325 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7326 | if(returnValue > 0) returnValue *= -1; |
| 7327 | } |
| 7328 | |
| 7329 | return returnValue; |
| 7330 | } |
| 7331 | |
| 7332 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7333 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7334 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7335 | try { |
| 7336 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7337 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7338 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7339 | } catch (SecurityException e) { |
| 7340 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7341 | throw e; |
| 7342 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7343 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7344 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7345 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7346 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7347 | final long identity = Binder.clearCallingIdentity(); |
| 7348 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7349 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7350 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7351 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7352 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7353 | } finally { |
| 7354 | Binder.restoreCallingIdentity(identity); |
| 7355 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7356 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7357 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7358 | |
| 7359 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7360 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7361 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7362 | try { |
| 7363 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7364 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7365 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7366 | } |
| 7367 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7368 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7369 | } |
| 7370 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7371 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7372 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7373 | throw new SecurityException("App must be the dialer role holder to" |
| 7374 | + " upload a call composer pic"); |
| 7375 | } |
| 7376 | |
| 7377 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7378 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7379 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7380 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7381 | boolean readUntilEnd = false; |
| 7382 | int totalBytesRead = 0; |
| 7383 | byte[] buffer = new byte[16 * 1024]; |
| 7384 | while (true) { |
| 7385 | int numRead; |
| 7386 | try { |
| 7387 | numRead = input.read(buffer); |
| 7388 | } catch (IOException e) { |
| 7389 | try { |
| 7390 | fd.checkError(); |
| 7391 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7392 | null); |
| 7393 | } catch (IOException e1) { |
| 7394 | // This means that the other side closed explicitly with an error. If this |
| 7395 | // happens, log and ignore. |
| 7396 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7397 | } |
| 7398 | break; |
| 7399 | } |
| 7400 | if (numRead == -1) { |
| 7401 | readUntilEnd = true; |
| 7402 | break; |
| 7403 | } |
| 7404 | totalBytesRead += numRead; |
| 7405 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7406 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7407 | try { |
| 7408 | input.close(); |
| 7409 | } catch (IOException e) { |
| 7410 | // ignore |
| 7411 | } |
| 7412 | break; |
| 7413 | } |
| 7414 | output.write(buffer, 0, numRead); |
| 7415 | } |
| 7416 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7417 | // close is above, where the picture size is too big. |
| 7418 | |
| 7419 | try { |
| 7420 | fd.checkError(); |
| 7421 | } catch (IOException e) { |
| 7422 | loge("Remote end for call composer closed with an error: " + e); |
| 7423 | return; |
| 7424 | } |
| 7425 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7426 | if (!readUntilEnd) { |
| 7427 | loge("Did not finish reading entire image; aborting"); |
| 7428 | return; |
| 7429 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7430 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7431 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7432 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7433 | new CallComposerPictureTransfer.Factory() {}, |
| 7434 | imageData, |
| 7435 | (result) -> { |
| 7436 | if (result.first != null) { |
| 7437 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7438 | Bundle outputResult = new Bundle(); |
| 7439 | outputResult.putParcelable( |
| 7440 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7441 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7442 | outputResult); |
| 7443 | } else { |
| 7444 | callback.send(result.second, null); |
| 7445 | } |
| 7446 | } |
| 7447 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7448 | }); |
| 7449 | } |
| 7450 | |
| 7451 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7452 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7453 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7454 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7455 | |
| 7456 | final long identity = Binder.clearCallingIdentity(); |
| 7457 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7458 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7459 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7460 | } finally { |
| 7461 | Binder.restoreCallingIdentity(identity); |
| 7462 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7463 | } |
| 7464 | |
| 7465 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7466 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7467 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7468 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7469 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7470 | return false; |
| 7471 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7472 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7473 | final long identity = Binder.clearCallingIdentity(); |
| 7474 | try { |
| 7475 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7476 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7477 | // In the long run, we may instead need to check if there exists a connection service |
| 7478 | // which can support video calling. |
| 7479 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7480 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7481 | return imsManager.isVtEnabledByPlatform() |
| 7482 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7483 | && imsManager.isVtEnabledByUser(); |
| 7484 | } finally { |
| 7485 | Binder.restoreCallingIdentity(identity); |
| 7486 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7487 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7488 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7489 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7490 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7491 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7492 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7493 | mApp, subId, callingPackage, callingFeatureId, |
| 7494 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7495 | return false; |
| 7496 | } |
| 7497 | |
| 7498 | final long identity = Binder.clearCallingIdentity(); |
| 7499 | try { |
| 7500 | CarrierConfigManager configManager = |
| 7501 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7502 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7503 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7504 | } finally { |
| 7505 | Binder.restoreCallingIdentity(identity); |
| 7506 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7507 | } |
| 7508 | |
| 7509 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7510 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7511 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7512 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7513 | return false; |
| 7514 | } |
| 7515 | |
| 7516 | final long identity = Binder.clearCallingIdentity(); |
| 7517 | try { |
| 7518 | CarrierConfigManager configManager = |
| 7519 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7520 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7521 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7522 | } finally { |
| 7523 | Binder.restoreCallingIdentity(identity); |
| 7524 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7525 | } |
| 7526 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7527 | @Override |
| 7528 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7529 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7530 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7531 | } |
| 7532 | |
| 7533 | @Override |
| 7534 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7535 | final long identity = Binder.clearCallingIdentity(); |
| 7536 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7537 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7538 | } finally { |
| 7539 | Binder.restoreCallingIdentity(identity); |
| 7540 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7541 | } |
| 7542 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7543 | /** |
| 7544 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7545 | * support for the feature and device firmware support. |
| 7546 | * |
| 7547 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7548 | */ |
| 7549 | @Override |
| 7550 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7551 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7552 | final Phone phone = getPhone(subscriptionId); |
| 7553 | if (phone == null) { |
| 7554 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7555 | return false; |
| 7556 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7557 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7558 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7559 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7560 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7561 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7562 | return isCarrierSupported && isDeviceSupported; |
| 7563 | } finally { |
| 7564 | Binder.restoreCallingIdentity(identity); |
| 7565 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7566 | } |
| 7567 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7568 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7569 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7570 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7571 | * 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] | 7572 | */ |
| 7573 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7574 | final long identity = Binder.clearCallingIdentity(); |
| 7575 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7576 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7577 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7578 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7579 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7580 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7581 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7582 | } finally { |
| 7583 | Binder.restoreCallingIdentity(identity); |
| 7584 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7585 | } |
| 7586 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7587 | @Deprecated |
| 7588 | @Override |
| 7589 | public String getDeviceId(String callingPackage) { |
| 7590 | return getDeviceIdWithFeature(callingPackage, null); |
| 7591 | } |
| 7592 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7593 | /** |
| 7594 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7595 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7596 | * |
| 7597 | * <p>Requires Permission: |
| 7598 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7599 | */ |
| 7600 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7601 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7602 | try { |
| 7603 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7604 | } catch (SecurityException se) { |
| 7605 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7606 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7607 | + Binder.getCallingUid()); |
| 7608 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7609 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7610 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7611 | return null; |
| 7612 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7613 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7614 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7615 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7616 | return null; |
| 7617 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7618 | |
| 7619 | final long identity = Binder.clearCallingIdentity(); |
| 7620 | try { |
| 7621 | return phone.getDeviceId(); |
| 7622 | } finally { |
| 7623 | Binder.restoreCallingIdentity(identity); |
| 7624 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7625 | } |
| 7626 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7627 | /** |
| 7628 | * {@hide} |
| 7629 | * Returns the IMS Registration Status on a particular subid |
| 7630 | * |
| 7631 | * @param subId |
| 7632 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7633 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7634 | Phone phone = getPhone(subId); |
| 7635 | if (phone != null) { |
| 7636 | return phone.isImsRegistered(); |
| 7637 | } else { |
| 7638 | return false; |
| 7639 | } |
| 7640 | } |
| 7641 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7642 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7643 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7644 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7645 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7646 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7647 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7648 | } |
| 7649 | final long identity = Binder.clearCallingIdentity(); |
| 7650 | try { |
| 7651 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7652 | } finally { |
| 7653 | Binder.restoreCallingIdentity(identity); |
| 7654 | } |
| 7655 | } |
| 7656 | |
| 7657 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7658 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7659 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7660 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7661 | mApp, |
| 7662 | subscriptionId, |
| 7663 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7664 | final long identity = Binder.clearCallingIdentity(); |
| 7665 | try { |
| 7666 | Phone phone = getPhone(subscriptionId); |
| 7667 | if (phone == null) { |
| 7668 | return null; |
| 7669 | } |
| 7670 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7671 | } finally { |
| 7672 | Binder.restoreCallingIdentity(identity); |
| 7673 | } |
| 7674 | } |
| 7675 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7676 | /** |
| 7677 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7678 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7679 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7680 | final long identity = Binder.clearCallingIdentity(); |
| 7681 | try { |
| 7682 | Phone phone = getPhone(subId); |
| 7683 | if (phone != null) { |
| 7684 | return phone.isWifiCallingEnabled(); |
| 7685 | } else { |
| 7686 | return false; |
| 7687 | } |
| 7688 | } finally { |
| 7689 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7690 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7691 | } |
| 7692 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7693 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7694 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7695 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7696 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7697 | final long identity = Binder.clearCallingIdentity(); |
| 7698 | try { |
| 7699 | Phone phone = getPhone(subId); |
| 7700 | if (phone != null) { |
| 7701 | return phone.isVideoEnabled(); |
| 7702 | } else { |
| 7703 | return false; |
| 7704 | } |
| 7705 | } finally { |
| 7706 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7707 | } |
| 7708 | } |
| 7709 | |
| 7710 | /** |
| 7711 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7712 | * defined in {@link ImsRegistrationImplBase}. |
| 7713 | */ |
| 7714 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7715 | final long identity = Binder.clearCallingIdentity(); |
| 7716 | try { |
| 7717 | Phone phone = getPhone(subId); |
| 7718 | if (phone != null) { |
| 7719 | return phone.getImsRegistrationTech(); |
| 7720 | } else { |
| 7721 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7722 | } |
| 7723 | } finally { |
| 7724 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7725 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7726 | } |
| 7727 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7728 | @Override |
| 7729 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7730 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7731 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7732 | return; |
| 7733 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7734 | Phone defaultPhone = getDefaultPhone(); |
| 7735 | if (defaultPhone != null) { |
| 7736 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7737 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7738 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7739 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7740 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7741 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7742 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7743 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7744 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7745 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7746 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7747 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7748 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7749 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7750 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7751 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7752 | // There has been issues when Sms raw table somehow stores orphan |
| 7753 | // fragments. They lead to garbled message when new fragments come |
| 7754 | // in and combined with those stale ones. In case this happens again, |
| 7755 | // user can reset all network settings which will clean up this table. |
| 7756 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7757 | // Clean up IMS settings as well here. |
| 7758 | int slotId = getSlotIndex(subId); |
| 7759 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7760 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7761 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7762 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7763 | if (defaultPhone == null) { |
| 7764 | return; |
| 7765 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7766 | // Erase modem config if erase modem on network setting is enabled. |
| 7767 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7768 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7769 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7770 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7771 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7772 | |
| 7773 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7774 | } finally { |
| 7775 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7776 | } |
| 7777 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7778 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7779 | @VisibleForTesting |
| 7780 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7781 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7782 | return; |
| 7783 | } |
| 7784 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7785 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7786 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7787 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7788 | "user=" + defaultNetworkType); |
| 7789 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7790 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7791 | defaultNetworkType, null); |
| 7792 | } |
| 7793 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7794 | private void cleanUpSmsRawTable(Context context) { |
| 7795 | ContentResolver resolver = context.getContentResolver(); |
| 7796 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7797 | resolver.delete(uri, null, null); |
| 7798 | } |
| 7799 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7800 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7801 | public String getSimLocaleForSubscriber(int subId) { |
| 7802 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7803 | final Phone phone = getPhone(subId); |
| 7804 | if (phone == null) { |
| 7805 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7806 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7807 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7808 | final long identity = Binder.clearCallingIdentity(); |
| 7809 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7810 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7811 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7812 | if (info == null) { |
| 7813 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7814 | return null; |
| 7815 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7816 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7817 | // preferences (EF-PL and EF-LI)... |
| 7818 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7819 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7820 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7821 | if (localeFromDefaultSim != null) { |
| 7822 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7823 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7824 | + localeFromDefaultSim); |
| 7825 | return localeFromDefaultSim.toLanguageTag(); |
| 7826 | } else { |
| 7827 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7828 | } |
| 7829 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7830 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7831 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7832 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7833 | // the SIM and carrier preferences does not include a country we add the country |
| 7834 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7835 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7836 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7837 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7838 | return mccLocale.toLanguageTag(); |
| 7839 | } |
| 7840 | |
| 7841 | if (DBG) log("No locale found - returning null"); |
| 7842 | return null; |
| 7843 | } finally { |
| 7844 | Binder.restoreCallingIdentity(identity); |
| 7845 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7846 | } |
| 7847 | |
| 7848 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7849 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7850 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7851 | } |
| 7852 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7853 | /** |
| 7854 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7855 | */ |
| 7856 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7857 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7858 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7859 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7860 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7861 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7862 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7863 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7864 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7865 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7866 | * representing the state of the modem. |
| 7867 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7868 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7869 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7870 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7871 | */ |
| 7872 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7873 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7874 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7875 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7876 | |
| 7877 | final long identity = Binder.clearCallingIdentity(); |
| 7878 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7879 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7880 | } finally { |
| 7881 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7882 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7883 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7884 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7885 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7886 | // less than total activity duration. |
| 7887 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7888 | if (info == null) { |
| 7889 | return false; |
| 7890 | } |
| 7891 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7892 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7893 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7894 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7895 | return (info.isValid() |
| 7896 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7897 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7898 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7899 | && (totalTxTimeMs <= activityDurationMs)); |
| 7900 | } |
| 7901 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7902 | /** |
| 7903 | * {@hide} |
| 7904 | * Returns the service state information on specified subscription. |
| 7905 | */ |
| 7906 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7907 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7908 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7909 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7910 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7911 | return null; |
| 7912 | } |
| 7913 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7914 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7915 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7916 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7917 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7918 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7919 | .setCallingPid(Binder.getCallingPid()) |
| 7920 | .setCallingUid(Binder.getCallingUid()) |
| 7921 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7922 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7923 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7924 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7925 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7926 | .build()); |
| 7927 | |
| 7928 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7929 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7930 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7931 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7932 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7933 | .setCallingPid(Binder.getCallingPid()) |
| 7934 | .setCallingUid(Binder.getCallingUid()) |
| 7935 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7936 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7937 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7938 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7939 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7940 | .build()); |
| 7941 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7942 | boolean hasFinePermission = |
| 7943 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7944 | boolean hasCoarsePermission = |
| 7945 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7946 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7947 | final Phone phone = getPhone(subId); |
| 7948 | if (phone == null) { |
| 7949 | return null; |
| 7950 | } |
| 7951 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7952 | final long identity = Binder.clearCallingIdentity(); |
| 7953 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7954 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7955 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7956 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7957 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7958 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7959 | Rlog.d(LOG_TAG, |
| 7960 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7961 | return null; |
| 7962 | } |
| 7963 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7964 | ServiceState ss = phone.getServiceState(); |
| 7965 | |
| 7966 | // Scrub out the location info in ServiceState depending on what level of access |
| 7967 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7968 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7969 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7970 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7971 | } finally { |
| 7972 | Binder.restoreCallingIdentity(identity); |
| 7973 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7974 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7975 | |
| 7976 | /** |
| 7977 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7978 | * |
| 7979 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7980 | * voicemail ringtone. |
| 7981 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7982 | * PhoneAccount. |
| 7983 | */ |
| 7984 | @Override |
| 7985 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7986 | final long identity = Binder.clearCallingIdentity(); |
| 7987 | try { |
| 7988 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7989 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7990 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7991 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7992 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7993 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7994 | } finally { |
| 7995 | Binder.restoreCallingIdentity(identity); |
| 7996 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7997 | } |
| 7998 | |
| 7999 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8000 | * Sets the per-account voicemail ringtone. |
| 8001 | * |
| 8002 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8003 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8004 | * |
| 8005 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8006 | * voicemail ringtone. |
| 8007 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8008 | * PhoneAccount. |
| 8009 | */ |
| 8010 | @Override |
| 8011 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8012 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8013 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8014 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8015 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8016 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8017 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8018 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8019 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8020 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8021 | |
| 8022 | final long identity = Binder.clearCallingIdentity(); |
| 8023 | try { |
| 8024 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8025 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8026 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8027 | } |
| 8028 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8029 | } finally { |
| 8030 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8031 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8032 | } |
| 8033 | |
| 8034 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8035 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8036 | * |
| 8037 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8038 | * voicemail vibration setting. |
| 8039 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8040 | */ |
| 8041 | @Override |
| 8042 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8043 | final long identity = Binder.clearCallingIdentity(); |
| 8044 | try { |
| 8045 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8046 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8047 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8048 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8049 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8050 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8051 | } finally { |
| 8052 | Binder.restoreCallingIdentity(identity); |
| 8053 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8054 | } |
| 8055 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8056 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8057 | * Sets the per-account voicemail vibration. |
| 8058 | * |
| 8059 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8060 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8061 | * |
| 8062 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8063 | * voicemail vibration setting. |
| 8064 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8065 | * specific PhoneAccount. |
| 8066 | */ |
| 8067 | @Override |
| 8068 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8069 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8070 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8071 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8072 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8073 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8074 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8075 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8076 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8077 | } |
| 8078 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8079 | final long identity = Binder.clearCallingIdentity(); |
| 8080 | try { |
| 8081 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8082 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8083 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8084 | } |
| 8085 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8086 | } finally { |
| 8087 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8088 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8089 | } |
| 8090 | |
| 8091 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8092 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8093 | * |
| 8094 | * @throws SecurityException if the caller does not have the required permission |
| 8095 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8096 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8097 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8098 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8099 | } |
| 8100 | |
| 8101 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8102 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8103 | * permission. |
| 8104 | * |
| 8105 | * @throws SecurityException if the caller does not have the required permission |
| 8106 | */ |
| 8107 | private void enforceSendSmsPermission() { |
| 8108 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8109 | } |
| 8110 | |
| 8111 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8112 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8113 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8114 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8115 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8116 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8117 | final long identity = Binder.clearCallingIdentity(); |
| 8118 | try { |
| 8119 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8120 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8121 | if (componentName == null) { |
| 8122 | throw new SecurityException( |
| 8123 | "Caller not current active visual voicemail package[null]"); |
| 8124 | } |
| 8125 | String vvmPackage = componentName.getPackageName(); |
| 8126 | if (!callingPackage.equals(vvmPackage)) { |
| 8127 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 8128 | + vvmPackage + "]"); |
| 8129 | } |
| 8130 | } finally { |
| 8131 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8132 | } |
| 8133 | } |
| 8134 | |
| 8135 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8136 | * Return the application ID for the app type. |
| 8137 | * |
| 8138 | * @param subId the subscription ID that this request applies to. |
| 8139 | * @param appType the uicc app type. |
| 8140 | * @return Application ID for specificied app type, or null if no uicc. |
| 8141 | */ |
| 8142 | @Override |
| 8143 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8144 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8145 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8146 | |
| 8147 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8148 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8149 | if (phone == null) { |
| 8150 | return null; |
| 8151 | } |
| 8152 | String aid = null; |
| 8153 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8154 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8155 | .getApplicationByType(appType).getAid(); |
| 8156 | } catch (Exception e) { |
| 8157 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8158 | } |
| 8159 | return aid; |
| 8160 | } finally { |
| 8161 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8162 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8163 | } |
| 8164 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8165 | /** |
| 8166 | * Return the Electronic Serial Number. |
| 8167 | * |
| 8168 | * @param subId the subscription ID that this request applies to. |
| 8169 | * @return ESN or null if error. |
| 8170 | */ |
| 8171 | @Override |
| 8172 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8173 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8174 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8175 | |
| 8176 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8177 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8178 | if (phone == null) { |
| 8179 | return null; |
| 8180 | } |
| 8181 | String esn = null; |
| 8182 | try { |
| 8183 | esn = phone.getEsn(); |
| 8184 | } catch (Exception e) { |
| 8185 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8186 | } |
| 8187 | return esn; |
| 8188 | } finally { |
| 8189 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8190 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8191 | } |
| 8192 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8193 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8194 | * Return the Preferred Roaming List Version. |
| 8195 | * |
| 8196 | * @param subId the subscription ID that this request applies to. |
| 8197 | * @return PRLVersion or null if error. |
| 8198 | */ |
| 8199 | @Override |
| 8200 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8201 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8202 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8203 | |
| 8204 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8205 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8206 | if (phone == null) { |
| 8207 | return null; |
| 8208 | } |
| 8209 | String cdmaPrlVersion = null; |
| 8210 | try { |
| 8211 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8212 | } catch (Exception e) { |
| 8213 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8214 | } |
| 8215 | return cdmaPrlVersion; |
| 8216 | } finally { |
| 8217 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8218 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8219 | } |
| 8220 | |
| 8221 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8222 | * Get snapshot of Telephony histograms |
| 8223 | * @return List of Telephony histograms |
| 8224 | * @hide |
| 8225 | */ |
| 8226 | @Override |
| 8227 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8228 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8229 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8230 | |
| 8231 | final long identity = Binder.clearCallingIdentity(); |
| 8232 | try { |
| 8233 | return RIL.getTelephonyRILTimingHistograms(); |
| 8234 | } finally { |
| 8235 | Binder.restoreCallingIdentity(identity); |
| 8236 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8237 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8238 | |
| 8239 | /** |
| 8240 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8241 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8242 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8243 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8244 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8245 | * @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] | 8246 | */ |
| 8247 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8248 | @TelephonyManager.SetCarrierRestrictionResult |
| 8249 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8250 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8251 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8252 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8253 | if (carrierRestrictionRules == null) { |
| 8254 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8255 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8256 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8257 | final long identity = Binder.clearCallingIdentity(); |
| 8258 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8259 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8260 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8261 | } finally { |
| 8262 | Binder.restoreCallingIdentity(identity); |
| 8263 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8264 | } |
| 8265 | |
| 8266 | /** |
| 8267 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8268 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8269 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8270 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8271 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8272 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8273 | */ |
| 8274 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8275 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8276 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8277 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8278 | |
| 8279 | final long identity = Binder.clearCallingIdentity(); |
| 8280 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8281 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8282 | if (response instanceof CarrierRestrictionRules) { |
| 8283 | return (CarrierRestrictionRules) response; |
| 8284 | } |
| 8285 | // Response is an Exception of some kind, |
| 8286 | // which is signalled to the user as a NULL retval |
| 8287 | return null; |
| 8288 | } catch (Exception e) { |
| 8289 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8290 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8291 | } finally { |
| 8292 | Binder.restoreCallingIdentity(identity); |
| 8293 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8294 | } |
| 8295 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8296 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8297 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8298 | * @param subId the subscription ID that this action applies to. |
| 8299 | * @param enabled control enable or disable radio. |
| 8300 | * {@hide} |
| 8301 | */ |
| 8302 | @Override |
| 8303 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8304 | enforceModifyPermission(); |
| 8305 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8306 | |
| 8307 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8308 | if (phone == null) { |
| 8309 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8310 | return; |
| 8311 | } |
| 8312 | try { |
| 8313 | phone.carrierActionSetRadioEnabled(enabled); |
| 8314 | } catch (Exception e) { |
| 8315 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8316 | } finally { |
| 8317 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8318 | } |
| 8319 | } |
| 8320 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8321 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8322 | * Enable or disable Voice over NR (VoNR) |
| 8323 | * @param subId the subscription ID that this action applies to. |
| 8324 | * @param enabled enable or disable VoNR. |
| 8325 | * @return operation result. |
| 8326 | */ |
| 8327 | @Override |
| 8328 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8329 | enforceModifyPermission(); |
| 8330 | final Phone phone = getPhone(subId); |
| 8331 | |
| 8332 | final long identity = Binder.clearCallingIdentity(); |
| 8333 | if (phone == null) { |
| 8334 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8335 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8336 | } |
| 8337 | |
| 8338 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8339 | try { |
| 8340 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8341 | workSource); |
| 8342 | if (DBG) log("setVoNrEnabled result: " + result); |
| 8343 | return result; |
| 8344 | } finally { |
| 8345 | Binder.restoreCallingIdentity(identity); |
| 8346 | } |
| 8347 | } |
| 8348 | |
| 8349 | /** |
| 8350 | * Is voice over NR enabled |
| 8351 | * @return true if VoNR is enabled else false |
| 8352 | */ |
| 8353 | @Override |
| 8354 | public boolean isVoNrEnabled(int subId) { |
| 8355 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8356 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8357 | final long identity = Binder.clearCallingIdentity(); |
| 8358 | try { |
| 8359 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8360 | null, subId, workSource); |
| 8361 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8362 | return isEnabled; |
| 8363 | } finally { |
| 8364 | Binder.restoreCallingIdentity(identity); |
| 8365 | } |
| 8366 | } |
| 8367 | |
| 8368 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8369 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8370 | * network status based on which carrier apps could apply actions accordingly, |
| 8371 | * enable/disable default url handler for example. |
| 8372 | * |
| 8373 | * @param subId the subscription ID that this action applies to. |
| 8374 | * @param report control start/stop reporting the default network status. |
| 8375 | * {@hide} |
| 8376 | */ |
| 8377 | @Override |
| 8378 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8379 | enforceModifyPermission(); |
| 8380 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8381 | |
| 8382 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8383 | if (phone == null) { |
| 8384 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8385 | return; |
| 8386 | } |
| 8387 | try { |
| 8388 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8389 | } catch (Exception e) { |
| 8390 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8391 | } finally { |
| 8392 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8393 | } |
| 8394 | } |
| 8395 | |
| 8396 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8397 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8398 | * @param subId the subscription ID that this action applies to. |
| 8399 | * {@hide} |
| 8400 | */ |
| 8401 | @Override |
| 8402 | public void carrierActionResetAll(int subId) { |
| 8403 | enforceModifyPermission(); |
| 8404 | final Phone phone = getPhone(subId); |
| 8405 | if (phone == null) { |
| 8406 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8407 | return; |
| 8408 | } |
| 8409 | try { |
| 8410 | phone.carrierActionResetAll(); |
| 8411 | } catch (Exception e) { |
| 8412 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8413 | } |
| 8414 | } |
| 8415 | |
| 8416 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8417 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8418 | * bug report is being generated. |
| 8419 | */ |
| 8420 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8421 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8422 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8423 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8424 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8425 | + Binder.getCallingPid() |
| 8426 | + ", uid=" + Binder.getCallingUid() |
| 8427 | + "without permission " |
| 8428 | + android.Manifest.permission.DUMP); |
| 8429 | return; |
| 8430 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8431 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8432 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8433 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8434 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8435 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8436 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8437 | @NonNull String[] args) { |
| 8438 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8439 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8440 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8441 | } |
| 8442 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8443 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8444 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8445 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8446 | * @param reason the reason the data enable change is taking place |
| 8447 | * @param enabled True if enabling the data, otherwise disabling. |
| 8448 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8449 | */ |
| 8450 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8451 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8452 | boolean enabled) { |
| 8453 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8454 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8455 | try { |
| 8456 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8457 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8458 | } catch (SecurityException se) { |
| 8459 | enforceModifyPermission(); |
| 8460 | } |
| 8461 | } else { |
| 8462 | enforceModifyPermission(); |
| 8463 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8464 | |
| 8465 | final long identity = Binder.clearCallingIdentity(); |
| 8466 | try { |
| 8467 | Phone phone = getPhone(subId); |
| 8468 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8469 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8470 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8471 | } else { |
| 8472 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 8473 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8474 | } |
| 8475 | } finally { |
| 8476 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8477 | } |
| 8478 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8479 | |
| 8480 | /** |
| 8481 | * Get Client request stats |
| 8482 | * @return List of Client Request Stats |
| 8483 | * @hide |
| 8484 | */ |
| 8485 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8486 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8487 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8488 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8489 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8490 | return null; |
| 8491 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8492 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8493 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8494 | final long identity = Binder.clearCallingIdentity(); |
| 8495 | try { |
| 8496 | if (phone != null) { |
| 8497 | return phone.getClientRequestStats(); |
| 8498 | } |
| 8499 | |
| 8500 | return null; |
| 8501 | } finally { |
| 8502 | Binder.restoreCallingIdentity(identity); |
| 8503 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8504 | } |
| 8505 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8506 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8507 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8508 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8509 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8510 | |
| 8511 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8512 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8513 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8514 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8515 | * @param state State of SIM (power down, power up, pass through) |
| 8516 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8517 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8518 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8519 | * |
| 8520 | **/ |
| 8521 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8522 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8523 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8524 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8525 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8526 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8527 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8528 | final long identity = Binder.clearCallingIdentity(); |
| 8529 | try { |
| 8530 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8531 | phone.setSimPowerState(state, null, workSource); |
| 8532 | } |
| 8533 | } finally { |
| 8534 | Binder.restoreCallingIdentity(identity); |
| 8535 | } |
| 8536 | } |
| 8537 | |
| 8538 | /** |
| 8539 | * Set SIM card power state. |
| 8540 | * |
| 8541 | * @param slotIndex SIM slot id. |
| 8542 | * @param state State of SIM (power down, power up, pass through) |
| 8543 | * @param callback callback to trigger after success or failure |
| 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} |
| 8547 | * |
| 8548 | **/ |
| 8549 | @Override |
| 8550 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8551 | IIntegerConsumer callback) { |
| 8552 | enforceModifyPermission(); |
| 8553 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8554 | |
| 8555 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8556 | |
| 8557 | final long identity = Binder.clearCallingIdentity(); |
| 8558 | try { |
| 8559 | if (phone != null) { |
| 8560 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8561 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8562 | } |
| 8563 | } finally { |
| 8564 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8565 | } |
| 8566 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8567 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8568 | private boolean isUssdApiAllowed(int subId) { |
| 8569 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8570 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8571 | if (configManager == null) { |
| 8572 | return false; |
| 8573 | } |
| 8574 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8575 | if (pb == null) { |
| 8576 | return false; |
| 8577 | } |
| 8578 | return pb.getBoolean( |
| 8579 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8580 | } |
| 8581 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8582 | /** |
| 8583 | * Check if phone is in emergency callback mode |
| 8584 | * @return true if phone is in emergency callback mode |
| 8585 | * @param subId sub id |
| 8586 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8587 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8588 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8589 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8590 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8591 | |
| 8592 | final long identity = Binder.clearCallingIdentity(); |
| 8593 | try { |
| 8594 | if (phone != null) { |
| 8595 | return phone.isInEcm(); |
| 8596 | } else { |
| 8597 | return false; |
| 8598 | } |
| 8599 | } finally { |
| 8600 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8601 | } |
| 8602 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8603 | |
| 8604 | /** |
| 8605 | * Get the current signal strength information for the given subscription. |
| 8606 | * Because this information is not updated when the device is in a low power state |
| 8607 | * it should not be relied-upon to be current. |
| 8608 | * @param subId Subscription index |
| 8609 | * @return the most recent cached signal strength info from the modem |
| 8610 | */ |
| 8611 | @Override |
| 8612 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8613 | final long identity = Binder.clearCallingIdentity(); |
| 8614 | try { |
| 8615 | Phone p = getPhone(subId); |
| 8616 | if (p == null) { |
| 8617 | return null; |
| 8618 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8619 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8620 | return p.getSignalStrength(); |
| 8621 | } finally { |
| 8622 | Binder.restoreCallingIdentity(identity); |
| 8623 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8624 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8625 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8626 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8627 | * Get the current modem radio state for the given slot. |
| 8628 | * @param slotIndex slot index. |
| 8629 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8630 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8631 | * @return the current radio power state from the modem |
| 8632 | */ |
| 8633 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8634 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8635 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8636 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8637 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8638 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8639 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8640 | } |
| 8641 | |
| 8642 | final long identity = Binder.clearCallingIdentity(); |
| 8643 | try { |
| 8644 | return phone.getRadioPowerState(); |
| 8645 | } finally { |
| 8646 | Binder.restoreCallingIdentity(identity); |
| 8647 | } |
| 8648 | } |
| 8649 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8650 | } |
| 8651 | |
| 8652 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8653 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8654 | * |
| 8655 | * <p>Requires one of the following permissions: |
| 8656 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8657 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8658 | * privileges. |
| 8659 | * |
| 8660 | * @param subId subscription id |
| 8661 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8662 | * {@code false}. |
| 8663 | */ |
| 8664 | @Override |
| 8665 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8666 | try { |
| 8667 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8668 | null); |
| 8669 | } catch (Exception e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8670 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8671 | mApp, subId, "isDataRoamingEnabled"); |
| 8672 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8673 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8674 | boolean isEnabled = false; |
| 8675 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8676 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8677 | Phone phone = getPhone(subId); |
| 8678 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8679 | } finally { |
| 8680 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8681 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8682 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8683 | } |
| 8684 | |
| 8685 | |
| 8686 | /** |
| 8687 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8688 | * |
| 8689 | * <p> Requires permission: |
| 8690 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8691 | * privileges. |
| 8692 | * |
| 8693 | * @param subId subscription id |
| 8694 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8695 | */ |
| 8696 | @Override |
| 8697 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8698 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8699 | mApp, subId, "setDataRoamingEnabled"); |
| 8700 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8701 | final long identity = Binder.clearCallingIdentity(); |
| 8702 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8703 | Phone phone = getPhone(subId); |
| 8704 | if (phone != null) { |
| 8705 | phone.setDataRoamingEnabled(isEnabled); |
| 8706 | } |
| 8707 | } finally { |
| 8708 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8709 | } |
| 8710 | } |
| 8711 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8712 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8713 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8714 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8715 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8716 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8717 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8718 | boolean isAllowed = true; |
| 8719 | final long identity = Binder.clearCallingIdentity(); |
| 8720 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8721 | Phone phone = getPhone(subId); |
| 8722 | if (phone != null) { |
| 8723 | isAllowed = phone.isCspPlmnEnabled(); |
| 8724 | } |
| 8725 | } finally { |
| 8726 | Binder.restoreCallingIdentity(identity); |
| 8727 | } |
| 8728 | return isAllowed; |
| 8729 | } |
| 8730 | |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8731 | private boolean haveCarrierPrivilegeAccess(UiccCard card, String callingPackage) { |
| 8732 | // TODO once MEP API refactoring CL is merged, loop port list from UiccCardInfo, |
| 8733 | // and if find the matching UiccPort by UiccController.getUiccPortForSlot(slot, portIdx) |
| 8734 | // Update each UiccPort object based on privilege access |
| 8735 | UiccPort[] uiccPorts = card.getUiccPortList(); |
| 8736 | for (UiccPort port : uiccPorts) { |
| 8737 | UiccProfile profile = port.getUiccProfile(); |
| 8738 | if (profile == null || |
| 8739 | profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8740 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8741 | return false; |
| 8742 | } |
| 8743 | } |
| 8744 | return true; |
| 8745 | } |
| 8746 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8747 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8748 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8749 | // Verify that tha callingPackage belongs to the calling UID |
| 8750 | mApp.getSystemService(AppOpsManager.class) |
| 8751 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8752 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8753 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame^] | 8754 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8755 | try { |
| 8756 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8757 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8758 | } catch (SecurityException e) { |
| 8759 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8760 | // has carrier privileges on an active UICC |
| 8761 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8762 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8763 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8764 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8765 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame^] | 8766 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8767 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8768 | Binder.getCallingUid())) { |
| 8769 | isIccIdAccessRestricted = true; |
| 8770 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8771 | final long identity = Binder.clearCallingIdentity(); |
| 8772 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8773 | UiccController uiccController = UiccController.getInstance(); |
| 8774 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8775 | if (hasReadPermission) { |
| 8776 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8777 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8778 | |
| 8779 | // Remove private info if the caller doesn't have access |
| 8780 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8781 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame^] | 8782 | //setting the value after compatibility check |
| 8783 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8784 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8785 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame^] | 8786 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8787 | // TODO remove card.getUiccPortList().length once MEP API refactoring CL is merged |
| 8788 | // Get UiccPortInfo from CardInfo and process further based on each UiccPort |
| 8789 | if (card == null || card.getUiccPortList().length == 0) { |
| 8790 | // assume no access if the card or ports are unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame^] | 8791 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8792 | continue; |
| 8793 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8794 | |
| 8795 | if (haveCarrierPrivilegeAccess(card, callingPackage)) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8796 | filteredInfos.add(cardInfo); |
| 8797 | } else { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame^] | 8798 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8799 | } |
| 8800 | } |
| 8801 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8802 | } finally { |
| 8803 | Binder.restoreCallingIdentity(identity); |
| 8804 | } |
| 8805 | } |
| 8806 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame^] | 8807 | /** |
| 8808 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 8809 | * generally private and require carrier privileges to view. |
| 8810 | * |
| 8811 | * @hide |
| 8812 | */ |
| 8813 | @NonNull |
| 8814 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 8815 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 8816 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 8817 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 8818 | } |
| 8819 | return new UiccCardInfo( |
| 8820 | cardInfo.isEuicc(), |
| 8821 | cardInfo.getCardId(), |
| 8822 | null, |
| 8823 | cardInfo.getPhysicalSlotIndex(), |
| 8824 | cardInfo.isRemovable(), |
| 8825 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8826 | portinfo |
| 8827 | ); |
| 8828 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8829 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame^] | 8830 | /** |
| 8831 | * @hide |
| 8832 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 8833 | * These values are generally private and require carrier privileges to view. |
| 8834 | */ |
| 8835 | @NonNull |
| 8836 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 8837 | return new UiccPortInfo( |
| 8838 | UiccPortInfo.ICCID_REDACTED, |
| 8839 | portInfo.getPortIndex(), |
| 8840 | portInfo.getLogicalSlotIndex(), |
| 8841 | portInfo.isActive() |
| 8842 | ); |
| 8843 | } |
| 8844 | @Override |
| 8845 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
| 8846 | // Verify that tha callingPackage belongs to the calling UID |
| 8847 | mApp.getSystemService(AppOpsManager.class) |
| 8848 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8849 | |
| 8850 | boolean hasReadPermission = false; |
| 8851 | boolean isLogicalSlotAccessRestricted = false; |
| 8852 | String iccId; |
| 8853 | |
| 8854 | try { |
| 8855 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
| 8856 | hasReadPermission = true; |
| 8857 | } catch (SecurityException e) { |
| 8858 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8859 | // has carrier privileges on an active UICC |
| 8860 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8861 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8862 | hasReadPermission = true; |
| 8863 | } |
| 8864 | } |
| 8865 | |
| 8866 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8867 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8868 | Binder.getCallingUid())) { |
| 8869 | isLogicalSlotAccessRestricted = true; |
| 8870 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8871 | final long identity = Binder.clearCallingIdentity(); |
| 8872 | try { |
| 8873 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8874 | if (slots == null) { |
| 8875 | Rlog.i(LOG_TAG, "slots is null."); |
| 8876 | return null; |
| 8877 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8878 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8879 | for (int i = 0; i < slots.length; i++) { |
| 8880 | UiccSlot slot = slots[i]; |
| 8881 | if (slot == null) { |
| 8882 | continue; |
| 8883 | } |
| 8884 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8885 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8886 | UiccCard card = slot.getUiccCard(); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame^] | 8887 | //if has read permission |
| 8888 | if (hasReadPermission) { |
| 8889 | iccId = slot.getIccId(); |
| 8890 | } else { |
| 8891 | // if no read permission checking carrier |
| 8892 | if (haveCarrierPrivilegeAccess(card, callingPackage)) { |
| 8893 | iccId = slot.getIccId(); |
| 8894 | } else { |
| 8895 | //if no carrier permission redact ICCID |
| 8896 | iccId = IccUtils.TEST_ICCID; |
| 8897 | } |
| 8898 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8899 | if (card != null) { |
| 8900 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8901 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8902 | cardId = slot.getEid(); |
| 8903 | if (TextUtils.isEmpty(cardId)) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame^] | 8904 | cardId = iccId; |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8905 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8906 | } |
| 8907 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8908 | if (cardId != null) { |
| 8909 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8910 | // if cardId is an EID, it's all digits so this is fine |
| 8911 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8912 | } |
| 8913 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8914 | int cardState = 0; |
| 8915 | switch (slot.getCardState()) { |
| 8916 | case CARDSTATE_ABSENT: |
| 8917 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8918 | break; |
| 8919 | case CARDSTATE_PRESENT: |
| 8920 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8921 | break; |
| 8922 | case CARDSTATE_ERROR: |
| 8923 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8924 | break; |
| 8925 | case CARDSTATE_RESTRICTED: |
| 8926 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8927 | break; |
| 8928 | default: |
| 8929 | break; |
| 8930 | |
| 8931 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8932 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8933 | slot.isEuicc(), |
| 8934 | cardId, |
| 8935 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8936 | slot.isExtendedApduSupported(), |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame^] | 8937 | slot.isRemovable(), Collections.singletonList( |
| 8938 | new UiccPortInfo( |
| 8939 | iccId, |
| 8940 | 0 /* TODO: to use portList from UiccSlots */, |
| 8941 | slot.getPhoneId(), |
| 8942 | slot.isActive()))); |
| 8943 | //setting the value after compatibility check |
| 8944 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8945 | } |
| 8946 | return infos; |
| 8947 | } finally { |
| 8948 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8949 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8950 | } |
| 8951 | |
| 8952 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame^] | 8953 | @Deprecated |
| 8954 | //TODO : once integrating with HAL Changes we can clean up this Internal API. |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8955 | public boolean switchSlots(int[] physicalSlots) { |
| 8956 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8957 | |
| 8958 | final long identity = Binder.clearCallingIdentity(); |
| 8959 | try { |
| 8960 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8961 | } finally { |
| 8962 | Binder.restoreCallingIdentity(identity); |
| 8963 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8964 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8965 | |
| 8966 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame^] | 8967 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 8968 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 8969 | enforceModifyPermission(); |
| 8970 | |
| 8971 | final long identity = Binder.clearCallingIdentity(); |
| 8972 | try { |
| 8973 | //TODO: once integrating the HAL changes we can proceed with to work on the parsing side |
| 8974 | int[] physicalSlots = new int[slotMapping.size()]; |
| 8975 | for (int i = 0; i < physicalSlots.length; i++) { |
| 8976 | physicalSlots[i] = slotMapping.get(i).getPhysicalSlotIndex(); |
| 8977 | } |
| 8978 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8979 | } finally { |
| 8980 | Binder.restoreCallingIdentity(identity); |
| 8981 | } |
| 8982 | } |
| 8983 | |
| 8984 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8985 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8986 | final long identity = Binder.clearCallingIdentity(); |
| 8987 | try { |
| 8988 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8989 | } finally { |
| 8990 | Binder.restoreCallingIdentity(identity); |
| 8991 | } |
| 8992 | } |
| 8993 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8994 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8995 | * A test API to reload the UICC profile. |
| 8996 | * |
| 8997 | * <p>Requires that the calling app has permission |
| 8998 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8999 | * @hide |
| 9000 | */ |
| 9001 | @Override |
| 9002 | public void refreshUiccProfile(int subId) { |
| 9003 | enforceModifyPermission(); |
| 9004 | |
| 9005 | final long identity = Binder.clearCallingIdentity(); |
| 9006 | try { |
| 9007 | Phone phone = getPhone(subId); |
| 9008 | if (phone == null) { |
| 9009 | return; |
| 9010 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9011 | UiccPort uiccPort = phone.getUiccPort(); |
| 9012 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9013 | return; |
| 9014 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9015 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9016 | if (uiccProfile == null) { |
| 9017 | return; |
| 9018 | } |
| 9019 | uiccProfile.refresh(); |
| 9020 | } finally { |
| 9021 | Binder.restoreCallingIdentity(identity); |
| 9022 | } |
| 9023 | } |
| 9024 | |
| 9025 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9026 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9027 | */ |
| 9028 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9029 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9030 | } |
| 9031 | |
| 9032 | /** |
| 9033 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9034 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9035 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9036 | */ |
| 9037 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9038 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9039 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9040 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9041 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9042 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9043 | return isDataRoamingEnabled; |
| 9044 | } |
| 9045 | |
| 9046 | /** |
| 9047 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9048 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9049 | */ |
| 9050 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9051 | List<Integer> list = TelephonyProperties.default_network(); |
| 9052 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 9053 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9054 | return list.get(phoneId); |
| 9055 | } |
| 9056 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9057 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9058 | |
| 9059 | @Override |
| 9060 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9061 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9062 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9063 | |
| 9064 | final long identity = Binder.clearCallingIdentity(); |
| 9065 | try { |
| 9066 | final Phone phone = getPhone(subId); |
| 9067 | if (phone == null) { |
| 9068 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9069 | return; |
| 9070 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9071 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9072 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9073 | if (carrierPrivilegeRules == null) { |
| 9074 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9075 | } else { |
| 9076 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9077 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9078 | } finally { |
| 9079 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9080 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9081 | } |
| 9082 | |
| 9083 | @Override |
| 9084 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9085 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9086 | |
| 9087 | final long identity = Binder.clearCallingIdentity(); |
| 9088 | try { |
| 9089 | final Phone phone = getPhone(subId); |
| 9090 | if (phone == null) { |
| 9091 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9092 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9093 | } |
| 9094 | return phone.getCarrierIdListVersion(); |
| 9095 | } finally { |
| 9096 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9097 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9098 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9099 | |
| 9100 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9101 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9102 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9103 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9104 | mApp, subId, callingPackage, callingFeatureId, |
| 9105 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9106 | return -1; |
| 9107 | } |
| 9108 | |
| 9109 | final long identity = Binder.clearCallingIdentity(); |
| 9110 | try { |
| 9111 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9112 | } finally { |
| 9113 | Binder.restoreCallingIdentity(identity); |
| 9114 | } |
| 9115 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9116 | |
| 9117 | @Override |
| 9118 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9119 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9120 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9121 | mApp, subId, "getCdmaRoamingMode"); |
| 9122 | |
| 9123 | final long identity = Binder.clearCallingIdentity(); |
| 9124 | try { |
| 9125 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9126 | } finally { |
| 9127 | Binder.restoreCallingIdentity(identity); |
| 9128 | } |
| 9129 | } |
| 9130 | |
| 9131 | @Override |
| 9132 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9133 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9134 | mApp, subId, "setCdmaRoamingMode"); |
| 9135 | |
| 9136 | final long identity = Binder.clearCallingIdentity(); |
| 9137 | try { |
| 9138 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9139 | } finally { |
| 9140 | Binder.restoreCallingIdentity(identity); |
| 9141 | } |
| 9142 | } |
| 9143 | |
| 9144 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9145 | public int getCdmaSubscriptionMode(int subId) { |
| 9146 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9147 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9148 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9149 | |
| 9150 | final long identity = Binder.clearCallingIdentity(); |
| 9151 | try { |
| 9152 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9153 | } finally { |
| 9154 | Binder.restoreCallingIdentity(identity); |
| 9155 | } |
| 9156 | } |
| 9157 | |
| 9158 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9159 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9160 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9161 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9162 | |
| 9163 | final long identity = Binder.clearCallingIdentity(); |
| 9164 | try { |
| 9165 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9166 | } finally { |
| 9167 | Binder.restoreCallingIdentity(identity); |
| 9168 | } |
| 9169 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9170 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9171 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9172 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9173 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9174 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9175 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9176 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9177 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9178 | } |
| 9179 | final long identity = Binder.clearCallingIdentity(); |
| 9180 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9181 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9182 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9183 | if (phone.getEmergencyNumberTracker() != null |
| 9184 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9185 | emergencyNumberListInternal.put( |
| 9186 | phone.getSubId(), |
| 9187 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9188 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9189 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9190 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9191 | } finally { |
| 9192 | Binder.restoreCallingIdentity(identity); |
| 9193 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9194 | } |
| 9195 | |
| 9196 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9197 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9198 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9199 | if (!exactMatch) { |
| 9200 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9201 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9202 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9203 | } |
| 9204 | final long identity = Binder.clearCallingIdentity(); |
| 9205 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9206 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9207 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9208 | && phone.getEmergencyNumberTracker() |
| 9209 | .isEmergencyNumber(number, exactMatch)) { |
| 9210 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9211 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9212 | } |
| 9213 | return false; |
| 9214 | } finally { |
| 9215 | Binder.restoreCallingIdentity(identity); |
| 9216 | } |
| 9217 | } |
| 9218 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9219 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9220 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9221 | */ |
| 9222 | @Override |
| 9223 | public void startEmergencyCallbackMode() { |
| 9224 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9225 | "startEmergencyCallbackMode"); |
| 9226 | enforceModifyPermission(); |
| 9227 | final long identity = Binder.clearCallingIdentity(); |
| 9228 | try { |
| 9229 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9230 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9231 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9232 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9233 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9234 | gsmCdmaPhone.obtainMessage( |
| 9235 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9236 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9237 | } |
| 9238 | } |
| 9239 | } finally { |
| 9240 | Binder.restoreCallingIdentity(identity); |
| 9241 | } |
| 9242 | } |
| 9243 | |
| 9244 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9245 | * Update emergency number list for test mode. |
| 9246 | */ |
| 9247 | @Override |
| 9248 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9249 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9250 | "updateEmergencyNumberListTestMode"); |
| 9251 | |
| 9252 | final long identity = Binder.clearCallingIdentity(); |
| 9253 | try { |
| 9254 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9255 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9256 | if (tracker != null) { |
| 9257 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9258 | } |
| 9259 | } |
| 9260 | } finally { |
| 9261 | Binder.restoreCallingIdentity(identity); |
| 9262 | } |
| 9263 | } |
| 9264 | |
| 9265 | /** |
| 9266 | * Get the full emergency number list for test mode. |
| 9267 | */ |
| 9268 | @Override |
| 9269 | public List<String> getEmergencyNumberListTestMode() { |
| 9270 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9271 | "getEmergencyNumberListTestMode"); |
| 9272 | |
| 9273 | final long identity = Binder.clearCallingIdentity(); |
| 9274 | try { |
| 9275 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9276 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9277 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9278 | if (tracker != null) { |
| 9279 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9280 | emergencyNumbers.add(num.getNumber()); |
| 9281 | } |
| 9282 | } |
| 9283 | } |
| 9284 | return new ArrayList<>(emergencyNumbers); |
| 9285 | } finally { |
| 9286 | Binder.restoreCallingIdentity(identity); |
| 9287 | } |
| 9288 | } |
| 9289 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9290 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9291 | public int getEmergencyNumberDbVersion(int subId) { |
| 9292 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9293 | |
| 9294 | final long identity = Binder.clearCallingIdentity(); |
| 9295 | try { |
| 9296 | final Phone phone = getPhone(subId); |
| 9297 | if (phone == null) { |
| 9298 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9299 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9300 | } |
| 9301 | return phone.getEmergencyNumberDbVersion(); |
| 9302 | } finally { |
| 9303 | Binder.restoreCallingIdentity(identity); |
| 9304 | } |
| 9305 | } |
| 9306 | |
| 9307 | @Override |
| 9308 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9309 | enforceModifyPermission(); |
| 9310 | |
| 9311 | final long identity = Binder.clearCallingIdentity(); |
| 9312 | try { |
| 9313 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9314 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9315 | if (tracker != null) { |
| 9316 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9317 | } |
| 9318 | } |
| 9319 | } finally { |
| 9320 | Binder.restoreCallingIdentity(identity); |
| 9321 | } |
| 9322 | } |
| 9323 | |
| 9324 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9325 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9326 | enforceActiveEmergencySessionPermission(); |
| 9327 | |
| 9328 | final long identity = Binder.clearCallingIdentity(); |
| 9329 | try { |
| 9330 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9331 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9332 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9333 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9334 | } |
| 9335 | } |
| 9336 | } finally { |
| 9337 | Binder.restoreCallingIdentity(identity); |
| 9338 | } |
| 9339 | } |
| 9340 | |
| 9341 | @Override |
| 9342 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9343 | enforceActiveEmergencySessionPermission(); |
| 9344 | |
| 9345 | final long identity = Binder.clearCallingIdentity(); |
| 9346 | try { |
| 9347 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9348 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9349 | if (tracker != null) { |
| 9350 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9351 | } |
| 9352 | } |
| 9353 | } finally { |
| 9354 | Binder.restoreCallingIdentity(identity); |
| 9355 | } |
| 9356 | } |
| 9357 | |
| 9358 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9359 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9360 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9361 | Phone phone = getPhone(subId); |
| 9362 | if (phone == null) { |
| 9363 | return null; |
| 9364 | } |
| 9365 | final long identity = Binder.clearCallingIdentity(); |
| 9366 | try { |
| 9367 | UiccProfile profile = UiccController.getInstance() |
| 9368 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9369 | if (profile != null) { |
| 9370 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9371 | } |
| 9372 | } finally { |
| 9373 | Binder.restoreCallingIdentity(identity); |
| 9374 | } |
| 9375 | return null; |
| 9376 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9377 | |
| 9378 | /** |
| 9379 | * Enable or disable a modem stack. |
| 9380 | */ |
| 9381 | @Override |
| 9382 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9383 | enforceModifyPermission(); |
| 9384 | |
| 9385 | final long identity = Binder.clearCallingIdentity(); |
| 9386 | try { |
| 9387 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9388 | if (phone == null) { |
| 9389 | return false; |
| 9390 | } else { |
| 9391 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9392 | } |
| 9393 | } finally { |
| 9394 | Binder.restoreCallingIdentity(identity); |
| 9395 | } |
| 9396 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9397 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9398 | /** |
| 9399 | * Whether a modem stack is enabled or not. |
| 9400 | */ |
| 9401 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9402 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9403 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9404 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9405 | if (phone == null) return false; |
| 9406 | |
| 9407 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9408 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9409 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9410 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9411 | } |
| 9412 | |
| 9413 | final long identity = Binder.clearCallingIdentity(); |
| 9414 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9415 | try { |
| 9416 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9417 | } catch (NoSuchElementException ex) { |
| 9418 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9419 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9420 | } finally { |
| 9421 | Binder.restoreCallingIdentity(identity); |
| 9422 | } |
| 9423 | } |
| 9424 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9425 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9426 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9427 | enforceModifyPermission(); |
| 9428 | |
| 9429 | final long identity = Binder.clearCallingIdentity(); |
| 9430 | try { |
| 9431 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9432 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9433 | .commit(); |
| 9434 | } finally { |
| 9435 | Binder.restoreCallingIdentity(identity); |
| 9436 | } |
| 9437 | } |
| 9438 | |
| 9439 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9440 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9441 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9442 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9443 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9444 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9445 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9446 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9447 | |
| 9448 | final long identity = Binder.clearCallingIdentity(); |
| 9449 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9450 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9451 | } finally { |
| 9452 | Binder.restoreCallingIdentity(identity); |
| 9453 | } |
| 9454 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9455 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9456 | @TelephonyManager.IsMultiSimSupportedResult |
| 9457 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9458 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9459 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9460 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9461 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9462 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9463 | } |
| 9464 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9465 | // supported by the modem, indicate that it is restricted. |
| 9466 | PhoneCapability staticCapability = |
| 9467 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9468 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9469 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9470 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9471 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9472 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9473 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9474 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9475 | } |
| 9476 | // Check if support of multiple SIMs is restricted by carrier |
| 9477 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9478 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9479 | } |
| 9480 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9481 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9482 | } |
| 9483 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9484 | /** |
| 9485 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9486 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9487 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9488 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9489 | * @param numOfSims number of active sims we want to switch to |
| 9490 | */ |
| 9491 | @Override |
| 9492 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9493 | if (numOfSims == 1) { |
| 9494 | enforceModifyPermission(); |
| 9495 | } else { |
| 9496 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9497 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9498 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9499 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9500 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9501 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9502 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9503 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9504 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9505 | return; |
| 9506 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9507 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9508 | } finally { |
| 9509 | Binder.restoreCallingIdentity(identity); |
| 9510 | } |
| 9511 | } |
| 9512 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9513 | @Override |
| 9514 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9515 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9516 | Phone phone = getPhone(subId); |
| 9517 | if (phone == null) { |
| 9518 | return false; |
| 9519 | } |
| 9520 | final long identity = Binder.clearCallingIdentity(); |
| 9521 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9522 | UiccPort uiccPort = phone.getUiccPort(); |
| 9523 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9524 | return false; |
| 9525 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9526 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9527 | if (uiccProfile == null) { |
| 9528 | return false; |
| 9529 | } |
| 9530 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9531 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9532 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9533 | } |
| 9534 | return false; |
| 9535 | } finally { |
| 9536 | Binder.restoreCallingIdentity(identity); |
| 9537 | } |
| 9538 | } |
| 9539 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9540 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9541 | * Get whether making changes to modem configurations will trigger reboot. |
| 9542 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9543 | */ |
| 9544 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9545 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9546 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9547 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9548 | mApp, subId, callingPackage, callingFeatureId, |
| 9549 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9550 | return false; |
| 9551 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9552 | final long identity = Binder.clearCallingIdentity(); |
| 9553 | try { |
| 9554 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9555 | } finally { |
| 9556 | Binder.restoreCallingIdentity(identity); |
| 9557 | } |
| 9558 | } |
| 9559 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9560 | private void updateModemStateMetrics() { |
| 9561 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9562 | // TODO: check the state for each modem if the api is ready. |
| 9563 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9564 | } |
| 9565 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9566 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame^] | 9567 | public int[] getSlotsMapping(@NonNull String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9568 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 9569 | |
| 9570 | final long identity = Binder.clearCallingIdentity(); |
| 9571 | try { |
| 9572 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 9573 | // All logical slots should have a mapping to a physical slot. |
| 9574 | int[] logicalSlotsMapping = new int[phoneCount]; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame^] | 9575 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9576 | for (int i = 0; i < slotInfos.length; i++) { |
| 9577 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 9578 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 9579 | } |
| 9580 | } |
| 9581 | return logicalSlotsMapping; |
| 9582 | } finally { |
| 9583 | Binder.restoreCallingIdentity(identity); |
| 9584 | } |
| 9585 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9586 | |
| 9587 | /** |
| 9588 | * Get the IRadio HAL Version |
| 9589 | */ |
| 9590 | @Override |
| 9591 | public int getRadioHalVersion() { |
| 9592 | Phone phone = getDefaultPhone(); |
| 9593 | if (phone == null) return -1; |
| 9594 | HalVersion hv = phone.getHalVersion(); |
| 9595 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9596 | return hv.major * 100 + hv.minor; |
| 9597 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9598 | |
| 9599 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9600 | * Get the current calling package name. |
| 9601 | * @return the current calling package name |
| 9602 | */ |
| 9603 | @Override |
| 9604 | public String getCurrentPackageName() { |
| 9605 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9606 | } |
| 9607 | |
| 9608 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9609 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9610 | * corresponding network requests on a subId. |
| 9611 | * |
| 9612 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9613 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9614 | * 2) APN is un-metered for this subscription, or |
| 9615 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9616 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9617 | * |
| 9618 | * @return whether data is allowed for a apn type. |
| 9619 | * |
| 9620 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9621 | */ |
| 9622 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9623 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9624 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9625 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9626 | |
| 9627 | // Now that all security checks passes, perform the operation as ourselves. |
| 9628 | final long identity = Binder.clearCallingIdentity(); |
| 9629 | try { |
| 9630 | Phone phone = getPhone(subId); |
| 9631 | if (phone == null) return false; |
| 9632 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9633 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9634 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9635 | } finally { |
| 9636 | Binder.restoreCallingIdentity(identity); |
| 9637 | } |
| 9638 | } |
| 9639 | |
| 9640 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9641 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9642 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9643 | |
| 9644 | // Now that all security checks passes, perform the operation as ourselves. |
| 9645 | final long identity = Binder.clearCallingIdentity(); |
| 9646 | try { |
| 9647 | Phone phone = getPhone(subId); |
| 9648 | if (phone == null) return true; // By default return true. |
| 9649 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9650 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9651 | } finally { |
| 9652 | Binder.restoreCallingIdentity(identity); |
| 9653 | } |
| 9654 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9655 | |
| 9656 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9657 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9658 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9659 | enforceModifyPermission(); |
| 9660 | long token = Binder.clearCallingIdentity(); |
| 9661 | try { |
| 9662 | Phone phone = getPhone(subscriptionId); |
| 9663 | if (phone == null) { |
| 9664 | try { |
| 9665 | if (resultCallback != null) { |
| 9666 | resultCallback.accept(false); |
| 9667 | } |
| 9668 | } catch (RemoteException e) { |
| 9669 | // ignore |
| 9670 | } |
| 9671 | return; |
| 9672 | } |
| 9673 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9674 | Pair.create(specifiers, (x) -> { |
| 9675 | try { |
| 9676 | if (resultCallback != null) { |
| 9677 | resultCallback.accept(x); |
| 9678 | } |
| 9679 | } catch (RemoteException e) { |
| 9680 | // ignore |
| 9681 | } |
| 9682 | }); |
| 9683 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9684 | } finally { |
| 9685 | Binder.restoreCallingIdentity(token); |
| 9686 | } |
| 9687 | } |
| 9688 | |
| 9689 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9690 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9691 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9692 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9693 | mApp, subId, "getSystemSelectionChannels"); |
| 9694 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9695 | final long identity = Binder.clearCallingIdentity(); |
| 9696 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 9697 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 9698 | if (result instanceof IllegalStateException) { |
| 9699 | throw (IllegalStateException) result; |
| 9700 | } |
| 9701 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9702 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9703 | return specifiers; |
| 9704 | } finally { |
| 9705 | Binder.restoreCallingIdentity(identity); |
| 9706 | } |
| 9707 | } |
| 9708 | |
| 9709 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9710 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9711 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9712 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9713 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9714 | if (iccRecords == null) { |
| 9715 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9716 | return false; |
| 9717 | } |
| 9718 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9719 | } |
| 9720 | |
| 9721 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9722 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9723 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9724 | if (callingPackage == null) { |
| 9725 | callingPackage = getCurrentPackageName(); |
| 9726 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9727 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9728 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9729 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9730 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9731 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9732 | } |
| 9733 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9734 | Intent intent = new Intent(); |
| 9735 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9736 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9737 | // Bring up choose default SMS subscription dialog right now |
| 9738 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9739 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9740 | mApp.startActivity(intent); |
| 9741 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9742 | |
| 9743 | @Override |
| 9744 | public String getMmsUAProfUrl(int subId) { |
| 9745 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9746 | final long identity = Binder.clearCallingIdentity(); |
| 9747 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9748 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9749 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9750 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9751 | return carrierUAProfUrl; |
| 9752 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9753 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9754 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9755 | } finally { |
| 9756 | Binder.restoreCallingIdentity(identity); |
| 9757 | } |
| 9758 | } |
| 9759 | |
| 9760 | @Override |
| 9761 | public String getMmsUserAgent(int subId) { |
| 9762 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9763 | final long identity = Binder.clearCallingIdentity(); |
| 9764 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9765 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9766 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9767 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9768 | return carrierUserAgent; |
| 9769 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9770 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9771 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9772 | } finally { |
| 9773 | Binder.restoreCallingIdentity(identity); |
| 9774 | } |
| 9775 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9776 | |
| 9777 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9778 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9779 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9780 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9781 | final long identity = Binder.clearCallingIdentity(); |
| 9782 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9783 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9784 | if (phone == null) return false; |
| 9785 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9786 | switch (policy) { |
| 9787 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9788 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9789 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9790 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9791 | default: |
| 9792 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9793 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9794 | } finally { |
| 9795 | Binder.restoreCallingIdentity(identity); |
| 9796 | } |
| 9797 | } |
| 9798 | |
| 9799 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9800 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9801 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9802 | enforceModifyPermission(); |
| 9803 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9804 | final long identity = Binder.clearCallingIdentity(); |
| 9805 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9806 | Phone phone = getPhone(subscriptionId); |
| 9807 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9808 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9809 | switch (policy) { |
| 9810 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9811 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9812 | break; |
| 9813 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9814 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9815 | break; |
| 9816 | default: |
| 9817 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9818 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9819 | } finally { |
| 9820 | Binder.restoreCallingIdentity(identity); |
| 9821 | } |
| 9822 | } |
| 9823 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9824 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9825 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9826 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9827 | * otherwise. |
| 9828 | */ |
| 9829 | @Override |
| 9830 | public void setCepEnabled(boolean isCepEnabled) { |
| 9831 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9832 | |
| 9833 | final long identity = Binder.clearCallingIdentity(); |
| 9834 | try { |
| 9835 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9836 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9837 | Phone defaultPhone = phone.getImsPhone(); |
| 9838 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9839 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9840 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9841 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9842 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9843 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9844 | + imsPhone.getMsisdn()); |
| 9845 | } |
| 9846 | } |
| 9847 | } finally { |
| 9848 | Binder.restoreCallingIdentity(identity); |
| 9849 | } |
| 9850 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9851 | |
| 9852 | /** |
| 9853 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9854 | * |
| 9855 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9856 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9857 | * before being read. |
| 9858 | */ |
| 9859 | @Override |
| 9860 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9861 | isCompressed) { |
| 9862 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9863 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9864 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9865 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9866 | } |
| 9867 | if (!isImsAvailableOnDevice()) { |
| 9868 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9869 | "IMS not available on device."); |
| 9870 | } |
| 9871 | |
| 9872 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9873 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9874 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9875 | } finally { |
| 9876 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9877 | } |
| 9878 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9879 | |
| 9880 | @Override |
| 9881 | public boolean isIccLockEnabled(int subId) { |
| 9882 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9883 | |
| 9884 | // Now that all security checks passes, perform the operation as ourselves. |
| 9885 | final long identity = Binder.clearCallingIdentity(); |
| 9886 | try { |
| 9887 | Phone phone = getPhone(subId); |
| 9888 | if (phone != null && phone.getIccCard() != null) { |
| 9889 | return phone.getIccCard().getIccLockEnabled(); |
| 9890 | } else { |
| 9891 | return false; |
| 9892 | } |
| 9893 | } finally { |
| 9894 | Binder.restoreCallingIdentity(identity); |
| 9895 | } |
| 9896 | } |
| 9897 | |
| 9898 | /** |
| 9899 | * Set the ICC pin lock enabled or disabled. |
| 9900 | * |
| 9901 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9902 | * three cases: |
| 9903 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9904 | * successfully. |
| 9905 | * - Positive number and zero for remaining password attempts. |
| 9906 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9907 | * |
| 9908 | */ |
| 9909 | @Override |
| 9910 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9911 | enforceModifyPermission(); |
| 9912 | |
| 9913 | Phone phone = getPhone(subId); |
| 9914 | if (phone == null) { |
| 9915 | return 0; |
| 9916 | } |
| 9917 | // Now that all security checks passes, perform the operation as ourselves. |
| 9918 | final long identity = Binder.clearCallingIdentity(); |
| 9919 | try { |
| 9920 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9921 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9922 | return attemptsRemaining; |
| 9923 | |
| 9924 | } catch (Exception e) { |
| 9925 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9926 | } finally { |
| 9927 | Binder.restoreCallingIdentity(identity); |
| 9928 | } |
| 9929 | return 0; |
| 9930 | } |
| 9931 | |
| 9932 | /** |
| 9933 | * Change the ICC password used in ICC pin lock. |
| 9934 | * |
| 9935 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9936 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9937 | * - Positive number and zero for remaining password attempts. |
| 9938 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9939 | * |
| 9940 | */ |
| 9941 | @Override |
| 9942 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9943 | enforceModifyPermission(); |
| 9944 | |
| 9945 | Phone phone = getPhone(subId); |
| 9946 | if (phone == null) { |
| 9947 | return 0; |
| 9948 | } |
| 9949 | // Now that all security checks passes, perform the operation as ourselves. |
| 9950 | final long identity = Binder.clearCallingIdentity(); |
| 9951 | try { |
| 9952 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9953 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9954 | return attemptsRemaining; |
| 9955 | |
| 9956 | } catch (Exception e) { |
| 9957 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9958 | } finally { |
| 9959 | Binder.restoreCallingIdentity(identity); |
| 9960 | } |
| 9961 | return 0; |
| 9962 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9963 | |
| 9964 | /** |
| 9965 | * Request for receiving user activity notification |
| 9966 | */ |
| 9967 | @Override |
| 9968 | public void requestUserActivityNotification() { |
| 9969 | if (!mNotifyUserActivity.get() |
| 9970 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9971 | mNotifyUserActivity.set(true); |
| 9972 | } |
| 9973 | } |
| 9974 | |
| 9975 | /** |
| 9976 | * Called when userActivity is signalled in the power manager. |
| 9977 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9978 | */ |
| 9979 | @Override |
| 9980 | public void userActivity() { |
| 9981 | // *************************************** |
| 9982 | // * Inherited from PhoneWindowManager * |
| 9983 | // *************************************** |
| 9984 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9985 | // WITH ITS LOCKS HELD. |
| 9986 | // |
| 9987 | // This code must be VERY careful about the locks |
| 9988 | // it acquires. |
| 9989 | // In fact, the current code acquires way too many, |
| 9990 | // and probably has lurking deadlocks. |
| 9991 | |
| 9992 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9993 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9994 | } |
| 9995 | |
| 9996 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9997 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9998 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9999 | } |
| 10000 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10001 | |
| 10002 | @Override |
| 10003 | public boolean canConnectTo5GInDsdsMode() { |
| 10004 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10005 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10006 | |
| 10007 | @Override |
| 10008 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10009 | String callingFeatureId) { |
| 10010 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10011 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10012 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10013 | } |
| 10014 | |
| 10015 | Phone phone = getPhone(subId); |
| 10016 | if (phone == null) { |
| 10017 | throw new RuntimeException("phone is not available"); |
| 10018 | } |
| 10019 | // Now that all security checks passes, perform the operation as ourselves. |
| 10020 | final long identity = Binder.clearCallingIdentity(); |
| 10021 | try { |
| 10022 | return phone.getEquivalentHomePlmns(); |
| 10023 | } finally { |
| 10024 | Binder.restoreCallingIdentity(identity); |
| 10025 | } |
| 10026 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10027 | |
| 10028 | @Override |
| 10029 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10030 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10031 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10032 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10033 | if (radioInterfaceCapabilities == null) { |
| 10034 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10035 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10036 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10037 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10038 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10039 | @Override |
| 10040 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10041 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10042 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10043 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10044 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10045 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10046 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10047 | if (DBG) { |
| 10048 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10049 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10050 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10051 | } |
| 10052 | |
| 10053 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10054 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10055 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10056 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10057 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10058 | if (callback != null) { |
| 10059 | try { |
| 10060 | callback.onAuthenticationFailure( |
| 10061 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10062 | } catch (RemoteException exception) { |
| 10063 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10064 | } |
| 10065 | return; |
| 10066 | } |
| 10067 | } |
| 10068 | |
| 10069 | final long token = Binder.clearCallingIdentity(); |
| 10070 | try { |
| 10071 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10072 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 10073 | forceBootStrapping, callback)); |
| 10074 | } finally { |
| 10075 | Binder.restoreCallingIdentity(token); |
| 10076 | } |
| 10077 | } |
| 10078 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10079 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10080 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10081 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10082 | * requested radio power state will actually be set. See {@link |
| 10083 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10084 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10085 | * @param enable {@code true} if trying to turn radio on. |
| 10086 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10087 | * false}. |
| 10088 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10089 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10090 | boolean isPhoneAvailable = false; |
| 10091 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10092 | Phone phone = PhoneFactory.getPhone(i); |
| 10093 | if (phone != null) { |
| 10094 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 10095 | isPhoneAvailable = true; |
| 10096 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10097 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10098 | |
| 10099 | // return true if successfully informed the phone object about the thermal radio power |
| 10100 | // request. |
| 10101 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10102 | } |
| 10103 | |
| 10104 | private int handleDataThrottlingRequest(int subId, |
| 10105 | DataThrottlingRequest dataThrottlingRequest) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10106 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10107 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10108 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10109 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10110 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10111 | } |
| 10112 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10113 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10114 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10115 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10116 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10117 | } |
| 10118 | |
| 10119 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 10120 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10121 | if (isDataThrottlingSupported) { |
| 10122 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10123 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10124 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10125 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10126 | } else if (thermalMitigationResult |
| 10127 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10128 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10129 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10130 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10131 | } |
| 10132 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10133 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10134 | |
| 10135 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10136 | } |
| 10137 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10138 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10139 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10140 | for (String pckg : context.getResources() |
| 10141 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10142 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10143 | } |
| 10144 | } |
| 10145 | |
| 10146 | return sThermalMitigationAllowlistedPackages; |
| 10147 | } |
| 10148 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10149 | private boolean isAnyPhoneInEmergencyState() { |
| 10150 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10151 | if (tm.isInEmergencyCall()) { |
| 10152 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10153 | return true; |
| 10154 | } |
| 10155 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10156 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10157 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10158 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10159 | + phone.isInEcm()); |
| 10160 | return true; |
| 10161 | } |
| 10162 | } |
| 10163 | |
| 10164 | return false; |
| 10165 | } |
| 10166 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10167 | /** |
| 10168 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10169 | * @param packageName name of package to be allowlisted |
| 10170 | * @param context |
| 10171 | */ |
| 10172 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10173 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10174 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10175 | } |
| 10176 | |
| 10177 | /** |
| 10178 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10179 | * @param packageName name of package to remove from allowlist |
| 10180 | * @param context |
| 10181 | */ |
| 10182 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10183 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10184 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10185 | } |
| 10186 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10187 | /** |
| 10188 | * Thermal mitigation request to control functionalities at modem. |
| 10189 | * |
| 10190 | * @param subId the id of the subscription. |
| 10191 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10192 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10193 | * |
| 10194 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10195 | */ |
| 10196 | @Override |
| 10197 | @ThermalMitigationResult |
| 10198 | public int sendThermalMitigationRequest( |
| 10199 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10200 | ThermalMitigationRequest thermalMitigationRequest, |
| 10201 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10202 | enforceModifyPermission(); |
| 10203 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10204 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10205 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10206 | .contains(callingPackage)) { |
| 10207 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10208 | + "calling package: " + callingPackage); |
| 10209 | } |
| 10210 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10211 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10212 | final long identity = Binder.clearCallingIdentity(); |
| 10213 | |
| 10214 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10215 | try { |
| 10216 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10217 | switch (thermalMitigationAction) { |
| 10218 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10219 | thermalMitigationResult = |
| 10220 | handleDataThrottlingRequest(subId, |
| 10221 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 10222 | break; |
| 10223 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10224 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10225 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10226 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10227 | } |
| 10228 | |
| 10229 | // Ensure that radio is on. If not able to power on due to phone being |
| 10230 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10231 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10232 | thermalMitigationResult = |
| 10233 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10234 | break; |
| 10235 | } |
| 10236 | |
| 10237 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 10238 | false); |
| 10239 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10240 | break; |
| 10241 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10242 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10243 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10244 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10245 | } |
| 10246 | |
| 10247 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10248 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10249 | Phone phone = getPhone(subId); |
| 10250 | if (phone == null) { |
| 10251 | thermalMitigationResult = |
| 10252 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10253 | break; |
| 10254 | } |
| 10255 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10256 | TelephonyConnectionService service = |
| 10257 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10258 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10259 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10260 | thermalMitigationResult = |
| 10261 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10262 | break; |
| 10263 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10264 | thermalMitigationResult = |
| 10265 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10266 | break; |
| 10267 | } |
| 10268 | } else { |
| 10269 | thermalMitigationResult = |
| 10270 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10271 | break; |
| 10272 | } |
| 10273 | |
| 10274 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10275 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10276 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10277 | thermalMitigationResult = |
| 10278 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10279 | break; |
| 10280 | } |
| 10281 | thermalMitigationResult = |
| 10282 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10283 | break; |
| 10284 | default: |
| 10285 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10286 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10287 | } |
| 10288 | } catch (IllegalArgumentException e) { |
| 10289 | throw e; |
| 10290 | } catch (Exception e) { |
| 10291 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10292 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10293 | } finally { |
| 10294 | Binder.restoreCallingIdentity(identity); |
| 10295 | } |
| 10296 | |
| 10297 | if (DBG) { |
| 10298 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10299 | + thermalMitigationResult); |
| 10300 | } |
| 10301 | |
| 10302 | return thermalMitigationResult; |
| 10303 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10304 | |
| 10305 | /** |
| 10306 | * Set the GbaService Package Name that Telephony will bind to. |
| 10307 | * |
| 10308 | * @param subId The sim that the GbaService is associated with. |
| 10309 | * @param packageName The name of the package to be replaced with. |
| 10310 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10311 | */ |
| 10312 | @Override |
| 10313 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10314 | enforceModifyPermission(); |
| 10315 | |
| 10316 | final long identity = Binder.clearCallingIdentity(); |
| 10317 | try { |
| 10318 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10319 | } finally { |
| 10320 | Binder.restoreCallingIdentity(identity); |
| 10321 | } |
| 10322 | } |
| 10323 | |
| 10324 | /** |
| 10325 | * Return the package name of the currently bound GbaService. |
| 10326 | * |
| 10327 | * @param subId The sim that the GbaService is associated with. |
| 10328 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10329 | */ |
| 10330 | @Override |
| 10331 | public String getBoundGbaService(int subId) { |
| 10332 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10333 | |
| 10334 | final long identity = Binder.clearCallingIdentity(); |
| 10335 | try { |
| 10336 | return getGbaManager(subId).getServicePackage(); |
| 10337 | } finally { |
| 10338 | Binder.restoreCallingIdentity(identity); |
| 10339 | } |
| 10340 | } |
| 10341 | |
| 10342 | /** |
| 10343 | * Set the release time for telephony to unbind GbaService. |
| 10344 | * |
| 10345 | * @param subId The sim that the GbaService is associated with. |
| 10346 | * @param interval The release time to unbind GbaService by millisecond. |
| 10347 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10348 | */ |
| 10349 | @Override |
| 10350 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10351 | enforceModifyPermission(); |
| 10352 | |
| 10353 | final long identity = Binder.clearCallingIdentity(); |
| 10354 | try { |
| 10355 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10356 | } finally { |
| 10357 | Binder.restoreCallingIdentity(identity); |
| 10358 | } |
| 10359 | } |
| 10360 | |
| 10361 | /** |
| 10362 | * Return the release time for telephony to unbind GbaService. |
| 10363 | * |
| 10364 | * @param subId The sim that the GbaService is associated with. |
| 10365 | * @return The release time to unbind GbaService by millisecond. |
| 10366 | */ |
| 10367 | @Override |
| 10368 | public int getGbaReleaseTime(int subId) { |
| 10369 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10370 | |
| 10371 | final long identity = Binder.clearCallingIdentity(); |
| 10372 | try { |
| 10373 | return getGbaManager(subId).getReleaseTime(); |
| 10374 | } finally { |
| 10375 | Binder.restoreCallingIdentity(identity); |
| 10376 | } |
| 10377 | } |
| 10378 | |
| 10379 | private GbaManager getGbaManager(int subId) { |
| 10380 | GbaManager instance = GbaManager.getInstance(subId); |
| 10381 | if (instance == null) { |
| 10382 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10383 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10384 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10385 | } |
| 10386 | return instance; |
| 10387 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10388 | |
| 10389 | /** |
| 10390 | * indicate whether the device and the carrier can support |
| 10391 | * RCS VoLTE single registration. |
| 10392 | */ |
| 10393 | @Override |
| 10394 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10395 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10396 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10397 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10398 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10399 | |
| 10400 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10401 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10402 | } |
| 10403 | |
| 10404 | final long identity = Binder.clearCallingIdentity(); |
| 10405 | try { |
| 10406 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10407 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10408 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10409 | if (isCapable != null) { |
| 10410 | return isCapable; |
| 10411 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10412 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10413 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10414 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10415 | } finally { |
| 10416 | Binder.restoreCallingIdentity(identity); |
| 10417 | } |
| 10418 | } |
| 10419 | |
| 10420 | /** |
| 10421 | * Register RCS provisioning callback. |
| 10422 | */ |
| 10423 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10424 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10425 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10426 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10427 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10428 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10429 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10430 | |
| 10431 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10432 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10433 | } |
| 10434 | if (!isImsAvailableOnDevice()) { |
| 10435 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10436 | "IMS not available on device."); |
| 10437 | } |
| 10438 | |
| 10439 | final long identity = Binder.clearCallingIdentity(); |
| 10440 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10441 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10442 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10443 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10444 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10445 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10446 | } finally { |
| 10447 | Binder.restoreCallingIdentity(identity); |
| 10448 | } |
| 10449 | } |
| 10450 | |
| 10451 | /** |
| 10452 | * Unregister RCS provisioning callback. |
| 10453 | */ |
| 10454 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10455 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10456 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10457 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10458 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10459 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10460 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10461 | |
| 10462 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10463 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10464 | } |
| 10465 | if (!isImsAvailableOnDevice()) { |
| 10466 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10467 | "IMS not available on device."); |
| 10468 | } |
| 10469 | |
| 10470 | final long identity = Binder.clearCallingIdentity(); |
| 10471 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10472 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10473 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10474 | } finally { |
| 10475 | Binder.restoreCallingIdentity(identity); |
| 10476 | } |
| 10477 | } |
| 10478 | |
| 10479 | /** |
| 10480 | * trigger RCS reconfiguration. |
| 10481 | */ |
| 10482 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10483 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10484 | "triggerRcsReconfiguration", |
| 10485 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10486 | |
| 10487 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10488 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10489 | } |
| 10490 | if (!isImsAvailableOnDevice()) { |
| 10491 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10492 | "IMS not available on device."); |
| 10493 | } |
| 10494 | |
| 10495 | final long identity = Binder.clearCallingIdentity(); |
| 10496 | try { |
| 10497 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10498 | } finally { |
| 10499 | Binder.restoreCallingIdentity(identity); |
| 10500 | } |
| 10501 | } |
| 10502 | |
| 10503 | /** |
| 10504 | * Provide the client configuration parameters of the RCS application. |
| 10505 | */ |
| 10506 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10507 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10508 | "setRcsClientConfiguration", |
| 10509 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10510 | |
| 10511 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10512 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10513 | } |
| 10514 | if (!isImsAvailableOnDevice()) { |
| 10515 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10516 | "IMS not available on device."); |
| 10517 | } |
| 10518 | |
| 10519 | final long identity = Binder.clearCallingIdentity(); |
| 10520 | |
| 10521 | try { |
| 10522 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10523 | if (configBinder == null) { |
| 10524 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10525 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10526 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10527 | } else { |
| 10528 | configBinder.setRcsClientConfiguration(rcc); |
| 10529 | } |
| 10530 | } catch (RemoteException e) { |
| 10531 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10532 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10533 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10534 | } finally { |
| 10535 | Binder.restoreCallingIdentity(identity); |
| 10536 | } |
| 10537 | } |
| 10538 | |
| 10539 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10540 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10541 | */ |
| 10542 | @Override |
| 10543 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10544 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10545 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10546 | |
| 10547 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10548 | } |
| 10549 | |
| 10550 | /** |
| 10551 | * Gets the test mode for RCS VoLTE single registration. |
| 10552 | */ |
| 10553 | @Override |
| 10554 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10555 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10556 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10557 | |
| 10558 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10559 | } |
| 10560 | |
| 10561 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10562 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10563 | */ |
| 10564 | @Override |
| 10565 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10566 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10567 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10568 | enforceModifyPermission(); |
| 10569 | |
| 10570 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10571 | : Boolean.parseBoolean(enabledStr); |
| 10572 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10573 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10574 | } |
| 10575 | |
| 10576 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10577 | * Sends a device to device communication message. Only usable via shell. |
| 10578 | * @param message message to send. |
| 10579 | * @param value message value. |
| 10580 | */ |
| 10581 | @Override |
| 10582 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10583 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10584 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10585 | enforceModifyPermission(); |
| 10586 | |
| 10587 | final long identity = Binder.clearCallingIdentity(); |
| 10588 | try { |
| 10589 | TelephonyConnectionService service = |
| 10590 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10591 | if (service == null) { |
| 10592 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10593 | return; |
| 10594 | } |
| 10595 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10596 | } finally { |
| 10597 | Binder.restoreCallingIdentity(identity); |
| 10598 | } |
| 10599 | } |
| 10600 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10601 | /** |
| 10602 | * Sets the specified device to device transport active. |
| 10603 | * @param transport The transport to set active. |
| 10604 | */ |
| 10605 | @Override |
| 10606 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10607 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10608 | "setActiveDeviceToDeviceTransport"); |
| 10609 | enforceModifyPermission(); |
| 10610 | |
| 10611 | final long identity = Binder.clearCallingIdentity(); |
| 10612 | try { |
| 10613 | TelephonyConnectionService service = |
| 10614 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10615 | if (service == null) { |
| 10616 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10617 | return; |
| 10618 | } |
| 10619 | service.setActiveDeviceToDeviceTransport(transport); |
| 10620 | } finally { |
| 10621 | Binder.restoreCallingIdentity(identity); |
| 10622 | } |
| 10623 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10624 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10625 | @Override |
| 10626 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10627 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10628 | "setDeviceToDeviceForceEnabled"); |
| 10629 | |
| 10630 | final long identity = Binder.clearCallingIdentity(); |
| 10631 | try { |
| 10632 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10633 | p -> { |
| 10634 | Phone thePhone = p.getImsPhone(); |
| 10635 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10636 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10637 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10638 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10639 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10640 | (ImsPhoneCallTracker) tracker; |
| 10641 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10642 | } |
| 10643 | } |
| 10644 | } |
| 10645 | ); |
| 10646 | } finally { |
| 10647 | Binder.restoreCallingIdentity(identity); |
| 10648 | } |
| 10649 | } |
| 10650 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10651 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10652 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10653 | */ |
| 10654 | @Override |
| 10655 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10656 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10657 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10658 | } |
| 10659 | |
| 10660 | /** |
| 10661 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10662 | */ |
| 10663 | @Override |
| 10664 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10665 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10666 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10667 | enforceModifyPermission(); |
| 10668 | |
| 10669 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10670 | : Boolean.parseBoolean(enabledStr); |
| 10671 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10672 | subId, enabled); |
| 10673 | } |
| 10674 | |
| 10675 | /** |
| 10676 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10677 | */ |
| 10678 | @Override |
| 10679 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10680 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10681 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10682 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10683 | |
| 10684 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 10685 | * Overrides the ims feature validation result |
| 10686 | */ |
| 10687 | @Override |
| 10688 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 10689 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10690 | "setImsFeatureValidationOverride"); |
| 10691 | |
| 10692 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10693 | : Boolean.parseBoolean(enabledStr); |
| 10694 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 10695 | subId, enabled); |
| 10696 | } |
| 10697 | |
| 10698 | /** |
| 10699 | * Gets the ims feature validation override value |
| 10700 | */ |
| 10701 | @Override |
| 10702 | public boolean getImsFeatureValidationOverride(int subId) { |
| 10703 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10704 | "getImsFeatureValidationOverride"); |
| 10705 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 10706 | } |
| 10707 | |
| 10708 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10709 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10710 | * their mobile plan. |
| 10711 | */ |
| 10712 | @Override |
| 10713 | public String getMobileProvisioningUrl() { |
| 10714 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10715 | final long identity = Binder.clearCallingIdentity(); |
| 10716 | try { |
| 10717 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10718 | } finally { |
| 10719 | Binder.restoreCallingIdentity(identity); |
| 10720 | } |
| 10721 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10722 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10723 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10724 | * Get the EAB contact from the EAB database. |
| 10725 | */ |
| 10726 | @Override |
| 10727 | public String getContactFromEab(String contact) { |
| 10728 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10729 | enforceModifyPermission(); |
| 10730 | final long identity = Binder.clearCallingIdentity(); |
| 10731 | try { |
| 10732 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10733 | } finally { |
| 10734 | Binder.restoreCallingIdentity(identity); |
| 10735 | } |
| 10736 | } |
| 10737 | |
| 10738 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 10739 | * Get the EAB capability from the EAB database. |
| 10740 | */ |
| 10741 | @Override |
| 10742 | public String getCapabilityFromEab(String contact) { |
| 10743 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 10744 | enforceModifyPermission(); |
| 10745 | final long identity = Binder.clearCallingIdentity(); |
| 10746 | try { |
| 10747 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 10748 | } finally { |
| 10749 | Binder.restoreCallingIdentity(identity); |
| 10750 | } |
| 10751 | } |
| 10752 | |
| 10753 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10754 | * Remove the EAB contacts from the EAB database. |
| 10755 | */ |
| 10756 | @Override |
| 10757 | public int removeContactFromEab(int subId, String contacts) { |
| 10758 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10759 | enforceModifyPermission(); |
| 10760 | final long identity = Binder.clearCallingIdentity(); |
| 10761 | try { |
| 10762 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10763 | } finally { |
| 10764 | Binder.restoreCallingIdentity(identity); |
| 10765 | } |
| 10766 | } |
| 10767 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10768 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10769 | public boolean getDeviceUceEnabled() { |
| 10770 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10771 | final long identity = Binder.clearCallingIdentity(); |
| 10772 | try { |
| 10773 | return mApp.getDeviceUceEnabled(); |
| 10774 | } finally { |
| 10775 | Binder.restoreCallingIdentity(identity); |
| 10776 | } |
| 10777 | } |
| 10778 | |
| 10779 | @Override |
| 10780 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10781 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10782 | final long identity = Binder.clearCallingIdentity(); |
| 10783 | try { |
| 10784 | mApp.setDeviceUceEnabled(isEnabled); |
| 10785 | } finally { |
| 10786 | Binder.restoreCallingIdentity(identity); |
| 10787 | } |
| 10788 | } |
| 10789 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10790 | /** |
| 10791 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10792 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10793 | */ |
| 10794 | // Used for SHELL command only right now. |
| 10795 | @Override |
| 10796 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 10797 | List<String> featureTags) { |
| 10798 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10799 | "addUceRegistrationOverrideShell"); |
| 10800 | final long identity = Binder.clearCallingIdentity(); |
| 10801 | try { |
| 10802 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 10803 | new ArraySet<>(featureTags)); |
| 10804 | } catch (ImsException e) { |
| 10805 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10806 | } finally { |
| 10807 | Binder.restoreCallingIdentity(identity); |
| 10808 | } |
| 10809 | } |
| 10810 | |
| 10811 | /** |
| 10812 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10813 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10814 | */ |
| 10815 | // Used for SHELL command only right now. |
| 10816 | @Override |
| 10817 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 10818 | List<String> featureTags) { |
| 10819 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10820 | "removeUceRegistrationOverrideShell"); |
| 10821 | final long identity = Binder.clearCallingIdentity(); |
| 10822 | try { |
| 10823 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 10824 | new ArraySet<>(featureTags)); |
| 10825 | } catch (ImsException e) { |
| 10826 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10827 | } finally { |
| 10828 | Binder.restoreCallingIdentity(identity); |
| 10829 | } |
| 10830 | } |
| 10831 | |
| 10832 | /** |
| 10833 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 10834 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10835 | */ |
| 10836 | // Used for SHELL command only right now. |
| 10837 | @Override |
| 10838 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 10839 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10840 | "clearUceRegistrationOverrideShell"); |
| 10841 | final long identity = Binder.clearCallingIdentity(); |
| 10842 | try { |
| 10843 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 10844 | } catch (ImsException e) { |
| 10845 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10846 | } finally { |
| 10847 | Binder.restoreCallingIdentity(identity); |
| 10848 | } |
| 10849 | } |
| 10850 | |
| 10851 | /** |
| 10852 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10853 | */ |
| 10854 | // Used for SHELL command only right now. |
| 10855 | @Override |
| 10856 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 10857 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10858 | "getLatestRcsContactUceCapabilityShell"); |
| 10859 | final long identity = Binder.clearCallingIdentity(); |
| 10860 | try { |
| 10861 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 10862 | } catch (ImsException e) { |
| 10863 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10864 | } finally { |
| 10865 | Binder.restoreCallingIdentity(identity); |
| 10866 | } |
| 10867 | } |
| 10868 | |
| 10869 | /** |
| 10870 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 10871 | * device does not have an active PUBLISH. |
| 10872 | */ |
| 10873 | // Used for SHELL command only right now. |
| 10874 | @Override |
| 10875 | public String getLastUcePidfXmlShell(int subId) { |
| 10876 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 10877 | final long identity = Binder.clearCallingIdentity(); |
| 10878 | try { |
| 10879 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 10880 | } catch (ImsException e) { |
| 10881 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10882 | } finally { |
| 10883 | Binder.restoreCallingIdentity(identity); |
| 10884 | } |
| 10885 | } |
| 10886 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 10887 | /** |
| 10888 | * Remove UCE requests cannot be sent to the network status. |
| 10889 | */ |
| 10890 | // Used for SHELL command only right now. |
| 10891 | @Override |
| 10892 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 10893 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 10894 | final long identity = Binder.clearCallingIdentity(); |
| 10895 | try { |
| 10896 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 10897 | } catch (ImsException e) { |
| 10898 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10899 | } finally { |
| 10900 | Binder.restoreCallingIdentity(identity); |
| 10901 | } |
| 10902 | } |
| 10903 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 10904 | /** |
| 10905 | * Remove UCE requests cannot be sent to the network status. |
| 10906 | */ |
| 10907 | // Used for SHELL command only. |
| 10908 | @Override |
| 10909 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 10910 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 10911 | final long identity = Binder.clearCallingIdentity(); |
| 10912 | try { |
| 10913 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 10914 | } catch (ImsException e) { |
| 10915 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10916 | } finally { |
| 10917 | Binder.restoreCallingIdentity(identity); |
| 10918 | } |
| 10919 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10920 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10921 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10922 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10923 | String callingPackage) { |
| 10924 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10925 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 10926 | |
| 10927 | final int callingUid = Binder.getCallingUid(); |
| 10928 | // Verify that tha callingPackage belongs to the calling UID |
| 10929 | mApp.getSystemService(AppOpsManager.class) |
| 10930 | .checkPackage(callingUid, callingPackage); |
| 10931 | |
| 10932 | validateSignalStrengthUpdateRequest(request, callingUid); |
| 10933 | |
| 10934 | final long identity = Binder.clearCallingIdentity(); |
| 10935 | try { |
| 10936 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10937 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10938 | |
| 10939 | if (result instanceof IllegalStateException) { |
| 10940 | throw (IllegalStateException) result; |
| 10941 | } |
| 10942 | } finally { |
| 10943 | Binder.restoreCallingIdentity(identity); |
| 10944 | } |
| 10945 | } |
| 10946 | |
| 10947 | @Override |
| 10948 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10949 | String callingPackage) { |
| 10950 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10951 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 10952 | |
| 10953 | final int callingUid = Binder.getCallingUid(); |
| 10954 | // Verify that tha callingPackage belongs to the calling UID |
| 10955 | mApp.getSystemService(AppOpsManager.class) |
| 10956 | .checkPackage(callingUid, callingPackage); |
| 10957 | |
| 10958 | final long identity = Binder.clearCallingIdentity(); |
| 10959 | try { |
| 10960 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10961 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10962 | |
| 10963 | if (result instanceof IllegalStateException) { |
| 10964 | throw (IllegalStateException) result; |
| 10965 | } |
| 10966 | } finally { |
| 10967 | Binder.restoreCallingIdentity(identity); |
| 10968 | } |
| 10969 | } |
| 10970 | |
| 10971 | private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request, |
| 10972 | int callingUid) { |
| 10973 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 10974 | // phone/system process do not have further restriction on request |
| 10975 | return; |
| 10976 | } |
| 10977 | |
| 10978 | // Applications has restrictions on how to use the request: |
| 10979 | // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle |
| 10980 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
| 10981 | // This is not system caller which has been checked above |
| 10982 | throw new IllegalArgumentException( |
| 10983 | "Only system can set isSystemThresholdReportingRequestedWhileIdle"); |
| 10984 | } |
| 10985 | |
| 10986 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 10987 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 10988 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 10989 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 10990 | || info.isEnabled()) { |
| 10991 | throw new IllegalArgumentException( |
| 10992 | "Only system can set hide fields in SignalThresholdInfo"); |
| 10993 | } |
| 10994 | |
| 10995 | // Thresholds length for each RAN need in range. This has been validated in |
| 10996 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 10997 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 10998 | final int[] thresholds = info.getThresholds(); |
| 10999 | Objects.requireNonNull(thresholds); |
| 11000 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11001 | || thresholds.length |
| 11002 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11003 | throw new IllegalArgumentException( |
| 11004 | "thresholds length is out of range: " + thresholds.length); |
| 11005 | } |
| 11006 | } |
| 11007 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11008 | |
| 11009 | /** |
| 11010 | * Gets the current phone capability. |
| 11011 | * |
| 11012 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11013 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11014 | * It's used to evaluate possible phone config change, for example from single |
| 11015 | * SIM device to multi-SIM device. |
| 11016 | */ |
| 11017 | @Override |
| 11018 | public PhoneCapability getPhoneCapability() { |
| 11019 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11020 | final long identity = Binder.clearCallingIdentity(); |
| 11021 | try { |
| 11022 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11023 | } finally { |
| 11024 | Binder.restoreCallingIdentity(identity); |
| 11025 | } |
| 11026 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11027 | |
| 11028 | /** |
| 11029 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11030 | * required to be done shortly after the API is invoked. |
| 11031 | */ |
| 11032 | @Override |
| 11033 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11034 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11035 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11036 | enforceRebootPermission(); |
| 11037 | |
| 11038 | final long identity = Binder.clearCallingIdentity(); |
| 11039 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11040 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11041 | } finally { |
| 11042 | Binder.restoreCallingIdentity(identity); |
| 11043 | } |
| 11044 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11045 | |
| 11046 | /** |
| 11047 | * Request to get the current slicing configuration including URSP rules and |
| 11048 | * NSSAIs (configured, allowed and rejected). |
| 11049 | * |
| 11050 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11051 | */ |
| 11052 | @Override |
| 11053 | public void getSlicingConfig(ResultReceiver callback) { |
| 11054 | enforceReadPrivilegedPermission("getSlicingConfig"); |
| 11055 | |
| 11056 | final long identity = Binder.clearCallingIdentity(); |
| 11057 | try { |
| 11058 | Phone phone = getDefaultPhone(); |
| 11059 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11060 | } finally { |
| 11061 | Binder.restoreCallingIdentity(identity); |
| 11062 | } |
| 11063 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 11064 | } |