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; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 30 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 31 | import android.app.PendingIntent; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 32 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 33 | import android.app.role.RoleManager; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 34 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 35 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 36 | import android.content.Context; |
| 37 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 38 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 39 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 40 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 41 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.net.Uri; |
| 43 | import android.os.AsyncResult; |
| 44 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 45 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 46 | import android.os.Bundle; |
| 47 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 48 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 49 | import android.os.Looper; |
| 50 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 51 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 52 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 53 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 54 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 55 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 56 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 57 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 58 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 59 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 60 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 61 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 62 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 63 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 64 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 65 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 66 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 67 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 68 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 69 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 70 | import android.telecom.TelecomManager; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 71 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 72 | import android.telephony.Annotation.ThermalMitigationResult; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 73 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 74 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 75 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 76 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 77 | import android.telephony.CellIdentityCdma; |
| 78 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 79 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 80 | import android.telephony.CellInfoGsm; |
| 81 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 82 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 83 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 84 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 85 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 86 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 87 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 88 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 89 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 90 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 91 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 92 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 93 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 94 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 95 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 96 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 97 | import android.telephony.SignalStrengthUpdateRequest; |
| 98 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 99 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 100 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 101 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 102 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 103 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 104 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 105 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 106 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 107 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 108 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 109 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 110 | import android.telephony.data.ApnSetting; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 111 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 112 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 113 | import android.telephony.gba.GbaAuthRequest; |
| 114 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 115 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 116 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 117 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 118 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 119 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 120 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 121 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 122 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 123 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 124 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 125 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 126 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 127 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 128 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 129 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 130 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 131 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 132 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 133 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 134 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 135 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 136 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 137 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 138 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 139 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 140 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 141 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d457521 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.CallTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 145 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | c7ebc0f | 2021-11-15 23:46:41 +0000 | [diff] [blame] | 155 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 157 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 165 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 166 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 170 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 175 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 176 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 177 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 179 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 181 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 183 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 184 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 185 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 187 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 188 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 189 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 191 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 192 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 193 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 194 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 195 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 196 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 197 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 198 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 199 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 200 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 201 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 202 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 203 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 204 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 205 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 206 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 207 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 208 | import com.android.services.telephony.TelecomAccountRegistry; |
| 209 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 210 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 211 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 212 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 213 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 214 | import java.io.IOException; |
| 215 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 216 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 217 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 218 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 219 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 220 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 221 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 222 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 223 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 224 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 225 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 226 | import java.util.Set; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 227 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 228 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 229 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 230 | |
| 231 | /** |
| 232 | * Implementation of the ITelephony interface. |
| 233 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 234 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 235 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 236 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 237 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 238 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 239 | |
| 240 | // Message codes used with mMainThreadHandler |
| 241 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 242 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 243 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 244 | private static final int CMD_OPEN_CHANNEL = 9; |
| 245 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 246 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 247 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 248 | private static final int CMD_NV_READ_ITEM = 13; |
| 249 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 250 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 251 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 252 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 253 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 254 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 255 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 256 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 257 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 258 | private static final int CMD_SEND_ENVELOPE = 25; |
| 259 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 260 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 261 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 262 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 263 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 264 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 265 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 266 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 267 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 268 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 269 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 270 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 271 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 272 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 273 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 274 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 275 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 276 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 277 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 278 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 279 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 280 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 281 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 282 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 283 | private static final int CMD_SWITCH_SLOTS = 50; |
| 284 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 285 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 286 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 287 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 288 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 289 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 290 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 291 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 292 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 293 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 294 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 295 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 296 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 297 | private static final int CMD_MODEM_REBOOT = 64; |
| 298 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 299 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 300 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 301 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 302 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 303 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 304 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 305 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 306 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 307 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 308 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 309 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 310 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 311 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 312 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 313 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 314 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 315 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 316 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 317 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 318 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 319 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 320 | private static final int CMD_GET_CALL_WAITING = 87; |
| 321 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 322 | private static final int CMD_SET_CALL_WAITING = 89; |
| 323 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 324 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 325 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 326 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 327 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 328 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 329 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 330 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 331 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 332 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 333 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 334 | private static final int CMD_SET_SIM_POWER = 101; |
| 335 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 336 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 337 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 338 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 339 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 340 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 341 | 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] | 342 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 343 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 344 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 345 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | bf5c79c | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 346 | private static final int CMD_ENABLE_VONR = 113; |
| 347 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 348 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 349 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 350 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 351 | // Parameters of select command. |
| 352 | private static final int SELECT_COMMAND = 0xA4; |
| 353 | private static final int SELECT_P1 = 0x04; |
| 354 | private static final int SELECT_P2 = 0; |
| 355 | private static final int SELECT_P3 = 0x10; |
| 356 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 357 | /** The singleton instance. */ |
| 358 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 359 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 360 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 361 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 362 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 363 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 364 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 365 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 366 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 367 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 368 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 369 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 370 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 371 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 372 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 373 | /** User Activity */ |
| 374 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 375 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 376 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 377 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 378 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 379 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 380 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 381 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 382 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 383 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 384 | // String to store multi SIM allowed |
| 385 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 386 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 387 | // The AID of ISD-R. |
| 388 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 389 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 390 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 391 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 392 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 393 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 394 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 395 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 396 | 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] | 397 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 398 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 399 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 400 | */ |
| 401 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 402 | "reset_network_erase_modem_config_enabled"; |
| 403 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 404 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds |
| 405 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 406 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 407 | * A request object to use for transmitting data to an ICC. |
| 408 | */ |
| 409 | private static final class IccAPDUArgument { |
| 410 | public int channel, cla, command, p1, p2, p3; |
| 411 | public String data; |
| 412 | |
| 413 | public IccAPDUArgument(int channel, int cla, int command, |
| 414 | int p1, int p2, int p3, String data) { |
| 415 | this.channel = channel; |
| 416 | this.cla = cla; |
| 417 | this.command = command; |
| 418 | this.p1 = p1; |
| 419 | this.p2 = p2; |
| 420 | this.p3 = p3; |
| 421 | this.data = data; |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 426 | * A request object to use for transmitting data to an ICC. |
| 427 | */ |
| 428 | private static final class ManualNetworkSelectionArgument { |
| 429 | public OperatorInfo operatorInfo; |
| 430 | public boolean persistSelection; |
| 431 | |
| 432 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 433 | this.operatorInfo = operatorInfo; |
| 434 | this.persistSelection = persistSelection; |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 439 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 440 | * request after sending. The main thread will notify the request when it is complete. |
| 441 | */ |
| 442 | private static final class MainThreadRequest { |
| 443 | /** The argument to use for the request */ |
| 444 | public Object argument; |
| 445 | /** The result of the request that is run on the main thread */ |
| 446 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 447 | // The subscriber id that this request applies to. Defaults to |
| 448 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 449 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 450 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 451 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 452 | public Phone phone; |
| 453 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 454 | public WorkSource workSource; |
| 455 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 456 | public MainThreadRequest(Object argument) { |
| 457 | this.argument = argument; |
| 458 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 459 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 460 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 461 | this.argument = argument; |
| 462 | if (phone != null) { |
| 463 | this.phone = phone; |
| 464 | } |
| 465 | this.workSource = workSource; |
| 466 | } |
| 467 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 468 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 469 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 470 | if (subId != null) { |
| 471 | this.subId = subId; |
| 472 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 473 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 474 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 477 | private static final class IncomingThirdPartyCallArgs { |
| 478 | public final ComponentName component; |
| 479 | public final String callId; |
| 480 | public final String callerDisplayName; |
| 481 | |
| 482 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 483 | String callerDisplayName) { |
| 484 | this.component = component; |
| 485 | this.callId = callId; |
| 486 | this.callerDisplayName = callerDisplayName; |
| 487 | } |
| 488 | } |
| 489 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 490 | /** |
| 491 | * A handler that processes messages on the main thread in the phone process. Since many |
| 492 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 493 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 494 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 495 | * on, which will be notified when the operation completes and will contain the result of the |
| 496 | * request. |
| 497 | * |
| 498 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 499 | * note that request.result must be set to something non-null for the calling thread to |
| 500 | * unblock. |
| 501 | */ |
| 502 | private final class MainThreadHandler extends Handler { |
| 503 | @Override |
| 504 | public void handleMessage(Message msg) { |
| 505 | MainThreadRequest request; |
| 506 | Message onCompleted; |
| 507 | AsyncResult ar; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 508 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 509 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 510 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 511 | |
| 512 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 513 | case CMD_HANDLE_USSD_REQUEST: { |
| 514 | request = (MainThreadRequest) msg.obj; |
| 515 | final Phone phone = getPhoneFromRequest(request); |
| 516 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 517 | String ussdRequest = ussdObject.first; |
| 518 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 519 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 520 | if (!isUssdApiAllowed(request.subId)) { |
| 521 | // Carrier does not support use of this API, return failure. |
| 522 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 523 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 524 | Bundle returnData = new Bundle(); |
| 525 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 526 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 527 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 528 | request.result = true; |
| 529 | notifyRequester(request); |
| 530 | return; |
| 531 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 532 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 533 | try { |
| 534 | request.result = phone != null |
| 535 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 536 | } catch (CallStateException cse) { |
| 537 | request.result = false; |
| 538 | } |
| 539 | // Wake up the requesting thread |
| 540 | notifyRequester(request); |
| 541 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 544 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 545 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 546 | final Phone phone = getPhoneFromRequest(request); |
| 547 | request.result = phone != null ? |
| 548 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 549 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 550 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 551 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 552 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 553 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 554 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 555 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 556 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 557 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 558 | uiccPort = getUiccPortFromRequest(request); |
| 559 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 560 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 561 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 562 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 563 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 564 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 565 | request); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 566 | uiccPort.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 567 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 568 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 569 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 570 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 571 | break; |
| 572 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 573 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 574 | ar = (AsyncResult) msg.obj; |
| 575 | request = (MainThreadRequest) ar.userObj; |
| 576 | if (ar.exception == null && ar.result != null) { |
| 577 | request.result = ar.result; |
| 578 | } else { |
| 579 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 580 | if (ar.result == null) { |
| 581 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 582 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 583 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 584 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 585 | } else { |
| 586 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 587 | } |
| 588 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 589 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 590 | break; |
| 591 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 592 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 593 | request = (MainThreadRequest) msg.obj; |
| 594 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 595 | uiccPort = getUiccPortFromRequest(request); |
| 596 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 597 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 598 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 599 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 600 | } else { |
| 601 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 602 | request); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 603 | uiccPort.iccTransmitApduBasicChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 604 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 605 | iccArgument.p3, iccArgument.data, onCompleted); |
| 606 | } |
| 607 | break; |
| 608 | |
| 609 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 610 | ar = (AsyncResult) msg.obj; |
| 611 | request = (MainThreadRequest) ar.userObj; |
| 612 | if (ar.exception == null && ar.result != null) { |
| 613 | request.result = ar.result; |
| 614 | } else { |
| 615 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 616 | if (ar.result == null) { |
| 617 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 618 | } else if (ar.exception instanceof CommandException) { |
| 619 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 620 | ar.exception); |
| 621 | } else { |
| 622 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 623 | } |
| 624 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 625 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 626 | break; |
| 627 | |
| 628 | case CMD_EXCHANGE_SIM_IO: |
| 629 | request = (MainThreadRequest) msg.obj; |
| 630 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 631 | uiccPort = getUiccPortFromRequest(request); |
| 632 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 633 | loge("iccExchangeSimIO: No UICC"); |
| 634 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 635 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 636 | } else { |
| 637 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 638 | request); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 639 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 640 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 641 | iccArgument.data, onCompleted); |
| 642 | } |
| 643 | break; |
| 644 | |
| 645 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 646 | ar = (AsyncResult) msg.obj; |
| 647 | request = (MainThreadRequest) ar.userObj; |
| 648 | if (ar.exception == null && ar.result != null) { |
| 649 | request.result = ar.result; |
| 650 | } else { |
| 651 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 652 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 653 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 654 | break; |
| 655 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 656 | case CMD_SEND_ENVELOPE: |
| 657 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 658 | uiccPort = getUiccPortFromRequest(request); |
| 659 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 660 | loge("sendEnvelopeWithStatus: No UICC"); |
| 661 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 662 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 663 | } else { |
| 664 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 665 | uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 666 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 667 | break; |
| 668 | |
| 669 | case EVENT_SEND_ENVELOPE_DONE: |
| 670 | ar = (AsyncResult) msg.obj; |
| 671 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 672 | if (ar.exception == null && ar.result != null) { |
| 673 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 674 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 675 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 676 | if (ar.result == null) { |
| 677 | loge("sendEnvelopeWithStatus: Empty response"); |
| 678 | } else if (ar.exception instanceof CommandException) { |
| 679 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 680 | ar.exception); |
| 681 | } else { |
| 682 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 683 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 684 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 685 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 686 | break; |
| 687 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 688 | case CMD_OPEN_CHANNEL: |
| 689 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 690 | uiccPort = getUiccPortFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 691 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 692 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 693 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 694 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 695 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 696 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 697 | } else { |
| 698 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 699 | uiccPort.iccOpenLogicalChannel(openChannelArgs.first, |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 700 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 701 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 702 | break; |
| 703 | |
| 704 | case EVENT_OPEN_CHANNEL_DONE: |
| 705 | ar = (AsyncResult) msg.obj; |
| 706 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 707 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 708 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 709 | int[] result = (int[]) ar.result; |
| 710 | int channelId = result[0]; |
| 711 | byte[] selectResponse = null; |
| 712 | if (result.length > 1) { |
| 713 | selectResponse = new byte[result.length - 1]; |
| 714 | for (int i = 1; i < result.length; ++i) { |
| 715 | selectResponse[i - 1] = (byte) result[i]; |
| 716 | } |
| 717 | } |
| 718 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 719 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 720 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 721 | if (ar.result == null) { |
| 722 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 723 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 724 | if (ar.exception != null) { |
| 725 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 726 | } |
| 727 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 728 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 729 | if (ar.exception instanceof CommandException) { |
| 730 | CommandException.Error error = |
| 731 | ((CommandException) (ar.exception)).getCommandError(); |
| 732 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 733 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 734 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 735 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 736 | } |
| 737 | } |
| 738 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 739 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 740 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 741 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 742 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 743 | break; |
| 744 | |
| 745 | case CMD_CLOSE_CHANNEL: |
| 746 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 747 | uiccPort = getUiccPortFromRequest(request); |
| 748 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 749 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 750 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 751 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 752 | } else { |
| 753 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 754 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 755 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 756 | break; |
| 757 | |
| 758 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 759 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 760 | break; |
| 761 | |
| 762 | case CMD_NV_READ_ITEM: |
| 763 | request = (MainThreadRequest) msg.obj; |
| 764 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 765 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 766 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 767 | break; |
| 768 | |
| 769 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 770 | ar = (AsyncResult) msg.obj; |
| 771 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 772 | if (ar.exception == null && ar.result != null) { |
| 773 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 774 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 775 | request.result = ""; |
| 776 | if (ar.result == null) { |
| 777 | loge("nvReadItem: Empty response"); |
| 778 | } else if (ar.exception instanceof CommandException) { |
| 779 | loge("nvReadItem: CommandException: " + |
| 780 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 781 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 782 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 783 | } |
| 784 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 785 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 786 | break; |
| 787 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 788 | case CMD_NV_WRITE_ITEM: |
| 789 | request = (MainThreadRequest) msg.obj; |
| 790 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 791 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 792 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 793 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 794 | break; |
| 795 | |
| 796 | case EVENT_NV_WRITE_ITEM_DONE: |
| 797 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 798 | break; |
| 799 | |
| 800 | case CMD_NV_WRITE_CDMA_PRL: |
| 801 | request = (MainThreadRequest) msg.obj; |
| 802 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 803 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 804 | break; |
| 805 | |
| 806 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 807 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 808 | break; |
| 809 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 810 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 811 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 812 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 813 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 814 | break; |
| 815 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 816 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 817 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 818 | break; |
| 819 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 820 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 821 | request = (MainThreadRequest) msg.obj; |
| 822 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 823 | request); |
| 824 | Phone phone = getPhoneFromRequest(request); |
| 825 | if (phone != null) { |
| 826 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 827 | } else { |
| 828 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 829 | request.result = false; |
| 830 | notifyRequester(request); |
| 831 | } |
| 832 | break; |
| 833 | } |
| 834 | |
| 835 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 836 | ar = (AsyncResult) msg.obj; |
| 837 | request = (MainThreadRequest) ar.userObj; |
| 838 | if (ar.exception == null && ar.result != null) { |
| 839 | request.result = ar.result; |
| 840 | } else { |
| 841 | // request.result must be set to something non-null |
| 842 | // for the calling thread to unblock |
Sooraj Sasindran | bf5c79c | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 843 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 844 | request.result = ar.result; |
| 845 | } else { |
| 846 | request.result = false; |
| 847 | } |
| 848 | if (ar.result == null) { |
| 849 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 850 | } else if (ar.exception instanceof CommandException) { |
| 851 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 852 | + ar.exception); |
| 853 | } else { |
| 854 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 855 | } |
| 856 | } |
| 857 | notifyRequester(request); |
| 858 | break; |
| 859 | |
Sooraj Sasindran | bf5c79c | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 860 | case CMD_IS_VONR_ENABLED: { |
| 861 | request = (MainThreadRequest) msg.obj; |
| 862 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 863 | request); |
| 864 | Phone phone = getPhoneFromRequest(request); |
| 865 | if (phone != null) { |
| 866 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 867 | } else { |
| 868 | loge("isVoNrEnabled: No phone object"); |
| 869 | request.result = false; |
| 870 | notifyRequester(request); |
| 871 | } |
| 872 | break; |
| 873 | } |
| 874 | |
| 875 | case EVENT_IS_VONR_ENABLED_DONE: |
| 876 | ar = (AsyncResult) msg.obj; |
| 877 | request = (MainThreadRequest) ar.userObj; |
| 878 | if (ar.exception == null && ar.result != null) { |
| 879 | request.result = ar.result; |
| 880 | } else { |
| 881 | // request.result must be set to something non-null |
| 882 | // for the calling thread to unblock |
| 883 | if (ar.result != null) { |
| 884 | request.result = ar.result; |
| 885 | } else { |
| 886 | request.result = false; |
| 887 | } |
| 888 | if (ar.result == null) { |
| 889 | loge("isVoNrEnabled: Empty response"); |
| 890 | } else if (ar.exception instanceof CommandException) { |
| 891 | loge("isVoNrEnabled: CommandException: " |
| 892 | + ar.exception); |
| 893 | } else { |
| 894 | loge("isVoNrEnabled: Unknown exception"); |
| 895 | } |
| 896 | } |
| 897 | notifyRequester(request); |
| 898 | break; |
| 899 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 900 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 901 | request = (MainThreadRequest) msg.obj; |
| 902 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 903 | Phone phone = getPhoneFromRequest(request); |
| 904 | if (phone != null) { |
| 905 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 906 | request.workSource); |
| 907 | } else { |
| 908 | loge("enableNrDualConnectivity: No phone object"); |
| 909 | request.result = |
| 910 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 911 | notifyRequester(request); |
| 912 | } |
| 913 | break; |
| 914 | } |
| 915 | |
| 916 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 917 | ar = (AsyncResult) msg.obj; |
| 918 | request = (MainThreadRequest) ar.userObj; |
| 919 | if (ar.exception == null) { |
| 920 | request.result = |
| 921 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 922 | } else { |
| 923 | request.result = |
| 924 | TelephonyManager |
| 925 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 926 | if (ar.exception instanceof CommandException) { |
| 927 | CommandException.Error error = |
| 928 | ((CommandException) (ar.exception)).getCommandError(); |
| 929 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 930 | request.result = |
| 931 | TelephonyManager |
| 932 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 933 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 934 | request.result = |
| 935 | TelephonyManager |
| 936 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 937 | } |
| 938 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 939 | + ar.exception); |
| 940 | } else { |
| 941 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 942 | } |
| 943 | } |
| 944 | notifyRequester(request); |
| 945 | break; |
| 946 | } |
| 947 | |
Sooraj Sasindran | bf5c79c | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 948 | case CMD_ENABLE_VONR: { |
| 949 | request = (MainThreadRequest) msg.obj; |
| 950 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 951 | Phone phone = getPhoneFromRequest(request); |
| 952 | if (phone != null) { |
| 953 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 954 | request.workSource); |
| 955 | } else { |
| 956 | loge("setVoNrEnabled: No phone object"); |
| 957 | request.result = |
| 958 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 959 | notifyRequester(request); |
| 960 | } |
| 961 | break; |
| 962 | } |
| 963 | |
| 964 | case EVENT_ENABLE_VONR_DONE: { |
| 965 | ar = (AsyncResult) msg.obj; |
| 966 | request = (MainThreadRequest) ar.userObj; |
| 967 | if (ar.exception == null) { |
| 968 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 969 | } else { |
| 970 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 971 | if (ar.exception instanceof CommandException) { |
| 972 | CommandException.Error error = |
| 973 | ((CommandException) (ar.exception)).getCommandError(); |
| 974 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 975 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 976 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 977 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 978 | } else { |
| 979 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 980 | } |
| 981 | loge("setVoNrEnabled" + ": CommandException: " |
| 982 | + ar.exception); |
| 983 | } else { |
| 984 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 985 | } |
| 986 | } |
| 987 | notifyRequester(request); |
| 988 | break; |
| 989 | } |
| 990 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 991 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 992 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 993 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 994 | request); |
| 995 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 996 | break; |
| 997 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 998 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 999 | ar = (AsyncResult) msg.obj; |
| 1000 | request = (MainThreadRequest) ar.userObj; |
| 1001 | if (ar.exception == null && ar.result != null) { |
| 1002 | request.result = ar.result; // Integer |
| 1003 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1004 | // request.result must be set to something non-null |
| 1005 | // for the calling thread to unblock |
| 1006 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1007 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1008 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1009 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1010 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1011 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1012 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1013 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1014 | } |
| 1015 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1016 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1017 | break; |
| 1018 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1019 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1020 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1021 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1022 | request); |
| 1023 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1024 | (Pair<Integer, Long>) request.argument; |
| 1025 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1026 | reasonWithNetworkTypes.first, |
| 1027 | reasonWithNetworkTypes.second, |
| 1028 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1029 | break; |
| 1030 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1031 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1032 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1033 | break; |
| 1034 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1035 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1036 | request = (MainThreadRequest)msg.obj; |
| 1037 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1038 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1039 | break; |
| 1040 | |
| 1041 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1042 | ar = (AsyncResult)msg.obj; |
| 1043 | request = (MainThreadRequest)ar.userObj; |
| 1044 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1045 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1046 | break; |
| 1047 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1048 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1049 | request = (MainThreadRequest) msg.obj; |
| 1050 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1051 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1052 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1053 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1054 | break; |
| 1055 | |
| 1056 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1057 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1058 | break; |
| 1059 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1060 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1061 | request = (MainThreadRequest) msg.obj; |
| 1062 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1063 | request); |
| 1064 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1065 | break; |
| 1066 | |
| 1067 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1068 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1069 | break; |
| 1070 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1071 | case CMD_PERFORM_NETWORK_SCAN: |
| 1072 | request = (MainThreadRequest) msg.obj; |
| 1073 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1074 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1075 | break; |
| 1076 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1077 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1078 | request = (MainThreadRequest) msg.obj; |
| 1079 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1080 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1081 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1082 | request.argument; |
| 1083 | int callForwardingReason = args.first; |
| 1084 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1085 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1086 | } |
| 1087 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1088 | ar = (AsyncResult) msg.obj; |
| 1089 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1090 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1091 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1092 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1093 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1094 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1095 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1096 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1097 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1098 | // any service for voice call. |
| 1099 | if ((callForwardInfo.serviceClass |
| 1100 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1101 | callForwardingInfo = new CallForwardingInfo( |
| 1102 | callForwardInfo.status |
| 1103 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1104 | callForwardInfo.reason, |
| 1105 | callForwardInfo.number, |
| 1106 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1107 | break; |
| 1108 | } |
| 1109 | } |
| 1110 | // Didn't find a call forward info for voice call. |
| 1111 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1112 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1113 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1114 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1115 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1116 | } else { |
| 1117 | if (ar.result == null) { |
| 1118 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1119 | } |
| 1120 | if (ar.exception != null) { |
| 1121 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1122 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1123 | int errorCode = TelephonyManager |
| 1124 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1125 | if (ar.exception instanceof CommandException) { |
| 1126 | CommandException.Error error = |
| 1127 | ((CommandException) (ar.exception)).getCommandError(); |
| 1128 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1129 | errorCode = TelephonyManager |
| 1130 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1131 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1132 | errorCode = TelephonyManager |
| 1133 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1134 | } |
| 1135 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1136 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1137 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1138 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1139 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1140 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1141 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1142 | request = (MainThreadRequest) msg.obj; |
| 1143 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1144 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1145 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1146 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1147 | request.argument).first; |
| 1148 | request.phone.setCallForwardingOption( |
| 1149 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1150 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1151 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1152 | callForwardingInfoToSet.getReason(), |
| 1153 | callForwardingInfoToSet.getNumber(), |
| 1154 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1155 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1156 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1157 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1158 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1159 | ar = (AsyncResult) msg.obj; |
| 1160 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1161 | Consumer<Integer> callback = |
| 1162 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1163 | request.argument).second; |
| 1164 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1165 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1166 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1167 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1168 | if (ar.exception instanceof CommandException) { |
| 1169 | CommandException.Error error = |
| 1170 | ((CommandException) (ar.exception)).getCommandError(); |
| 1171 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1172 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1173 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1174 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1175 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1176 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1177 | } |
| 1178 | } |
| 1179 | callback.accept(errorCode); |
| 1180 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1181 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1182 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1183 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1184 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1185 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1186 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1187 | request = (MainThreadRequest) msg.obj; |
| 1188 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1189 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1190 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1191 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1192 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1193 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1194 | ar = (AsyncResult) msg.obj; |
| 1195 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1196 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1197 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1198 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1199 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1200 | // Service Class is a bit mask per 3gpp 27.007. |
| 1201 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1202 | if (callForwardResults.length > 1 |
| 1203 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1204 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1205 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1206 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1207 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1208 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1209 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1210 | } |
| 1211 | } else { |
| 1212 | if (ar.result == null) { |
| 1213 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1214 | } |
| 1215 | if (ar.exception != null) { |
| 1216 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1217 | } |
| 1218 | if (ar.exception instanceof CommandException) { |
| 1219 | CommandException.Error error = |
| 1220 | ((CommandException) (ar.exception)).getCommandError(); |
| 1221 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1222 | callForwardingStatus = |
| 1223 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1224 | } |
| 1225 | } |
| 1226 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1227 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1228 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1229 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1230 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1231 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1232 | request = (MainThreadRequest) msg.obj; |
| 1233 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1234 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1235 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1236 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1237 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1238 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1239 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1240 | ar = (AsyncResult) msg.obj; |
| 1241 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1242 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1243 | Consumer<Integer> callback = |
| 1244 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1245 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1246 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1247 | if (ar.exception instanceof CommandException) { |
| 1248 | CommandException.Error error = |
| 1249 | ((CommandException) (ar.exception)).getCommandError(); |
| 1250 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1251 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1252 | } else { |
| 1253 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1254 | } |
| 1255 | } else { |
| 1256 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1257 | } |
| 1258 | } else { |
| 1259 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1260 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1261 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1262 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1263 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1264 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1265 | ar = (AsyncResult) msg.obj; |
| 1266 | request = (MainThreadRequest) ar.userObj; |
| 1267 | CellNetworkScanResult cellScanResult; |
| 1268 | if (ar.exception == null && ar.result != null) { |
| 1269 | cellScanResult = new CellNetworkScanResult( |
| 1270 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1271 | (List<OperatorInfo>) ar.result); |
| 1272 | } else { |
| 1273 | if (ar.result == null) { |
| 1274 | loge("getCellNetworkScanResults: Empty response"); |
| 1275 | } |
| 1276 | if (ar.exception != null) { |
| 1277 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1278 | } |
| 1279 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1280 | if (ar.exception instanceof CommandException) { |
| 1281 | CommandException.Error error = |
| 1282 | ((CommandException) (ar.exception)).getCommandError(); |
| 1283 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1284 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1285 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1286 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1287 | } |
| 1288 | } |
| 1289 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1290 | } |
| 1291 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1292 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1293 | break; |
| 1294 | |
| 1295 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1296 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1297 | ManualNetworkSelectionArgument selArg = |
| 1298 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1299 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1300 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1301 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1302 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1303 | break; |
| 1304 | |
| 1305 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1306 | ar = (AsyncResult) msg.obj; |
| 1307 | request = (MainThreadRequest) ar.userObj; |
| 1308 | if (ar.exception == null) { |
| 1309 | request.result = true; |
| 1310 | } else { |
| 1311 | request.result = false; |
| 1312 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1313 | } |
| 1314 | notifyRequester(request); |
| 1315 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1316 | break; |
| 1317 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1318 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1319 | request = (MainThreadRequest) msg.obj; |
| 1320 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1321 | if (defaultPhone != null) { |
| 1322 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1323 | } else { |
| 1324 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1325 | Bundle bundle = new Bundle(); |
| 1326 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1327 | new ModemActivityInfo(0, 0, 0, |
| 1328 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1329 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1330 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1331 | break; |
| 1332 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1333 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1334 | ar = (AsyncResult) msg.obj; |
| 1335 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1336 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1337 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1338 | ModemActivityInfo ret = null; |
| 1339 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1340 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1341 | // Update the last modem activity info and the result of the request. |
| 1342 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1343 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1344 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1345 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1346 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1347 | .getTransmitTimeMillis(); |
| 1348 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1349 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1350 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1351 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1352 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1353 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1354 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1355 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1356 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1357 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1358 | info.getReceiveTimeMillis() |
| 1359 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1360 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1361 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1362 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1363 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1364 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1365 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1366 | } else { |
| 1367 | if (ar.result == null) { |
| 1368 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1369 | error = TelephonyManager.ModemActivityInfoException |
| 1370 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1371 | } else if (ar.exception instanceof CommandException) { |
| 1372 | loge("queryModemActivityInfo: CommandException: " + |
| 1373 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1374 | error = TelephonyManager.ModemActivityInfoException |
| 1375 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1376 | } else { |
| 1377 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1378 | error = TelephonyManager.ModemActivityInfoException |
| 1379 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1380 | } |
| 1381 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1382 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1383 | if (ret != null) { |
| 1384 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1385 | } else { |
| 1386 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1387 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1388 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1389 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1390 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1391 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1392 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1393 | case CMD_SET_ALLOWED_CARRIERS: |
| 1394 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1395 | CarrierRestrictionRules argument = |
| 1396 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1397 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1398 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1399 | break; |
| 1400 | |
| 1401 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1402 | ar = (AsyncResult) msg.obj; |
| 1403 | request = (MainThreadRequest) ar.userObj; |
| 1404 | if (ar.exception == null && ar.result != null) { |
| 1405 | request.result = ar.result; |
| 1406 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1407 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1408 | if (ar.exception instanceof CommandException) { |
| 1409 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1410 | CommandException.Error error = |
| 1411 | ((CommandException) (ar.exception)).getCommandError(); |
| 1412 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1413 | request.result = |
| 1414 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1415 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1416 | } else { |
| 1417 | loge("setAllowedCarriers: Unknown exception"); |
| 1418 | } |
| 1419 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1420 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1421 | break; |
| 1422 | |
| 1423 | case CMD_GET_ALLOWED_CARRIERS: |
| 1424 | request = (MainThreadRequest) msg.obj; |
| 1425 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1426 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1427 | break; |
| 1428 | |
| 1429 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1430 | ar = (AsyncResult) msg.obj; |
| 1431 | request = (MainThreadRequest) ar.userObj; |
| 1432 | if (ar.exception == null && ar.result != null) { |
| 1433 | request.result = ar.result; |
| 1434 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1435 | request.result = new IllegalStateException( |
| 1436 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1437 | if (ar.result == null) { |
| 1438 | loge("getAllowedCarriers: Empty response"); |
| 1439 | } else if (ar.exception instanceof CommandException) { |
| 1440 | loge("getAllowedCarriers: CommandException: " + |
| 1441 | ar.exception); |
| 1442 | } else { |
| 1443 | loge("getAllowedCarriers: Unknown exception"); |
| 1444 | } |
| 1445 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1446 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1447 | break; |
| 1448 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1449 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1450 | ar = (AsyncResult) msg.obj; |
| 1451 | request = (MainThreadRequest) ar.userObj; |
| 1452 | if (ar.exception == null && ar.result != null) { |
| 1453 | request.result = ar.result; |
| 1454 | } else { |
| 1455 | request.result = new IllegalArgumentException( |
| 1456 | "Failed to retrieve Forbidden Plmns"); |
| 1457 | if (ar.result == null) { |
| 1458 | loge("getForbiddenPlmns: Empty response"); |
| 1459 | } else { |
| 1460 | loge("getForbiddenPlmns: Unknown exception"); |
| 1461 | } |
| 1462 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1463 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1464 | break; |
| 1465 | |
| 1466 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1467 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1468 | uiccPort = getUiccPortFromRequest(request); |
| 1469 | if (uiccPort == null) { |
| 1470 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1471 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1472 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1473 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1474 | break; |
| 1475 | } |
| 1476 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1477 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1478 | if (uiccApp == null) { |
| 1479 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1480 | + appType); |
| 1481 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1482 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1483 | break; |
| 1484 | } else { |
| 1485 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1486 | + " specified type -- " + appType); |
| 1487 | } |
| 1488 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1489 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1490 | onCompleted); |
| 1491 | break; |
| 1492 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1493 | case CMD_SWITCH_SLOTS: |
| 1494 | request = (MainThreadRequest) msg.obj; |
| 1495 | int[] physicalSlots = (int[]) request.argument; |
| 1496 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1497 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1498 | break; |
| 1499 | |
| 1500 | case EVENT_SWITCH_SLOTS_DONE: |
| 1501 | ar = (AsyncResult) msg.obj; |
| 1502 | request = (MainThreadRequest) ar.userObj; |
| 1503 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1504 | notifyRequester(request); |
| 1505 | break; |
| 1506 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1507 | request = (MainThreadRequest) msg.obj; |
| 1508 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1509 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1510 | break; |
| 1511 | |
| 1512 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1513 | ar = (AsyncResult) msg.obj; |
| 1514 | request = (MainThreadRequest) ar.userObj; |
| 1515 | if (ar.exception != null) { |
| 1516 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1517 | } else { |
| 1518 | int mode = ((int[]) ar.result)[0]; |
| 1519 | if (mode == 0) { |
| 1520 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1521 | } else { |
| 1522 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1523 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1524 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1525 | notifyRequester(request); |
| 1526 | break; |
| 1527 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1528 | request = (MainThreadRequest) msg.obj; |
| 1529 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1530 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1531 | break; |
| 1532 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1533 | ar = (AsyncResult) msg.obj; |
| 1534 | request = (MainThreadRequest) ar.userObj; |
| 1535 | if (ar.exception != null) { |
| 1536 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1537 | } else { |
| 1538 | request.result = ((int[]) ar.result)[0]; |
| 1539 | } |
| 1540 | notifyRequester(request); |
| 1541 | break; |
| 1542 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1543 | request = (MainThreadRequest) msg.obj; |
| 1544 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1545 | int mode = (int) request.argument; |
| 1546 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1547 | break; |
| 1548 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1549 | ar = (AsyncResult) msg.obj; |
| 1550 | request = (MainThreadRequest) ar.userObj; |
| 1551 | request.result = ar.exception == null; |
| 1552 | notifyRequester(request); |
| 1553 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1554 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1555 | request = (MainThreadRequest) msg.obj; |
| 1556 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1557 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1558 | break; |
| 1559 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1560 | ar = (AsyncResult) msg.obj; |
| 1561 | request = (MainThreadRequest) ar.userObj; |
| 1562 | if (ar.exception != null) { |
| 1563 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1564 | } else { |
| 1565 | request.result = ((int[]) ar.result)[0]; |
| 1566 | } |
| 1567 | notifyRequester(request); |
| 1568 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1569 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1570 | request = (MainThreadRequest) msg.obj; |
| 1571 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1572 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1573 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1574 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1575 | break; |
| 1576 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1577 | ar = (AsyncResult) msg.obj; |
| 1578 | request = (MainThreadRequest) ar.userObj; |
| 1579 | request.result = ar.exception == null; |
| 1580 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1581 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1582 | case CMD_GET_ALL_CELL_INFO: |
| 1583 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1584 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1585 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1586 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1587 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1588 | ar = (AsyncResult) msg.obj; |
| 1589 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1590 | // If a timeout occurs, the response will be null |
| 1591 | request.result = (ar.exception == null && ar.result != null) |
| 1592 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1593 | synchronized (request) { |
| 1594 | request.notifyAll(); |
| 1595 | } |
| 1596 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1597 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1598 | request = (MainThreadRequest) msg.obj; |
| 1599 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1600 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1601 | break; |
| 1602 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1603 | ar = (AsyncResult) msg.obj; |
| 1604 | request = (MainThreadRequest) ar.userObj; |
| 1605 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1606 | try { |
| 1607 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1608 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1609 | cb.onError( |
| 1610 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1611 | ar.exception.getClass().getName(), |
| 1612 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1613 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1614 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1615 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1616 | } else { |
| 1617 | // use the result as returned |
| 1618 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1619 | } |
| 1620 | } catch (RemoteException re) { |
| 1621 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1622 | } |
| 1623 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1624 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1625 | request = (MainThreadRequest) msg.obj; |
| 1626 | WorkSource ws = (WorkSource) request.argument; |
| 1627 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1628 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1629 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1630 | } |
| 1631 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1632 | ar = (AsyncResult) msg.obj; |
| 1633 | request = (MainThreadRequest) ar.userObj; |
| 1634 | if (ar.exception == null) { |
| 1635 | request.result = ar.result; |
| 1636 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1637 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1638 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1639 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1640 | } |
| 1641 | |
| 1642 | synchronized (request) { |
| 1643 | request.notifyAll(); |
| 1644 | } |
| 1645 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1646 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1647 | case CMD_MODEM_REBOOT: |
| 1648 | request = (MainThreadRequest) msg.obj; |
| 1649 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1650 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1651 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1652 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1653 | handleNullReturnEvent(msg, "rebootModem"); |
| 1654 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1655 | case CMD_REQUEST_ENABLE_MODEM: |
| 1656 | request = (MainThreadRequest) msg.obj; |
| 1657 | boolean enable = (boolean) request.argument; |
| 1658 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1659 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1660 | PhoneConfigurationManager.getInstance() |
| 1661 | .enablePhone(request.phone, enable, onCompleted); |
| 1662 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1663 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1664 | ar = (AsyncResult) msg.obj; |
| 1665 | request = (MainThreadRequest) ar.userObj; |
| 1666 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1667 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1668 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1669 | if ((boolean) request.result) { |
| 1670 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1671 | updateModemStateMetrics(); |
| 1672 | } else { |
| 1673 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1674 | + ar.exception); |
| 1675 | } |
| 1676 | notifyRequester(request); |
| 1677 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1678 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1679 | case CMD_GET_MODEM_STATUS: |
| 1680 | request = (MainThreadRequest) msg.obj; |
| 1681 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1682 | PhoneConfigurationManager.getInstance() |
| 1683 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1684 | break; |
| 1685 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1686 | ar = (AsyncResult) msg.obj; |
| 1687 | request = (MainThreadRequest) ar.userObj; |
| 1688 | int id = request.phone.getPhoneId(); |
| 1689 | if (ar.exception == null && ar.result != null) { |
| 1690 | request.result = ar.result; |
| 1691 | //update the cache as modem status has changed |
| 1692 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1693 | (boolean) request.result); |
| 1694 | } else { |
| 1695 | // Return true if modem status cannot be retrieved. For most cases, |
| 1696 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1697 | // and disable modem are not supported. Modem is always on. |
| 1698 | // TODO: this should be fixed in R to support a third |
| 1699 | // status UNKNOWN b/131631629 |
| 1700 | request.result = true; |
| 1701 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1702 | + ar.exception); |
| 1703 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1704 | notifyRequester(request); |
| 1705 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1706 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1707 | request = (MainThreadRequest) msg.obj; |
| 1708 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1709 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1710 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1711 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1712 | break; |
| 1713 | } |
| 1714 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1715 | ar = (AsyncResult) msg.obj; |
| 1716 | request = (MainThreadRequest) ar.userObj; |
| 1717 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1718 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1719 | args.second.accept(ar.exception == null); |
| 1720 | notifyRequester(request); |
| 1721 | break; |
| 1722 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1723 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1724 | request = (MainThreadRequest) msg.obj; |
| 1725 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1726 | Phone phone = getPhoneFromRequest(request); |
| 1727 | if (phone != null) { |
| 1728 | phone.getSystemSelectionChannels(onCompleted); |
| 1729 | } else { |
| 1730 | loge("getSystemSelectionChannels: No phone object"); |
| 1731 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1732 | notifyRequester(request); |
| 1733 | } |
| 1734 | break; |
| 1735 | } |
| 1736 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1737 | ar = (AsyncResult) msg.obj; |
| 1738 | request = (MainThreadRequest) ar.userObj; |
| 1739 | if (ar.exception == null && ar.result != null) { |
| 1740 | request.result = ar.result; |
| 1741 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1742 | request.result = new IllegalStateException( |
| 1743 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1744 | if (ar.result == null) { |
| 1745 | loge("getSystemSelectionChannels: Empty response"); |
| 1746 | } else { |
| 1747 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1748 | } |
| 1749 | } |
| 1750 | notifyRequester(request); |
| 1751 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1752 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1753 | ar = (AsyncResult) msg.obj; |
| 1754 | request = (MainThreadRequest) ar.userObj; |
| 1755 | if (ar.exception == null && ar.result != null) { |
| 1756 | request.result = ar.result; |
| 1757 | } else { |
| 1758 | request.result = -1; |
| 1759 | loge("Failed to set Forbidden Plmns"); |
| 1760 | if (ar.result == null) { |
| 1761 | loge("setForbidenPlmns: Empty response"); |
| 1762 | } else if (ar.exception != null) { |
| 1763 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1764 | request.result = -1; |
| 1765 | } else { |
| 1766 | loge("setForbiddenPlmns: Unknown exception"); |
| 1767 | } |
| 1768 | } |
| 1769 | notifyRequester(request); |
| 1770 | break; |
| 1771 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1772 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1773 | uiccPort = getUiccPortFromRequest(request); |
| 1774 | if (uiccPort == null) { |
| 1775 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1776 | request.result = -1; |
| 1777 | notifyRequester(request); |
| 1778 | break; |
| 1779 | } |
| 1780 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1781 | (Pair<Integer, List<String>>) request.argument; |
| 1782 | appType = setFplmnsArgs.first; |
| 1783 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1784 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1785 | if (uiccApp == null) { |
| 1786 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1787 | request.result = -1; |
| 1788 | loge("Failed to get UICC App"); |
| 1789 | notifyRequester(request); |
| 1790 | } else { |
| 1791 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1792 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1793 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1794 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1795 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1796 | case CMD_ERASE_MODEM_CONFIG: |
| 1797 | request = (MainThreadRequest) msg.obj; |
| 1798 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1799 | defaultPhone.eraseModemConfig(onCompleted); |
| 1800 | break; |
| 1801 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1802 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1803 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1804 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1805 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1806 | request = (MainThreadRequest) msg.obj; |
| 1807 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1808 | notifyRequester(request); |
| 1809 | break; |
| 1810 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1811 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1812 | request = (MainThreadRequest) msg.obj; |
| 1813 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1814 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1815 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1816 | changed.first, changed.second, onCompleted); |
| 1817 | break; |
| 1818 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1819 | ar = (AsyncResult) msg.obj; |
| 1820 | request = (MainThreadRequest) ar.userObj; |
| 1821 | if (ar.exception == null) { |
| 1822 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1823 | // If the operation is successful, update the PIN storage |
| 1824 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1825 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | bb77752 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1826 | UiccController.getInstance().getPinStorage() |
| 1827 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1828 | } else { |
| 1829 | request.result = msg.arg1; |
| 1830 | } |
| 1831 | notifyRequester(request); |
| 1832 | break; |
| 1833 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1834 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1835 | request = (MainThreadRequest) msg.obj; |
| 1836 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1837 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1838 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1839 | enabled.first, enabled.second, onCompleted); |
| 1840 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1841 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1842 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1843 | ar = (AsyncResult) msg.obj; |
| 1844 | request = (MainThreadRequest) ar.userObj; |
| 1845 | if (ar.exception == null) { |
| 1846 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1847 | // If the operation is successful, update the PIN storage |
| 1848 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1849 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1850 | if (enabled.first) { |
Jon Spivack | bb77752 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1851 | UiccController.getInstance().getPinStorage() |
| 1852 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1853 | } else { |
| 1854 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1855 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1856 | } else { |
| 1857 | request.result = msg.arg1; |
| 1858 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1859 | |
| 1860 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1861 | notifyRequester(request); |
| 1862 | break; |
| 1863 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1864 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1865 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1866 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1867 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1868 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1869 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1870 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1871 | |
| 1872 | case CMD_SET_DATA_THROTTLING: { |
| 1873 | request = (MainThreadRequest) msg.obj; |
| 1874 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1875 | DataThrottlingRequest dataThrottlingRequest = |
| 1876 | (DataThrottlingRequest) request.argument; |
| 1877 | Phone phone = getPhoneFromRequest(request); |
| 1878 | if (phone != null) { |
| 1879 | phone.setDataThrottling(onCompleted, |
| 1880 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1881 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1882 | } else { |
| 1883 | loge("setDataThrottling: No phone object"); |
| 1884 | request.result = |
| 1885 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1886 | notifyRequester(request); |
| 1887 | } |
| 1888 | |
| 1889 | break; |
| 1890 | } |
| 1891 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1892 | ar = (AsyncResult) msg.obj; |
| 1893 | request = (MainThreadRequest) ar.userObj; |
| 1894 | |
| 1895 | if (ar.exception == null) { |
| 1896 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1897 | } else if (ar.exception instanceof CommandException) { |
| 1898 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1899 | CommandException.Error error = |
| 1900 | ((CommandException) (ar.exception)).getCommandError(); |
| 1901 | |
| 1902 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1903 | request.result = TelephonyManager |
| 1904 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1905 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1906 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 1907 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1908 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1909 | } else { |
| 1910 | request.result = |
| 1911 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1912 | } |
| 1913 | } else { |
| 1914 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1915 | } |
| 1916 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1917 | notifyRequester(request); |
| 1918 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1919 | |
| 1920 | case CMD_SET_SIM_POWER: { |
| 1921 | request = (MainThreadRequest) msg.obj; |
| 1922 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1923 | request = (MainThreadRequest) msg.obj; |
| 1924 | int stateToSet = |
| 1925 | ((Pair<Integer, IIntegerConsumer>) |
| 1926 | request.argument).first; |
| 1927 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1928 | break; |
| 1929 | } |
| 1930 | case EVENT_SET_SIM_POWER_DONE: { |
| 1931 | ar = (AsyncResult) msg.obj; |
| 1932 | request = (MainThreadRequest) ar.userObj; |
| 1933 | IIntegerConsumer callback = |
| 1934 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1935 | if (ar.exception != null) { |
| 1936 | loge("setSimPower exception: " + ar.exception); |
| 1937 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1938 | .RESULT_ERROR_UNKNOWN; |
| 1939 | if (ar.exception instanceof CommandException) { |
| 1940 | CommandException.Error error = |
| 1941 | ((CommandException) (ar.exception)).getCommandError(); |
| 1942 | if (error == CommandException.Error.SIM_ERR) { |
| 1943 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1944 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1945 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1946 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1947 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1948 | } else { |
| 1949 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1950 | } |
| 1951 | } |
| 1952 | try { |
| 1953 | callback.accept(errorCode); |
| 1954 | } catch (RemoteException e) { |
| 1955 | // Ignore if the remote process is no longer available to call back. |
| 1956 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1957 | } |
| 1958 | } else { |
| 1959 | try { |
| 1960 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1961 | } catch (RemoteException e) { |
| 1962 | // Ignore if the remote process is no longer available to call back. |
| 1963 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1964 | } |
| 1965 | } |
| 1966 | break; |
| 1967 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1968 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1969 | request = (MainThreadRequest) msg.obj; |
| 1970 | |
| 1971 | final Phone phone = getPhoneFromRequest(request); |
| 1972 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1973 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1974 | notifyRequester(request); |
| 1975 | break; |
| 1976 | } |
| 1977 | |
| 1978 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1979 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1980 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1981 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 1982 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1983 | request.subId, pair.first /*callingUid*/, |
| 1984 | pair.second /*request*/, onCompleted); |
| 1985 | break; |
| 1986 | } |
| 1987 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1988 | ar = (AsyncResult) msg.obj; |
| 1989 | request = (MainThreadRequest) ar.userObj; |
| 1990 | // request.result will be the exception of ar if present, true otherwise. |
| 1991 | // Be cautious not to leave result null which will wait() forever |
| 1992 | request.result = ar.exception != null ? ar.exception : true; |
| 1993 | notifyRequester(request); |
| 1994 | break; |
| 1995 | } |
| 1996 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1997 | request = (MainThreadRequest) msg.obj; |
| 1998 | |
| 1999 | Phone phone = getPhoneFromRequest(request); |
| 2000 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2001 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2002 | notifyRequester(request); |
| 2003 | break; |
| 2004 | } |
| 2005 | |
| 2006 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2007 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2008 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2009 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2010 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2011 | request.subId, pair.first /*callingUid*/, |
| 2012 | pair.second /*request*/, onCompleted); |
| 2013 | break; |
| 2014 | } |
| 2015 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2016 | ar = (AsyncResult) msg.obj; |
| 2017 | request = (MainThreadRequest) ar.userObj; |
| 2018 | request.result = ar.exception != null ? ar.exception : true; |
| 2019 | notifyRequester(request); |
| 2020 | break; |
| 2021 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2022 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2023 | case CMD_GET_SLICING_CONFIG: { |
| 2024 | request = (MainThreadRequest) msg.obj; |
| 2025 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2026 | request.phone.getSlicingConfig(onCompleted); |
| 2027 | break; |
| 2028 | } |
| 2029 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2030 | ar = (AsyncResult) msg.obj; |
| 2031 | request = (MainThreadRequest) ar.userObj; |
| 2032 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2033 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2034 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2035 | Bundle bundle = new Bundle(); |
| 2036 | int resultCode = 0; |
| 2037 | if (ar.exception != null) { |
| 2038 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2039 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2040 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2041 | } else if (ar.result == null) { |
| 2042 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2043 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2044 | } else { |
| 2045 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2046 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2047 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2048 | } |
| 2049 | |
| 2050 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2051 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2052 | } |
| 2053 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2054 | result.send(resultCode, bundle); |
| 2055 | notifyRequester(request); |
| 2056 | break; |
| 2057 | } |
| 2058 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2059 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2060 | request = (MainThreadRequest) msg.obj; |
| 2061 | request.result = |
| 2062 | UiccController.getInstance().getPinStorage().prepareUnattendedReboot(); |
| 2063 | notifyRequester(request); |
| 2064 | break; |
| 2065 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2066 | default: |
| 2067 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2068 | break; |
| 2069 | } |
| 2070 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2071 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2072 | private void notifyRequester(MainThreadRequest request) { |
| 2073 | synchronized (request) { |
| 2074 | request.notifyAll(); |
| 2075 | } |
| 2076 | } |
| 2077 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2078 | private void handleNullReturnEvent(Message msg, String command) { |
| 2079 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2080 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2081 | if (ar.exception == null) { |
| 2082 | request.result = true; |
| 2083 | } else { |
| 2084 | request.result = false; |
| 2085 | if (ar.exception instanceof CommandException) { |
| 2086 | loge(command + ": CommandException: " + ar.exception); |
| 2087 | } else { |
| 2088 | loge(command + ": Unknown exception"); |
| 2089 | } |
| 2090 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2091 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2092 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2093 | } |
| 2094 | |
| 2095 | /** |
| 2096 | * Posts the specified command to be executed on the main thread, |
| 2097 | * waits for the request to complete, and returns the result. |
| 2098 | * @see #sendRequestAsync |
| 2099 | */ |
| 2100 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2101 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2102 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2103 | } |
| 2104 | |
| 2105 | /** |
| 2106 | * Posts the specified command to be executed on the main thread, |
| 2107 | * waits for the request to complete, and returns the result. |
| 2108 | * @see #sendRequestAsync |
| 2109 | */ |
| 2110 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2111 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2112 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2113 | } |
| 2114 | |
| 2115 | /** |
| 2116 | * Posts the specified command to be executed on the main thread, |
| 2117 | * waits for the request to complete, and returns the result. |
| 2118 | * @see #sendRequestAsync |
| 2119 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2120 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2121 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2122 | } |
| 2123 | |
| 2124 | /** |
| 2125 | * Posts the specified command to be executed on the main thread, |
| 2126 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2127 | * if not timeout or null otherwise. |
| 2128 | * @see #sendRequestAsync |
| 2129 | */ |
| 2130 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2131 | long timeoutInMs) { |
| 2132 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2133 | } |
| 2134 | |
| 2135 | /** |
| 2136 | * Posts the specified command to be executed on the main thread, |
| 2137 | * waits for the request to complete, and returns the result. |
| 2138 | * @see #sendRequestAsync |
| 2139 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2140 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2141 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2142 | } |
| 2143 | |
| 2144 | /** |
| 2145 | * Posts the specified command to be executed on the main thread, |
| 2146 | * waits for the request to complete, and returns the result. |
| 2147 | * @see #sendRequestAsync |
| 2148 | */ |
| 2149 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2150 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2151 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2152 | } |
| 2153 | |
| 2154 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2155 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2156 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2157 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2158 | * @see #sendRequestAsync |
| 2159 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2160 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2161 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2162 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2163 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2164 | } |
| 2165 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2166 | MainThreadRequest request = null; |
| 2167 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2168 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2169 | } else if (phone != null) { |
| 2170 | request = new MainThreadRequest(argument, phone, workSource); |
| 2171 | } else { |
| 2172 | request = new MainThreadRequest(argument, subId, workSource); |
| 2173 | } |
| 2174 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2175 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2176 | msg.sendToTarget(); |
| 2177 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2178 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2179 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2180 | if (timeoutInMs >= 0) { |
| 2181 | // Wait for at least timeoutInMs before returning null request result |
| 2182 | long now = SystemClock.elapsedRealtime(); |
| 2183 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2184 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2185 | try { |
| 2186 | request.wait(deadline - now); |
| 2187 | } catch (InterruptedException e) { |
| 2188 | // Do nothing, go back and check if request is completed or timeout |
| 2189 | } finally { |
| 2190 | now = SystemClock.elapsedRealtime(); |
| 2191 | } |
| 2192 | } |
| 2193 | } else { |
| 2194 | // Wait for the request to complete |
| 2195 | while (request.result == null) { |
| 2196 | try { |
| 2197 | request.wait(); |
| 2198 | } catch (InterruptedException e) { |
| 2199 | // Do nothing, go back and wait until the request is complete |
| 2200 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2201 | } |
| 2202 | } |
| 2203 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2204 | if (request.result == null) { |
| 2205 | Log.wtf(LOG_TAG, |
| 2206 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2207 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2208 | return request.result; |
| 2209 | } |
| 2210 | |
| 2211 | /** |
| 2212 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2213 | * Posts the specified command to be executed on the main thread, and |
| 2214 | * returns immediately. |
| 2215 | * @see #sendRequest |
| 2216 | */ |
| 2217 | private void sendRequestAsync(int command) { |
| 2218 | mMainThreadHandler.sendEmptyMessage(command); |
| 2219 | } |
| 2220 | |
| 2221 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2222 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2223 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2224 | */ |
| 2225 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2226 | sendRequestAsync(command, argument, null, null); |
| 2227 | } |
| 2228 | |
| 2229 | /** |
| 2230 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2231 | * @see {@link #sendRequest(int,Object)} |
| 2232 | */ |
| 2233 | private void sendRequestAsync( |
| 2234 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2235 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2236 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2237 | msg.sendToTarget(); |
| 2238 | } |
| 2239 | |
| 2240 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2241 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2242 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2243 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2244 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2245 | synchronized (PhoneInterfaceManager.class) { |
| 2246 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2247 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2248 | } else { |
| 2249 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2250 | } |
| 2251 | return sInstance; |
| 2252 | } |
| 2253 | } |
| 2254 | |
| 2255 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2256 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2257 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2258 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2259 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2260 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2261 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2262 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2263 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2264 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2265 | mTelephonySharedPreferences = |
| 2266 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2267 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2268 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2269 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2270 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2271 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2272 | publish(); |
| 2273 | } |
| 2274 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2275 | private Phone getDefaultPhone() { |
| 2276 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2277 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2278 | } |
| 2279 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2280 | private void publish() { |
| 2281 | if (DBG) log("publish: " + this); |
| 2282 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2283 | TelephonyFrameworkInitializer |
| 2284 | .getTelephonyServiceManager() |
| 2285 | .getTelephonyServiceRegisterer() |
| 2286 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2287 | } |
| 2288 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2289 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2290 | if (request.phone != null) { |
| 2291 | return request.phone; |
| 2292 | } else { |
| 2293 | return getPhoneFromSubId(request.subId); |
| 2294 | } |
| 2295 | } |
| 2296 | |
| 2297 | private Phone getPhoneFromSubId(int subId) { |
| 2298 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2299 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2300 | } |
| 2301 | |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2302 | private UiccPort getUiccPortFromRequest(MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2303 | Phone phone = getPhoneFromRequest(request); |
| 2304 | return phone == null ? null : |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2305 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2306 | } |
| 2307 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2308 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2309 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2310 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2311 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2312 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2313 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2314 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2315 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2316 | } |
| 2317 | |
| 2318 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2319 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2320 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2321 | } |
| 2322 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2323 | private boolean isImsAvailableOnDevice() { |
| 2324 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2325 | if (pm == null) { |
| 2326 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2327 | // so do not throw error and allow. |
| 2328 | return true; |
| 2329 | } |
| 2330 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2331 | } |
| 2332 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2333 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2334 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2335 | } |
| 2336 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2337 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2338 | if (DBG) log("dial: " + number); |
| 2339 | // No permission check needed here: This is just a wrapper around the |
| 2340 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2341 | // the UI before it does anything. |
| 2342 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2343 | final long identity = Binder.clearCallingIdentity(); |
| 2344 | try { |
| 2345 | String url = createTelUrl(number); |
| 2346 | if (url == null) { |
| 2347 | return; |
| 2348 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2349 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2350 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2351 | PhoneConstants.State state = mCM.getState(subId); |
| 2352 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2353 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2354 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2355 | mApp.startActivity(intent); |
| 2356 | } |
| 2357 | } finally { |
| 2358 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2359 | } |
| 2360 | } |
| 2361 | |
| 2362 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2363 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2364 | } |
| 2365 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2366 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2367 | if (DBG) log("call: " + number); |
| 2368 | |
| 2369 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2370 | // need to do a permission check since we're calling startActivity() |
| 2371 | // from the context of the phone app. |
| 2372 | enforceCallPermission(); |
| 2373 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2374 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2375 | != AppOpsManager.MODE_ALLOWED) { |
| 2376 | return; |
| 2377 | } |
| 2378 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2379 | final long identity = Binder.clearCallingIdentity(); |
| 2380 | try { |
| 2381 | String url = createTelUrl(number); |
| 2382 | if (url == null) { |
| 2383 | return; |
| 2384 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2385 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2386 | boolean isValid = false; |
| 2387 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2388 | if (slist != null) { |
| 2389 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2390 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2391 | isValid = true; |
| 2392 | break; |
| 2393 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2394 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2395 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2396 | if (!isValid) { |
| 2397 | return; |
| 2398 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2399 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2400 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2401 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2402 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2403 | mApp.startActivity(intent); |
| 2404 | } finally { |
| 2405 | Binder.restoreCallingIdentity(identity); |
| 2406 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2407 | } |
| 2408 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2409 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2410 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2411 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2412 | } |
| 2413 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2414 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2415 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2416 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2417 | } |
| 2418 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2419 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2420 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2421 | |
| 2422 | final long identity = Binder.clearCallingIdentity(); |
| 2423 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2424 | Phone phone = getPhone(subId); |
| 2425 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2426 | checkSimPin.start(); |
| 2427 | return checkSimPin.unlockSim(null, pin); |
| 2428 | } finally { |
| 2429 | Binder.restoreCallingIdentity(identity); |
| 2430 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2431 | } |
| 2432 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2433 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, 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 checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2440 | checkSimPuk.start(); |
| 2441 | return checkSimPuk.unlockSim(puk, pin); |
| 2442 | } finally { |
| 2443 | Binder.restoreCallingIdentity(identity); |
| 2444 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2445 | } |
| 2446 | |
| 2447 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2448 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2449 | * a synchronous one. |
| 2450 | */ |
| 2451 | private static class UnlockSim extends Thread { |
| 2452 | |
| 2453 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2454 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2455 | |
| 2456 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2457 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2458 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2459 | |
| 2460 | // For replies from SimCard interface |
| 2461 | private Handler mHandler; |
| 2462 | |
| 2463 | // For async handler to identify request type |
| 2464 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2465 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2466 | UnlockSim(int phoneId, IccCard simCard) { |
| 2467 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2468 | mSimCard = simCard; |
| 2469 | } |
| 2470 | |
| 2471 | @Override |
| 2472 | public void run() { |
| 2473 | Looper.prepare(); |
| 2474 | synchronized (UnlockSim.this) { |
| 2475 | mHandler = new Handler() { |
| 2476 | @Override |
| 2477 | public void handleMessage(Message msg) { |
| 2478 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2479 | switch (msg.what) { |
| 2480 | case SUPPLY_PIN_COMPLETE: |
| 2481 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2482 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2483 | mRetryCount = msg.arg1; |
| 2484 | if (ar.exception != null) { |
| 2485 | if (ar.exception instanceof CommandException && |
| 2486 | ((CommandException)(ar.exception)).getCommandError() |
| 2487 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2488 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2489 | } //When UiccCardApp dispose,handle message and return exception |
| 2490 | else if (ar.exception instanceof CommandException && |
| 2491 | ((CommandException) (ar.exception)).getCommandError() |
| 2492 | == CommandException.Error.ABORTED) { |
| 2493 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2494 | } else { |
| 2495 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2496 | } |
| 2497 | } else { |
| 2498 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2499 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2500 | mDone = true; |
| 2501 | UnlockSim.this.notifyAll(); |
| 2502 | } |
| 2503 | break; |
| 2504 | } |
| 2505 | } |
| 2506 | }; |
| 2507 | UnlockSim.this.notifyAll(); |
| 2508 | } |
| 2509 | Looper.loop(); |
| 2510 | } |
| 2511 | |
| 2512 | /* |
| 2513 | * Use PIN or PUK to unlock SIM card |
| 2514 | * |
| 2515 | * If PUK is null, unlock SIM card with PIN |
| 2516 | * |
| 2517 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2518 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2519 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2520 | |
| 2521 | while (mHandler == null) { |
| 2522 | try { |
| 2523 | wait(); |
| 2524 | } catch (InterruptedException e) { |
| 2525 | Thread.currentThread().interrupt(); |
| 2526 | } |
| 2527 | } |
| 2528 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2529 | |
| 2530 | if (puk == null) { |
| 2531 | mSimCard.supplyPin(pin, callback); |
| 2532 | } else { |
| 2533 | mSimCard.supplyPuk(puk, pin, callback); |
| 2534 | } |
| 2535 | |
| 2536 | while (!mDone) { |
| 2537 | try { |
| 2538 | Log.d(LOG_TAG, "wait for done"); |
| 2539 | wait(); |
| 2540 | } catch (InterruptedException e) { |
| 2541 | // Restore the interrupted status |
| 2542 | Thread.currentThread().interrupt(); |
| 2543 | } |
| 2544 | } |
| 2545 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2546 | int[] resultArray = new int[2]; |
| 2547 | resultArray[0] = mResult; |
| 2548 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2549 | |
| 2550 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | bb77752 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2551 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2552 | } |
| 2553 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2554 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2555 | } |
| 2556 | } |
| 2557 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2558 | /** |
| 2559 | * This method has been removed due to privacy and stability concerns. |
| 2560 | */ |
| 2561 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2562 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2563 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2564 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2565 | } |
| 2566 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2567 | @Override |
| 2568 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2569 | mApp.getSystemService(AppOpsManager.class) |
| 2570 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2571 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2572 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2573 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2574 | // Callers targeting S have no business invoking this method. |
| 2575 | return; |
| 2576 | } |
| 2577 | |
| 2578 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2579 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2580 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2581 | .setCallingPackage(callingPackage) |
| 2582 | .setCallingFeatureId(null) |
| 2583 | .setCallingPid(Binder.getCallingPid()) |
| 2584 | .setCallingUid(Binder.getCallingUid()) |
| 2585 | .setMethod("updateServiceLocation") |
| 2586 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2587 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2588 | .build()); |
| 2589 | // Apps that lack location permission have no business calling this method; |
| 2590 | // however, because no permission was declared in the public API, denials must |
| 2591 | // all be "soft". |
| 2592 | switch (locationResult) { |
| 2593 | case DENIED_HARD: /* fall through */ |
| 2594 | case DENIED_SOFT: |
| 2595 | return; |
| 2596 | } |
| 2597 | |
| 2598 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2599 | final long identity = Binder.clearCallingIdentity(); |
| 2600 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2601 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2602 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2603 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2604 | } |
| 2605 | } finally { |
| 2606 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2607 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2608 | } |
| 2609 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2610 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2611 | @Override |
| 2612 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2613 | return isRadioOnWithFeature(callingPackage, null); |
| 2614 | } |
| 2615 | |
| 2616 | |
| 2617 | @Override |
| 2618 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2619 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2620 | callingFeatureId); |
| 2621 | } |
| 2622 | |
| 2623 | @Deprecated |
| 2624 | @Override |
| 2625 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2626 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2627 | } |
| 2628 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2629 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2630 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2631 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2632 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2633 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2634 | return false; |
| 2635 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2636 | |
| 2637 | final long identity = Binder.clearCallingIdentity(); |
| 2638 | try { |
| 2639 | return isRadioOnForSubscriber(subId); |
| 2640 | } finally { |
| 2641 | Binder.restoreCallingIdentity(identity); |
| 2642 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2643 | } |
| 2644 | |
| 2645 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2646 | final long identity = Binder.clearCallingIdentity(); |
| 2647 | try { |
| 2648 | final Phone phone = getPhone(subId); |
| 2649 | if (phone != null) { |
| 2650 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2651 | } else { |
| 2652 | return false; |
| 2653 | } |
| 2654 | } finally { |
| 2655 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2656 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2657 | } |
| 2658 | |
| 2659 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2660 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2661 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2662 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2663 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2664 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2665 | |
| 2666 | final long identity = Binder.clearCallingIdentity(); |
| 2667 | try { |
| 2668 | final Phone phone = getPhone(subId); |
| 2669 | if (phone != null) { |
| 2670 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2671 | } |
| 2672 | } finally { |
| 2673 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2674 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2675 | } |
| 2676 | |
| 2677 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2678 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2679 | } |
| 2680 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2681 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2682 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2683 | |
| 2684 | final long identity = Binder.clearCallingIdentity(); |
| 2685 | try { |
| 2686 | final Phone phone = getPhone(subId); |
| 2687 | if (phone == null) { |
| 2688 | return false; |
| 2689 | } |
| 2690 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2691 | toggleRadioOnOffForSubscriber(subId); |
| 2692 | } |
| 2693 | return true; |
| 2694 | } finally { |
| 2695 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2696 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2697 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2698 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2699 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2700 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2701 | /* |
| 2702 | * If any of the Radios are available, it will need to be |
| 2703 | * shutdown. So return true if any Radio is available. |
| 2704 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2705 | final long identity = Binder.clearCallingIdentity(); |
| 2706 | try { |
| 2707 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2708 | Phone phone = PhoneFactory.getPhone(i); |
| 2709 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2710 | } |
| 2711 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2712 | return false; |
| 2713 | } finally { |
| 2714 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2715 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2716 | } |
| 2717 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2718 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2719 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2720 | enforceModifyPermission(); |
| 2721 | |
| 2722 | final long identity = Binder.clearCallingIdentity(); |
| 2723 | try { |
| 2724 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2725 | logv("Shutting down Phone " + i); |
| 2726 | shutdownRadioUsingPhoneId(i); |
| 2727 | } |
| 2728 | } finally { |
| 2729 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2730 | } |
| 2731 | } |
| 2732 | |
| 2733 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2734 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2735 | if (phone != null && phone.isRadioAvailable()) { |
| 2736 | phone.shutdownRadio(); |
| 2737 | } |
| 2738 | } |
| 2739 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2740 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2741 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2742 | |
| 2743 | final long identity = Binder.clearCallingIdentity(); |
| 2744 | try { |
| 2745 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2746 | if (defaultPhone != null) { |
| 2747 | defaultPhone.setRadioPower(turnOn); |
| 2748 | return true; |
| 2749 | } else { |
| 2750 | loge("There's no default phone."); |
| 2751 | return false; |
| 2752 | } |
| 2753 | } finally { |
| 2754 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2755 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2756 | } |
| 2757 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2758 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2759 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2760 | |
| 2761 | final long identity = Binder.clearCallingIdentity(); |
| 2762 | try { |
| 2763 | final Phone phone = getPhone(subId); |
| 2764 | if (phone != null) { |
| 2765 | phone.setRadioPower(turnOn); |
| 2766 | return true; |
| 2767 | } else { |
| 2768 | return false; |
| 2769 | } |
| 2770 | } finally { |
| 2771 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2772 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2773 | } |
| 2774 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2775 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2776 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2777 | public boolean enableDataConnectivity() { |
| 2778 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2779 | |
| 2780 | final long identity = Binder.clearCallingIdentity(); |
| 2781 | try { |
| 2782 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2783 | final Phone phone = getPhone(subId); |
| 2784 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2785 | phone.getDataEnabledSettings().setDataEnabled( |
| 2786 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2787 | return true; |
| 2788 | } else { |
| 2789 | return false; |
| 2790 | } |
| 2791 | } finally { |
| 2792 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2793 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2794 | } |
| 2795 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2796 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2797 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2798 | public boolean disableDataConnectivity() { |
| 2799 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2800 | |
| 2801 | final long identity = Binder.clearCallingIdentity(); |
| 2802 | try { |
| 2803 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2804 | final Phone phone = getPhone(subId); |
| 2805 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2806 | phone.getDataEnabledSettings().setDataEnabled( |
| 2807 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2808 | return true; |
| 2809 | } else { |
| 2810 | return false; |
| 2811 | } |
| 2812 | } finally { |
| 2813 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2814 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2815 | } |
| 2816 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2817 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2818 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2819 | final long identity = Binder.clearCallingIdentity(); |
| 2820 | try { |
| 2821 | final Phone phone = getPhone(subId); |
| 2822 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2823 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2824 | } else { |
| 2825 | return false; |
| 2826 | } |
| 2827 | } finally { |
| 2828 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2829 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2830 | } |
| 2831 | |
| 2832 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2833 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2834 | } |
| 2835 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2836 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2837 | enforceCallPermission(); |
| 2838 | |
| 2839 | final long identity = Binder.clearCallingIdentity(); |
| 2840 | try { |
| 2841 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2842 | return; |
| 2843 | } |
| 2844 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2845 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2846 | } finally { |
| 2847 | Binder.restoreCallingIdentity(identity); |
| 2848 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2849 | }; |
| 2850 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2851 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2852 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2853 | |
| 2854 | final long identity = Binder.clearCallingIdentity(); |
| 2855 | try { |
| 2856 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2857 | return false; |
| 2858 | } |
| 2859 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2860 | } finally { |
| 2861 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2862 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2863 | } |
| 2864 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2865 | /** |
| 2866 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 2867 | * tag on getCallState Binder call. |
| 2868 | */ |
| 2869 | @Deprecated |
| 2870 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2871 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2872 | if (CompatChanges.isChangeEnabled( |
| 2873 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2874 | Binder.getCallingUid())) { |
| 2875 | // Do not allow this API to be called on API version 31+, it should only be |
| 2876 | // called on old apps using this Binder call directly. |
| 2877 | throw new SecurityException("This method can only be used for applications " |
| 2878 | + "targeting API version 30 or less."); |
| 2879 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2880 | final long identity = Binder.clearCallingIdentity(); |
| 2881 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2882 | Phone phone = getPhone(getDefaultSubscription()); |
| 2883 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2884 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2885 | } finally { |
| 2886 | Binder.restoreCallingIdentity(identity); |
| 2887 | } |
| 2888 | } |
| 2889 | |
| 2890 | @Override |
| 2891 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 2892 | if (CompatChanges.isChangeEnabled( |
| 2893 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2894 | Binder.getCallingUid())) { |
| 2895 | // Check READ_PHONE_STATE for API version 31+ |
| 2896 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2897 | featureId, "getCallStateForSubscription")) { |
| 2898 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 2899 | + "targeting API level 31+."); |
| 2900 | } |
| 2901 | } |
| 2902 | final long identity = Binder.clearCallingIdentity(); |
| 2903 | try { |
| 2904 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2905 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2906 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2907 | } finally { |
| 2908 | Binder.restoreCallingIdentity(identity); |
| 2909 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2910 | } |
| 2911 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2912 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2913 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2914 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2915 | } |
| 2916 | |
| 2917 | @Override |
| 2918 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2919 | final long identity = Binder.clearCallingIdentity(); |
| 2920 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2921 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2922 | if (phone != null) { |
Jack Yu | 4accbd9 | 2021-11-29 11:36:17 -0800 | [diff] [blame^] | 2923 | if (phone.isUsingNewDataStack()) { |
| 2924 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
| 2925 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2926 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2927 | } else { |
| 2928 | return PhoneConstantConversions.convertDataState( |
| 2929 | PhoneConstants.DataState.DISCONNECTED); |
| 2930 | } |
| 2931 | } finally { |
| 2932 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2933 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2934 | } |
| 2935 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2936 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2937 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2938 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2939 | } |
| 2940 | |
| 2941 | @Override |
| 2942 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2943 | final long identity = Binder.clearCallingIdentity(); |
| 2944 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2945 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2946 | if (phone != null) { |
| 2947 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2948 | } else { |
| 2949 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2950 | } |
| 2951 | } finally { |
| 2952 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2953 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2954 | } |
| 2955 | |
| 2956 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2957 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2958 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2959 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2960 | |
| 2961 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2962 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2963 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2964 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2965 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2966 | .setCallingPid(Binder.getCallingPid()) |
| 2967 | .setCallingUid(Binder.getCallingUid()) |
| 2968 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2969 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2970 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2971 | .build()); |
| 2972 | switch (locationResult) { |
| 2973 | case DENIED_HARD: |
| 2974 | throw new SecurityException("Not allowed to access cell location"); |
| 2975 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2976 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2977 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2978 | } |
| 2979 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2980 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2981 | final long identity = Binder.clearCallingIdentity(); |
| 2982 | try { |
| 2983 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2984 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2985 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2986 | } finally { |
| 2987 | Binder.restoreCallingIdentity(identity); |
| 2988 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2989 | } |
| 2990 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2991 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2992 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2993 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2994 | // registered cell info, so return a NULL country instead. |
| 2995 | final long identity = Binder.clearCallingIdentity(); |
| 2996 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2997 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2998 | // Get default phone in this case. |
| 2999 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3000 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3001 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3002 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3003 | if (phone == null) return ""; |
| 3004 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3005 | if (sst == null) return ""; |
| 3006 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3007 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3008 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3009 | } finally { |
| 3010 | Binder.restoreCallingIdentity(identity); |
| 3011 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3012 | } |
| 3013 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3014 | /** |
| 3015 | * This method was removed due to potential issues caused by performing partial |
| 3016 | * updates of service state, and lack of a credible use case. |
| 3017 | * |
| 3018 | * This has the ability to break the telephony implementation by disabling notification of |
| 3019 | * changes in device connectivity. DO NOT USE THIS! |
| 3020 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3021 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3022 | public void enableLocationUpdates() { |
| 3023 | mApp.enforceCallingOrSelfPermission( |
| 3024 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3025 | } |
| 3026 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3027 | /** |
| 3028 | * This method was removed due to potential issues caused by performing partial |
| 3029 | * updates of service state, and lack of a credible use case. |
| 3030 | * |
| 3031 | * This has the ability to break the telephony implementation by disabling notification of |
| 3032 | * changes in device connectivity. DO NOT USE THIS! |
| 3033 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3034 | @Override |
| 3035 | public void disableLocationUpdates() { |
| 3036 | mApp.enforceCallingOrSelfPermission( |
| 3037 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3038 | } |
| 3039 | |
| 3040 | @Override |
| 3041 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3042 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3043 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3044 | try { |
| 3045 | mApp.getSystemService(AppOpsManager.class) |
| 3046 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3047 | } catch (SecurityException e) { |
| 3048 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3049 | throw e; |
| 3050 | } |
| 3051 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3052 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3053 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3054 | throw new SecurityException( |
| 3055 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3056 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3057 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3058 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3059 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3060 | return null; |
| 3061 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3062 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3063 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3064 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3065 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3066 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3067 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3068 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3069 | for (CellInfo ci : info) { |
| 3070 | if (ci instanceof CellInfoGsm) { |
| 3071 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3072 | } else if (ci instanceof CellInfoWcdma) { |
| 3073 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3074 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3075 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3076 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3077 | } |
| 3078 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3079 | private List<CellInfo> getCachedCellInfo() { |
| 3080 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3081 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3082 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3083 | if (info != null) cellInfos.addAll(info); |
| 3084 | } |
| 3085 | return cellInfos; |
| 3086 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3087 | |
| 3088 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3089 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3090 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3091 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3092 | |
| 3093 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3094 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3095 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3096 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3097 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3098 | .setCallingPid(Binder.getCallingPid()) |
| 3099 | .setCallingUid(Binder.getCallingUid()) |
| 3100 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3101 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3102 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3103 | .build()); |
| 3104 | switch (locationResult) { |
| 3105 | case DENIED_HARD: |
| 3106 | throw new SecurityException("Not allowed to access cell info"); |
| 3107 | case DENIED_SOFT: |
| 3108 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3109 | } |
| 3110 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3111 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3112 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3113 | return getCachedCellInfo(); |
| 3114 | } |
| 3115 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3116 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3117 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3118 | final long identity = Binder.clearCallingIdentity(); |
| 3119 | try { |
| 3120 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3121 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3122 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3123 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3124 | if (info != null) cellInfos.addAll(info); |
| 3125 | } |
| 3126 | return cellInfos; |
| 3127 | } finally { |
| 3128 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3129 | } |
| 3130 | } |
| 3131 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3132 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3133 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3134 | String callingFeatureId) { |
| 3135 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3136 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3137 | } |
| 3138 | |
| 3139 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3140 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3141 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3142 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3143 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3144 | } |
| 3145 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3146 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3147 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3148 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3149 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3150 | |
| 3151 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3152 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3153 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3154 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3155 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3156 | .setCallingPid(Binder.getCallingPid()) |
| 3157 | .setCallingUid(Binder.getCallingUid()) |
| 3158 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3159 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3160 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3161 | .build()); |
| 3162 | switch (locationResult) { |
| 3163 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3164 | if (TelephonyPermissions |
| 3165 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3166 | // Safetynet logging for b/154934934 |
| 3167 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3168 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3169 | throw new SecurityException("Not allowed to access cell info"); |
| 3170 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3171 | if (TelephonyPermissions |
| 3172 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3173 | // Safetynet logging for b/154934934 |
| 3174 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3175 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3176 | try { |
| 3177 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3178 | } catch (RemoteException re) { |
| 3179 | // Drop without consequences |
| 3180 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3181 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3182 | } |
| 3183 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3184 | |
| 3185 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3186 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3187 | |
| 3188 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3189 | } |
| 3190 | |
| 3191 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3192 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3193 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3194 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3195 | |
| 3196 | final long identity = Binder.clearCallingIdentity(); |
| 3197 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3198 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3199 | } finally { |
| 3200 | Binder.restoreCallingIdentity(identity); |
| 3201 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3202 | } |
| 3203 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3204 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3205 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3206 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3207 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3208 | return null; |
| 3209 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3210 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3211 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3212 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3213 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3214 | return null; |
| 3215 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3216 | |
| 3217 | final long identity = Binder.clearCallingIdentity(); |
| 3218 | try { |
| 3219 | return phone.getImei(); |
| 3220 | } finally { |
| 3221 | Binder.restoreCallingIdentity(identity); |
| 3222 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3223 | } |
| 3224 | |
| 3225 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3226 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3227 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3228 | String tac = null; |
| 3229 | if (phone != null) { |
| 3230 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3231 | try { |
| 3232 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3233 | } catch (IndexOutOfBoundsException e) { |
| 3234 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3235 | return null; |
| 3236 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3237 | } |
| 3238 | return tac; |
| 3239 | } |
| 3240 | |
| 3241 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3242 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3243 | try { |
| 3244 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3245 | } catch (SecurityException se) { |
| 3246 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3247 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3248 | + Binder.getCallingUid()); |
| 3249 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3250 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3251 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3252 | return null; |
| 3253 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3254 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3255 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3256 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3257 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3258 | return null; |
| 3259 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3260 | |
| 3261 | final long identity = Binder.clearCallingIdentity(); |
| 3262 | try { |
| 3263 | return phone.getMeid(); |
| 3264 | } finally { |
| 3265 | Binder.restoreCallingIdentity(identity); |
| 3266 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3267 | } |
| 3268 | |
| 3269 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3270 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3271 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3272 | String manufacturerCode = null; |
| 3273 | if (phone != null) { |
| 3274 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3275 | try { |
| 3276 | manufacturerCode = |
| 3277 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3278 | } catch (IndexOutOfBoundsException e) { |
| 3279 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3280 | return null; |
| 3281 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3282 | } |
| 3283 | return manufacturerCode; |
| 3284 | } |
| 3285 | |
| 3286 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3287 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3288 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3289 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3290 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3291 | return null; |
| 3292 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3293 | int subId = phone.getSubId(); |
| 3294 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3295 | mApp, subId, callingPackage, callingFeatureId, |
| 3296 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3297 | return null; |
| 3298 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3299 | |
| 3300 | final long identity = Binder.clearCallingIdentity(); |
| 3301 | try { |
| 3302 | return phone.getDeviceSvn(); |
| 3303 | } finally { |
| 3304 | Binder.restoreCallingIdentity(identity); |
| 3305 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3306 | } |
| 3307 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3308 | @Override |
| 3309 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3310 | final long identity = Binder.clearCallingIdentity(); |
| 3311 | try { |
| 3312 | final Phone phone = getPhone(subId); |
| 3313 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3314 | } finally { |
| 3315 | Binder.restoreCallingIdentity(identity); |
| 3316 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3317 | } |
| 3318 | |
| 3319 | @Override |
| 3320 | public String getSubscriptionCarrierName(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 ? null : phone.getCarrierName(); |
| 3325 | } finally { |
| 3326 | Binder.restoreCallingIdentity(identity); |
| 3327 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3328 | } |
| 3329 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3330 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3331 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3332 | final long identity = Binder.clearCallingIdentity(); |
| 3333 | try { |
| 3334 | final Phone phone = getPhone(subId); |
| 3335 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3336 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3337 | } finally { |
| 3338 | Binder.restoreCallingIdentity(identity); |
| 3339 | } |
| 3340 | } |
| 3341 | |
| 3342 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3343 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3344 | final long identity = Binder.clearCallingIdentity(); |
| 3345 | try { |
| 3346 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3347 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3348 | } finally { |
| 3349 | Binder.restoreCallingIdentity(identity); |
| 3350 | } |
| 3351 | } |
| 3352 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3353 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3354 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3355 | if (!isSubscriptionMccMnc) { |
| 3356 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3357 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3358 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3359 | if (phone == null) { |
| 3360 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3361 | } |
| 3362 | final long identity = Binder.clearCallingIdentity(); |
| 3363 | try { |
| 3364 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3365 | } finally { |
| 3366 | Binder.restoreCallingIdentity(identity); |
| 3367 | } |
| 3368 | } |
| 3369 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3370 | // |
| 3371 | // Internal helper methods. |
| 3372 | // |
| 3373 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3374 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3375 | * Make sure the caller is the calling package itself |
| 3376 | * |
| 3377 | * @throws SecurityException if the caller is not the calling package |
| 3378 | */ |
| 3379 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3380 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3381 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3382 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3383 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3384 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3385 | } catch (PackageManager.NameNotFoundException e) { |
| 3386 | // packageUid is -1 |
| 3387 | } |
| 3388 | if (packageUid != callingUid) { |
| 3389 | throw new SecurityException(message + ": Package " + callingPackage |
| 3390 | + " does not belong to " + callingUid); |
| 3391 | } |
| 3392 | } |
| 3393 | |
| 3394 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3395 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3396 | * |
| 3397 | * @throws SecurityException if the caller does not have the required permission |
| 3398 | */ |
| 3399 | private void enforceModifyPermission() { |
| 3400 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3401 | } |
| 3402 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3403 | private void enforceActiveEmergencySessionPermission() { |
| 3404 | mApp.enforceCallingOrSelfPermission( |
| 3405 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3406 | } |
| 3407 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3408 | /** |
| 3409 | * Make sure the caller has the CALL_PHONE permission. |
| 3410 | * |
| 3411 | * @throws SecurityException if the caller does not have the required permission |
| 3412 | */ |
| 3413 | private void enforceCallPermission() { |
| 3414 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3415 | } |
| 3416 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3417 | private void enforceSettingsPermission() { |
| 3418 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3419 | } |
| 3420 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3421 | private void enforceRebootPermission() { |
| 3422 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3423 | } |
| 3424 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3425 | private String createTelUrl(String number) { |
| 3426 | if (TextUtils.isEmpty(number)) { |
| 3427 | return null; |
| 3428 | } |
| 3429 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3430 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3431 | } |
| 3432 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3433 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3434 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3435 | } |
| 3436 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3437 | private static void logv(String msg) { |
| 3438 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3439 | } |
| 3440 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3441 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3442 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3443 | } |
| 3444 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3445 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3446 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3447 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3448 | } |
| 3449 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3450 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3451 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3452 | final long identity = Binder.clearCallingIdentity(); |
| 3453 | try { |
| 3454 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3455 | if (phone == null) { |
| 3456 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3457 | } else { |
| 3458 | return phone.getPhoneType(); |
| 3459 | } |
| 3460 | } finally { |
| 3461 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3462 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3463 | } |
| 3464 | |
| 3465 | /** |
| 3466 | * Returns the CDMA ERI icon index to display |
| 3467 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3468 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3469 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3470 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3471 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3472 | } |
| 3473 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3474 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3475 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3476 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3477 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3478 | mApp, subId, callingPackage, callingFeatureId, |
| 3479 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3480 | return -1; |
| 3481 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3482 | |
| 3483 | final long identity = Binder.clearCallingIdentity(); |
| 3484 | try { |
| 3485 | final Phone phone = getPhone(subId); |
| 3486 | if (phone != null) { |
| 3487 | return phone.getCdmaEriIconIndex(); |
| 3488 | } else { |
| 3489 | return -1; |
| 3490 | } |
| 3491 | } finally { |
| 3492 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3493 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3494 | } |
| 3495 | |
| 3496 | /** |
| 3497 | * Returns the CDMA ERI icon mode, |
| 3498 | * 0 - ON |
| 3499 | * 1 - FLASHING |
| 3500 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3501 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3502 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3503 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3504 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3505 | } |
| 3506 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3507 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3508 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3509 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3510 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3511 | mApp, subId, callingPackage, callingFeatureId, |
| 3512 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3513 | return -1; |
| 3514 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3515 | |
| 3516 | final long identity = Binder.clearCallingIdentity(); |
| 3517 | try { |
| 3518 | final Phone phone = getPhone(subId); |
| 3519 | if (phone != null) { |
| 3520 | return phone.getCdmaEriIconMode(); |
| 3521 | } else { |
| 3522 | return -1; |
| 3523 | } |
| 3524 | } finally { |
| 3525 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3526 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3527 | } |
| 3528 | |
| 3529 | /** |
| 3530 | * Returns the CDMA ERI text, |
| 3531 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3532 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3533 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3534 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3535 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3536 | } |
| 3537 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3538 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3539 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3540 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3541 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3542 | mApp, subId, callingPackage, callingFeatureId, |
| 3543 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3544 | return null; |
| 3545 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3546 | |
| 3547 | final long identity = Binder.clearCallingIdentity(); |
| 3548 | try { |
| 3549 | final Phone phone = getPhone(subId); |
| 3550 | if (phone != null) { |
| 3551 | return phone.getCdmaEriText(); |
| 3552 | } else { |
| 3553 | return null; |
| 3554 | } |
| 3555 | } finally { |
| 3556 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3557 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3558 | } |
| 3559 | |
| 3560 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3561 | * Returns the CDMA MDN. |
| 3562 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3563 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3564 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3565 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3566 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3567 | |
| 3568 | final long identity = Binder.clearCallingIdentity(); |
| 3569 | try { |
| 3570 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3571 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3572 | return phone.getLine1Number(); |
| 3573 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3574 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3575 | return null; |
| 3576 | } |
| 3577 | } finally { |
| 3578 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3579 | } |
| 3580 | } |
| 3581 | |
| 3582 | /** |
| 3583 | * Returns the CDMA MIN. |
| 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 getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3587 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3588 | mApp, subId, "getCdmaMin"); |
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); |
| 3593 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3594 | return phone.getCdmaMin(); |
| 3595 | } else { |
| 3596 | return null; |
| 3597 | } |
| 3598 | } finally { |
| 3599 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3600 | } |
| 3601 | } |
| 3602 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3603 | @Override |
| 3604 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3605 | INumberVerificationCallback callback, String callingPackage) { |
| 3606 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3607 | != PERMISSION_GRANTED) { |
| 3608 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3609 | } |
| 3610 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3611 | |
| 3612 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3613 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3614 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3615 | + "calling package: " + callingPackage |
| 3616 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3617 | } |
| 3618 | |
| 3619 | if (range == null) { |
| 3620 | throw new NullPointerException("Range must be non-null"); |
| 3621 | } |
| 3622 | |
| 3623 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3624 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3625 | |
| 3626 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3627 | } |
| 3628 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3629 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3630 | * Returns true if CDMA provisioning needs to run. |
| 3631 | */ |
| 3632 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3633 | final long identity = Binder.clearCallingIdentity(); |
| 3634 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3635 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3636 | } finally { |
| 3637 | Binder.restoreCallingIdentity(identity); |
| 3638 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3639 | } |
| 3640 | |
| 3641 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3642 | * Sets the voice mail number of a given subId. |
| 3643 | */ |
| 3644 | @Override |
| 3645 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3646 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3647 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3648 | |
| 3649 | final long identity = Binder.clearCallingIdentity(); |
| 3650 | try { |
| 3651 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3652 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3653 | return success; |
| 3654 | } finally { |
| 3655 | Binder.restoreCallingIdentity(identity); |
| 3656 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3657 | } |
| 3658 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3659 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3660 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3661 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3662 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3663 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3664 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3665 | throw new SecurityException("caller must be system dialer"); |
| 3666 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3667 | |
| 3668 | final long identity = Binder.clearCallingIdentity(); |
| 3669 | try { |
| 3670 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3671 | if (phoneAccountHandle == null) { |
| 3672 | return null; |
| 3673 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3674 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3675 | } finally { |
| 3676 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3677 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3678 | } |
| 3679 | |
| 3680 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3681 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3682 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3683 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3684 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3685 | mApp, subId, callingPackage, callingFeatureId, |
| 3686 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3687 | return null; |
| 3688 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3689 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3690 | final long identity = Binder.clearCallingIdentity(); |
| 3691 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3692 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3693 | } finally { |
| 3694 | Binder.restoreCallingIdentity(identity); |
| 3695 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3696 | } |
| 3697 | |
| 3698 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3699 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3700 | VisualVoicemailSmsFilterSettings settings) { |
| 3701 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3702 | |
| 3703 | final long identity = Binder.clearCallingIdentity(); |
| 3704 | try { |
| 3705 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3706 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3707 | } finally { |
| 3708 | Binder.restoreCallingIdentity(identity); |
| 3709 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3710 | } |
| 3711 | |
| 3712 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3713 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3714 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3715 | |
| 3716 | final long identity = Binder.clearCallingIdentity(); |
| 3717 | try { |
| 3718 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3719 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3720 | } finally { |
| 3721 | Binder.restoreCallingIdentity(identity); |
| 3722 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3723 | } |
| 3724 | |
| 3725 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3726 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3727 | String callingPackage, int subId) { |
| 3728 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3729 | |
| 3730 | final long identity = Binder.clearCallingIdentity(); |
| 3731 | try { |
| 3732 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3733 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3734 | } finally { |
| 3735 | Binder.restoreCallingIdentity(identity); |
| 3736 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3737 | } |
| 3738 | |
| 3739 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3740 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3741 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3742 | |
| 3743 | final long identity = Binder.clearCallingIdentity(); |
| 3744 | try { |
| 3745 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3746 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3747 | } finally { |
| 3748 | Binder.restoreCallingIdentity(identity); |
| 3749 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3750 | } |
| 3751 | |
| 3752 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3753 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3754 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3755 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3756 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3757 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3758 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3759 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3760 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3761 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3762 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3763 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3764 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3765 | * Sets the voice activation state of a given subId. |
| 3766 | */ |
| 3767 | @Override |
| 3768 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3769 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3770 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3771 | |
| 3772 | final long identity = Binder.clearCallingIdentity(); |
| 3773 | try { |
| 3774 | final Phone phone = getPhone(subId); |
| 3775 | if (phone != null) { |
| 3776 | phone.setVoiceActivationState(activationState); |
| 3777 | } else { |
| 3778 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3779 | } |
| 3780 | } finally { |
| 3781 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3782 | } |
| 3783 | } |
| 3784 | |
| 3785 | /** |
| 3786 | * Sets the data activation state of a given subId. |
| 3787 | */ |
| 3788 | @Override |
| 3789 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3790 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3791 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3792 | |
| 3793 | final long identity = Binder.clearCallingIdentity(); |
| 3794 | try { |
| 3795 | final Phone phone = getPhone(subId); |
| 3796 | if (phone != null) { |
| 3797 | phone.setDataActivationState(activationState); |
| 3798 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3799 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3800 | } |
| 3801 | } finally { |
| 3802 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3803 | } |
| 3804 | } |
| 3805 | |
| 3806 | /** |
| 3807 | * Returns the voice activation state of a given subId. |
| 3808 | */ |
| 3809 | @Override |
| 3810 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3811 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3812 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3813 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3814 | final long identity = Binder.clearCallingIdentity(); |
| 3815 | try { |
| 3816 | if (phone != null) { |
| 3817 | return phone.getVoiceActivationState(); |
| 3818 | } else { |
| 3819 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3820 | } |
| 3821 | } finally { |
| 3822 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3823 | } |
| 3824 | } |
| 3825 | |
| 3826 | /** |
| 3827 | * Returns the data activation state of a given subId. |
| 3828 | */ |
| 3829 | @Override |
| 3830 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3831 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3832 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3833 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3834 | final long identity = Binder.clearCallingIdentity(); |
| 3835 | try { |
| 3836 | if (phone != null) { |
| 3837 | return phone.getDataActivationState(); |
| 3838 | } else { |
| 3839 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3840 | } |
| 3841 | } finally { |
| 3842 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3843 | } |
| 3844 | } |
| 3845 | |
| 3846 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3847 | * Returns the unread count of voicemails for a subId |
| 3848 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3849 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3850 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3851 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3852 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3853 | mApp, subId, callingPackage, callingFeatureId, |
| 3854 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3855 | return 0; |
| 3856 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3857 | final long identity = Binder.clearCallingIdentity(); |
| 3858 | try { |
| 3859 | final Phone phone = getPhone(subId); |
| 3860 | if (phone != null) { |
| 3861 | return phone.getVoiceMessageCount(); |
| 3862 | } else { |
| 3863 | return 0; |
| 3864 | } |
| 3865 | } finally { |
| 3866 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3867 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3868 | } |
| 3869 | |
| 3870 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3871 | * returns true, if the device is in a state where both voice and data |
| 3872 | * are supported simultaneously. This can change based on location or network condition. |
| 3873 | */ |
| 3874 | @Override |
| 3875 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3876 | final long identity = Binder.clearCallingIdentity(); |
| 3877 | try { |
| 3878 | final Phone phone = getPhone(subId); |
| 3879 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3880 | } finally { |
| 3881 | Binder.restoreCallingIdentity(identity); |
| 3882 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3883 | } |
| 3884 | |
| 3885 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3886 | * Send the dialer code if called from the current default dialer or the caller has |
| 3887 | * carrier privilege. |
| 3888 | * @param inputCode The dialer code to send |
| 3889 | */ |
| 3890 | @Override |
| 3891 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3892 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3893 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3894 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3895 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3896 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3897 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3898 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3899 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3900 | |
| 3901 | final long identity = Binder.clearCallingIdentity(); |
| 3902 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3903 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3904 | } finally { |
| 3905 | Binder.restoreCallingIdentity(identity); |
| 3906 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3907 | } |
| 3908 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3909 | @Override |
| 3910 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3911 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3912 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3913 | mApp, subId, "getNetworkSelectionMode"); |
| 3914 | final long identity = Binder.clearCallingIdentity(); |
| 3915 | try { |
| 3916 | if (!isActiveSubscription(subId)) { |
| 3917 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3918 | } |
| 3919 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3920 | } finally { |
| 3921 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3922 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3923 | } |
| 3924 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3925 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3926 | public boolean isInEmergencySmsMode() { |
| 3927 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3928 | final long identity = Binder.clearCallingIdentity(); |
| 3929 | try { |
| 3930 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3931 | if (phone.isInEmergencySmsMode()) { |
| 3932 | return true; |
| 3933 | } |
| 3934 | } |
| 3935 | } finally { |
| 3936 | Binder.restoreCallingIdentity(identity); |
| 3937 | } |
| 3938 | return false; |
| 3939 | } |
| 3940 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3941 | /** |
| 3942 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3943 | * @param subId The subscription to use to check the configuration. |
| 3944 | * @param c The callback that will be used to send the result. |
| 3945 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3946 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3947 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3948 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3949 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3950 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3951 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3952 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3953 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3954 | "IMS not available on device."); |
| 3955 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3956 | final long token = Binder.clearCallingIdentity(); |
| 3957 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 3958 | int slotId = getSlotIndexOrException(subId); |
| 3959 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 3960 | ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3961 | } catch (ImsException e) { |
| 3962 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3963 | } finally { |
| 3964 | Binder.restoreCallingIdentity(token); |
| 3965 | } |
| 3966 | } |
| 3967 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3968 | /** |
| 3969 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3970 | * @param subId The subscription to use to check the configuration. |
| 3971 | * @param c The callback that will be used to send the result. |
| 3972 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3973 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3974 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3975 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3976 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3977 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3978 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3979 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3980 | final long token = Binder.clearCallingIdentity(); |
| 3981 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3982 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3983 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3984 | } catch (ImsException e) { |
| 3985 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3986 | + "is inactive, ignoring unregister."); |
| 3987 | // If the subscription is no longer active, just return, since the callback |
| 3988 | // will already have been removed internally. |
| 3989 | } finally { |
| 3990 | Binder.restoreCallingIdentity(token); |
| 3991 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3992 | } |
| 3993 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3994 | /** |
| 3995 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3996 | */ |
| 3997 | @Override |
| 3998 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3999 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4000 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4001 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4002 | "IMS not available on device."); |
| 4003 | } |
| 4004 | final long token = Binder.clearCallingIdentity(); |
| 4005 | try { |
| 4006 | Phone phone = getPhone(subId); |
| 4007 | if (phone == null) { |
| 4008 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4009 | + subId + "'"); |
| 4010 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4011 | } |
| 4012 | phone.getImsRegistrationState(regState -> { |
| 4013 | try { |
| 4014 | consumer.accept((regState == null) |
| 4015 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4016 | } catch (RemoteException e) { |
| 4017 | // Ignore if the remote process is no longer available to call back. |
| 4018 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4019 | } |
| 4020 | }); |
| 4021 | } finally { |
| 4022 | Binder.restoreCallingIdentity(token); |
| 4023 | } |
| 4024 | } |
| 4025 | |
| 4026 | /** |
| 4027 | * Get the transport type for the IMS service registration state. |
| 4028 | */ |
| 4029 | @Override |
| 4030 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4031 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4032 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4033 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4034 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4035 | "IMS not available on device."); |
| 4036 | } |
| 4037 | final long token = Binder.clearCallingIdentity(); |
| 4038 | try { |
| 4039 | Phone phone = getPhone(subId); |
| 4040 | if (phone == null) { |
| 4041 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4042 | + subId + "'"); |
| 4043 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4044 | } |
| 4045 | phone.getImsRegistrationTech(regTech -> { |
| 4046 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4047 | int regTechConverted = (regTech == null) |
| 4048 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4049 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4050 | regTechConverted); |
| 4051 | try { |
| 4052 | consumer.accept(regTechConverted); |
| 4053 | } catch (RemoteException e) { |
| 4054 | // Ignore if the remote process is no longer available to call back. |
| 4055 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4056 | } |
| 4057 | }); |
| 4058 | } finally { |
| 4059 | Binder.restoreCallingIdentity(token); |
| 4060 | } |
| 4061 | } |
| 4062 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4063 | /** |
| 4064 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4065 | * @param subId The subscription to use to check the configuration. |
| 4066 | * @param c The callback that will be used to send the result. |
| 4067 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4068 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4069 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4070 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4071 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4072 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4073 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4074 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4075 | "IMS not available on device."); |
| 4076 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4077 | final long token = Binder.clearCallingIdentity(); |
| 4078 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4079 | int slotId = getSlotIndexOrException(subId); |
| 4080 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4081 | ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4082 | } catch (ImsException e) { |
| 4083 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4084 | } finally { |
| 4085 | Binder.restoreCallingIdentity(token); |
| 4086 | } |
| 4087 | } |
| 4088 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4089 | /** |
| 4090 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4091 | * @param subId The subscription to use to check the configuration. |
| 4092 | * @param c The callback that will be used to send the result. |
| 4093 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4094 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4095 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4096 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4097 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4098 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4099 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4100 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4101 | |
| 4102 | final long token = Binder.clearCallingIdentity(); |
| 4103 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4104 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4105 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4106 | } catch (ImsException e) { |
| 4107 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4108 | + "is inactive, ignoring unregister."); |
| 4109 | // If the subscription is no longer active, just return, since the callback |
| 4110 | // will already have been removed internally. |
| 4111 | } finally { |
| 4112 | Binder.restoreCallingIdentity(token); |
| 4113 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4114 | } |
| 4115 | |
| 4116 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4117 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4118 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4119 | final long token = Binder.clearCallingIdentity(); |
| 4120 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4121 | int slotId = getSlotIndexOrException(subId); |
| 4122 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4123 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4124 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4125 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4126 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4127 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4128 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4129 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4130 | } finally { |
| 4131 | Binder.restoreCallingIdentity(token); |
| 4132 | } |
| 4133 | } |
| 4134 | |
| 4135 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4136 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4137 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4138 | final long token = Binder.clearCallingIdentity(); |
| 4139 | try { |
| 4140 | Phone phone = getPhone(subId); |
| 4141 | if (phone == null) return false; |
| 4142 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4143 | } catch (com.android.ims.ImsException e) { |
| 4144 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4145 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4146 | } finally { |
| 4147 | Binder.restoreCallingIdentity(token); |
| 4148 | } |
| 4149 | } |
| 4150 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4151 | /** |
| 4152 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4153 | * subscription. |
| 4154 | * @param subId The subscription to use to check the configuration. |
| 4155 | * @param callback The callback that will be used to send the result. |
| 4156 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4157 | * @param transportType The transport type of the MmTelFeature capability. |
| 4158 | */ |
| 4159 | @Override |
| 4160 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4161 | int transportType) { |
| 4162 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 4163 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4164 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4165 | "IMS not available on device."); |
| 4166 | } |
| 4167 | final long token = Binder.clearCallingIdentity(); |
| 4168 | try { |
| 4169 | int slotId = getSlotIndex(subId); |
| 4170 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4171 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4172 | + subId + "'"); |
| 4173 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4174 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4175 | verifyImsMmTelConfiguredOrThrow(slotId); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4176 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4177 | transportType, aBoolean -> { |
| 4178 | try { |
| 4179 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4180 | } catch (RemoteException e) { |
| 4181 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4182 | + "running. Ignore"); |
| 4183 | } |
| 4184 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4185 | } catch (ImsException e) { |
| 4186 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4187 | } finally { |
| 4188 | Binder.restoreCallingIdentity(token); |
| 4189 | } |
| 4190 | } |
| 4191 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4192 | /** |
| 4193 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4194 | * @param subId The subscription to use to check the configuration. |
| 4195 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4196 | @Override |
| 4197 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4198 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4199 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4200 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4201 | final long token = Binder.clearCallingIdentity(); |
| 4202 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4203 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4204 | // 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] | 4205 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4206 | } catch (ImsException e) { |
| 4207 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4208 | } finally { |
| 4209 | Binder.restoreCallingIdentity(token); |
| 4210 | } |
| 4211 | } |
| 4212 | |
| 4213 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4214 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4215 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4216 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4217 | final long identity = Binder.clearCallingIdentity(); |
| 4218 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4219 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4220 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4221 | // 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] | 4222 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4223 | } catch (ImsException e) { |
| 4224 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4225 | } finally { |
| 4226 | Binder.restoreCallingIdentity(identity); |
| 4227 | } |
| 4228 | } |
| 4229 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4230 | /** |
| 4231 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4232 | * @param subId The subscription to use to check the configuration. |
| 4233 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4234 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4235 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4236 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4237 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4238 | final long identity = Binder.clearCallingIdentity(); |
| 4239 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4240 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4241 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4242 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4243 | } catch (ImsException e) { |
| 4244 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4245 | } finally { |
| 4246 | Binder.restoreCallingIdentity(identity); |
| 4247 | } |
| 4248 | } |
| 4249 | |
| 4250 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4251 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4252 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4253 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4254 | final long identity = Binder.clearCallingIdentity(); |
| 4255 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4256 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4257 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4258 | // 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] | 4259 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4260 | } catch (ImsException e) { |
| 4261 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4262 | } finally { |
| 4263 | Binder.restoreCallingIdentity(identity); |
| 4264 | } |
| 4265 | } |
| 4266 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4267 | /** |
| 4268 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4269 | * @param subId The subscription to use to check the configuration. |
| 4270 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4271 | @Override |
| 4272 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4273 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4274 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4275 | final long identity = Binder.clearCallingIdentity(); |
| 4276 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4277 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4278 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4279 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4280 | } catch (ImsException e) { |
| 4281 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4282 | } finally { |
| 4283 | Binder.restoreCallingIdentity(identity); |
| 4284 | } |
| 4285 | } |
| 4286 | |
| 4287 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4288 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4289 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4290 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4291 | final long identity = Binder.clearCallingIdentity(); |
| 4292 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4293 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4294 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4295 | // 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] | 4296 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4297 | } catch (ImsException e) { |
| 4298 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4299 | } finally { |
| 4300 | Binder.restoreCallingIdentity(identity); |
| 4301 | } |
| 4302 | } |
| 4303 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4304 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4305 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4306 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4307 | * @param subId The subscription to use to check the configuration. |
| 4308 | */ |
| 4309 | @Override |
| 4310 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4311 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4312 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 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. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4317 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4318 | } catch (ImsException e) { |
| 4319 | throw new ServiceSpecificException(e.getCode()); |
| 4320 | } finally { |
| 4321 | Binder.restoreCallingIdentity(identity); |
| 4322 | } |
| 4323 | } |
| 4324 | |
| 4325 | /** |
| 4326 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4327 | * Requires MODIFY_PHONE_STATE permission. |
| 4328 | * @param subId The subscription to use to check the configuration. |
| 4329 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4330 | * false otherwise |
| 4331 | */ |
| 4332 | @Override |
| 4333 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4334 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4335 | "setCrossSimCallingEnabled"); |
| 4336 | final long identity = Binder.clearCallingIdentity(); |
| 4337 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4338 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4339 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4340 | // 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] | 4341 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4342 | } catch (ImsException e) { |
| 4343 | throw new ServiceSpecificException(e.getCode()); |
| 4344 | } finally { |
| 4345 | Binder.restoreCallingIdentity(identity); |
| 4346 | } |
| 4347 | } |
| 4348 | |
| 4349 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4350 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4351 | * @param subId The subscription to use to check the configuration. |
| 4352 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4353 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4354 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4355 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4356 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4357 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 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. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4362 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4363 | } catch (ImsException e) { |
| 4364 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4365 | } finally { |
| 4366 | Binder.restoreCallingIdentity(identity); |
| 4367 | } |
| 4368 | } |
| 4369 | |
| 4370 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4371 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4372 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4373 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4374 | final long identity = Binder.clearCallingIdentity(); |
| 4375 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4376 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4377 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4378 | // 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] | 4379 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4380 | } catch (ImsException e) { |
| 4381 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4382 | } finally { |
| 4383 | Binder.restoreCallingIdentity(identity); |
| 4384 | } |
| 4385 | } |
| 4386 | |
| 4387 | @Override |
| 4388 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4389 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4390 | "setVoWiFiNonPersistent"); |
| 4391 | final long identity = Binder.clearCallingIdentity(); |
| 4392 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4393 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4394 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4395 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4396 | } catch (ImsException e) { |
| 4397 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4398 | } finally { |
| 4399 | Binder.restoreCallingIdentity(identity); |
| 4400 | } |
| 4401 | } |
| 4402 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4403 | /** |
| 4404 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4405 | * @param subId The subscription to use to check the configuration. |
| 4406 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4407 | @Override |
| 4408 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4409 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4410 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4411 | final long identity = Binder.clearCallingIdentity(); |
| 4412 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4413 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4414 | // 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] | 4415 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4416 | } catch (ImsException e) { |
| 4417 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4418 | } finally { |
| 4419 | Binder.restoreCallingIdentity(identity); |
| 4420 | } |
| 4421 | } |
| 4422 | |
| 4423 | @Override |
| 4424 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4425 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4426 | "setVoWiFiModeSetting"); |
| 4427 | final long identity = Binder.clearCallingIdentity(); |
| 4428 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4429 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4430 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4431 | // 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] | 4432 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4433 | } catch (ImsException e) { |
| 4434 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4435 | } finally { |
| 4436 | Binder.restoreCallingIdentity(identity); |
| 4437 | } |
| 4438 | } |
| 4439 | |
| 4440 | @Override |
| 4441 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4442 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4443 | final long identity = Binder.clearCallingIdentity(); |
| 4444 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4445 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4446 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4447 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4448 | } catch (ImsException e) { |
| 4449 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4450 | } finally { |
| 4451 | Binder.restoreCallingIdentity(identity); |
| 4452 | } |
| 4453 | } |
| 4454 | |
| 4455 | @Override |
| 4456 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4457 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4458 | "setVoWiFiRoamingModeSetting"); |
| 4459 | final long identity = Binder.clearCallingIdentity(); |
| 4460 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4461 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4462 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4463 | // new setting will be picked up when the ImsService comes up next if it isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4464 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4465 | } catch (ImsException e) { |
| 4466 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4467 | } finally { |
| 4468 | Binder.restoreCallingIdentity(identity); |
| 4469 | } |
| 4470 | } |
| 4471 | |
| 4472 | @Override |
| 4473 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4474 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4475 | "setRttCapabilityEnabled"); |
| 4476 | final long identity = Binder.clearCallingIdentity(); |
| 4477 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4478 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4479 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4480 | // 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] | 4481 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4482 | } catch (ImsException e) { |
| 4483 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4484 | } finally { |
| 4485 | Binder.restoreCallingIdentity(identity); |
| 4486 | } |
| 4487 | } |
| 4488 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4489 | /** |
| 4490 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4491 | * @param subId The subscription to use to check the configuration. |
| 4492 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4493 | @Override |
| 4494 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4495 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4496 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4497 | final long identity = Binder.clearCallingIdentity(); |
| 4498 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4499 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4500 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4501 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4502 | } catch (ImsException e) { |
| 4503 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4504 | } finally { |
| 4505 | Binder.restoreCallingIdentity(identity); |
| 4506 | } |
| 4507 | } |
| 4508 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4509 | @Override |
| 4510 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4511 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4512 | final long identity = Binder.clearCallingIdentity(); |
| 4513 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4514 | if (!isImsAvailableOnDevice()) { |
| 4515 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4516 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4517 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4518 | int slotId = getSlotIndexOrException(subId); |
| 4519 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4520 | ImsManager.getInstance(mApp, slotId) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4521 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4522 | } catch (ImsException e) { |
| 4523 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4524 | } finally { |
| 4525 | Binder.restoreCallingIdentity(identity); |
| 4526 | } |
| 4527 | } |
| 4528 | |
| 4529 | @Override |
| 4530 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4531 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4532 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4533 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4534 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4535 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4536 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4537 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4538 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4539 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4540 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4541 | + "is inactive, ignoring unregister."); |
| 4542 | // If the subscription is no longer active, just return, since the callback will already |
| 4543 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4544 | } finally { |
| 4545 | Binder.restoreCallingIdentity(identity); |
| 4546 | } |
| 4547 | } |
| 4548 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4549 | |
| 4550 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4551 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4552 | message); |
| 4553 | } |
| 4554 | |
| 4555 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4556 | boolean isMmtelCapability) { |
| 4557 | Phone phone = getPhone(subId); |
| 4558 | if (phone == null) { |
| 4559 | loge("phone instance null for subid " + subId); |
| 4560 | return false; |
| 4561 | } |
| 4562 | if (isMmtelCapability) { |
| 4563 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4564 | return false; |
| 4565 | } |
| 4566 | } else { |
| 4567 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4568 | return false; |
| 4569 | } |
| 4570 | } |
| 4571 | return true; |
| 4572 | } |
| 4573 | |
| 4574 | @Override |
| 4575 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4576 | boolean isProvisioned) { |
| 4577 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4578 | |
| 4579 | final long identity = Binder.clearCallingIdentity(); |
| 4580 | try { |
| 4581 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4582 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4583 | return; |
| 4584 | } |
| 4585 | |
| 4586 | // this capability requires provisioning, route to the correct API. |
| 4587 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4588 | switch (capability) { |
| 4589 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4590 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4591 | ims.setEabProvisioned(isProvisioned); |
| 4592 | break; |
| 4593 | default: { |
| 4594 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4595 | + "rcs capability '" + capability + "', which does not require " |
| 4596 | + "provisioning."); |
| 4597 | } |
| 4598 | } |
| 4599 | } finally { |
| 4600 | Binder.restoreCallingIdentity(identity); |
| 4601 | } |
| 4602 | |
| 4603 | } |
| 4604 | |
| 4605 | |
| 4606 | @Override |
| 4607 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4608 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4609 | final long identity = Binder.clearCallingIdentity(); |
| 4610 | try { |
| 4611 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4612 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4613 | return true; |
| 4614 | } |
| 4615 | |
| 4616 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4617 | switch (capability) { |
| 4618 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4619 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4620 | return ims.isEabProvisionedOnDevice(); |
| 4621 | |
| 4622 | default: { |
| 4623 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4624 | + "capability '" + capability + "', which does not require " |
| 4625 | + "provisioning."); |
| 4626 | } |
| 4627 | } |
| 4628 | |
| 4629 | } finally { |
| 4630 | Binder.restoreCallingIdentity(identity); |
| 4631 | } |
| 4632 | } |
| 4633 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4634 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4635 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4636 | boolean isProvisioned) { |
| 4637 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4638 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE |
| 4639 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4640 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4641 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4642 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4643 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4644 | final long identity = Binder.clearCallingIdentity(); |
| 4645 | try { |
| 4646 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4647 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4648 | return; |
| 4649 | } |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4650 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4651 | || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
| 4652 | loge("setImsProvisioningStatusForCapability: called for technology that does " |
| 4653 | + "not support provisioning - " + tech); |
| 4654 | return; |
| 4655 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4656 | |
| 4657 | // this capability requires provisioning, route to the correct API. |
| 4658 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4659 | switch (capability) { |
| 4660 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4661 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4662 | ims.setVolteProvisioned(isProvisioned); |
| 4663 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4664 | ims.setWfcProvisioned(isProvisioned); |
| 4665 | } |
| 4666 | break; |
| 4667 | } |
| 4668 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4669 | // There is currently no difference in VT provisioning type. |
| 4670 | ims.setVtProvisioned(isProvisioned); |
| 4671 | break; |
| 4672 | } |
| 4673 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4674 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4675 | // change the capability of the feature instead if needed. |
| 4676 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4677 | == isProvisioned) { |
| 4678 | // No change in provisioning. |
| 4679 | return; |
| 4680 | } |
| 4681 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4682 | try { |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4683 | ims.changeMmTelCapability(isProvisioned, capability, tech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4684 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4685 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4686 | + ", Exception" + e.getMessage()); |
| 4687 | } |
| 4688 | break; |
| 4689 | } |
| 4690 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4691 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4692 | + "MmTel capability '" + capability + "', which does not require " |
| 4693 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4694 | } |
| 4695 | } |
| 4696 | |
| 4697 | } finally { |
| 4698 | Binder.restoreCallingIdentity(identity); |
| 4699 | } |
| 4700 | } |
| 4701 | |
| 4702 | @Override |
| 4703 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4704 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4705 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE |
| 4706 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4707 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4708 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4709 | } |
| 4710 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4711 | final long identity = Binder.clearCallingIdentity(); |
| 4712 | try { |
| 4713 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4714 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4715 | return true; |
| 4716 | } |
| 4717 | |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4718 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4719 | || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
| 4720 | loge("getImsProvisioningStatusForCapability: called for technology that does " |
| 4721 | + "not support provisioning - " + tech); |
| 4722 | return true; |
| 4723 | } |
| 4724 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4725 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4726 | switch (capability) { |
| 4727 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4728 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4729 | return ims.isVolteProvisionedOnDevice(); |
| 4730 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4731 | return ims.isWfcProvisionedOnDevice(); |
| 4732 | } |
| 4733 | // This should never happen, since we are checking tech above to make sure it |
| 4734 | // is either LTE or IWLAN. |
| 4735 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4736 | + "capability."); |
| 4737 | } |
| 4738 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4739 | // There is currently no difference in VT provisioning type. |
| 4740 | return ims.isVtProvisionedOnDevice(); |
| 4741 | } |
| 4742 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4743 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4744 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4745 | } |
| 4746 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4747 | throw new IllegalArgumentException( |
| 4748 | "Tried to get provisioning for MmTel capability '" + capability |
| 4749 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4750 | } |
| 4751 | } |
| 4752 | |
| 4753 | } finally { |
| 4754 | Binder.restoreCallingIdentity(identity); |
| 4755 | } |
| 4756 | } |
| 4757 | |
| 4758 | @Override |
| 4759 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4760 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4761 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4762 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4763 | } |
| 4764 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4765 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4766 | return (provisionedBits & capability) > 0; |
| 4767 | } |
| 4768 | |
| 4769 | @Override |
| 4770 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4771 | boolean isProvisioned) { |
| 4772 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4773 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4774 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4775 | } |
| 4776 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4777 | "setProvisioningStatusForCapability"); |
| 4778 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4779 | // If the current provisioning status for capability already matches isProvisioned, |
| 4780 | // do nothing. |
| 4781 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4782 | return; |
| 4783 | } |
| 4784 | if (isProvisioned) { |
| 4785 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4786 | } else { |
| 4787 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4788 | } |
| 4789 | } |
| 4790 | |
| 4791 | /** |
| 4792 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4793 | * technology. The bitfield should mirror the bitfield defined by |
| 4794 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4795 | */ |
| 4796 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4797 | String key = getMmTelProvisioningKey(subId, tech); |
| 4798 | // Default is no capabilities are provisioned. |
| 4799 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4800 | } |
| 4801 | |
| 4802 | /** |
| 4803 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4804 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4805 | * technology specified. |
| 4806 | * |
| 4807 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4808 | */ |
| 4809 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4810 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4811 | String key = getMmTelProvisioningKey(subId, tech); |
| 4812 | editor.putInt(key, newField); |
| 4813 | editor.commit(); |
| 4814 | } |
| 4815 | |
| 4816 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4817 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4818 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4819 | } |
| 4820 | |
| 4821 | /** |
| 4822 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4823 | * carrier associated with the subscription id. |
| 4824 | */ |
| 4825 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4826 | int capability) { |
| 4827 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4828 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4829 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4830 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4831 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4832 | false); |
| 4833 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4834 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4835 | |
| 4836 | // First check to make sure that the capability requires provisioning. |
| 4837 | switch (capability) { |
| 4838 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4839 | // intentional fallthrough |
| 4840 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4841 | if (requireVoiceVtProvisioning) { |
| 4842 | // Voice and Video requires provisioning |
| 4843 | return true; |
| 4844 | } |
| 4845 | break; |
| 4846 | } |
| 4847 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4848 | if (requireUtProvisioning) { |
| 4849 | // UT requires provisioning |
| 4850 | return true; |
| 4851 | } |
| 4852 | break; |
| 4853 | } |
| 4854 | } |
| 4855 | return false; |
| 4856 | } |
| 4857 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4858 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4859 | int capability) { |
| 4860 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4861 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4862 | |
| 4863 | boolean requireRcsProvisioning = c.getBoolean( |
| 4864 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4865 | |
| 4866 | // First check to make sure that the capability requires provisioning. |
| 4867 | switch (capability) { |
| 4868 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4869 | // intentional fallthrough |
| 4870 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4871 | if (requireRcsProvisioning) { |
| 4872 | // OPTION or PRESENCE requires provisioning |
| 4873 | return true; |
| 4874 | } |
| 4875 | break; |
| 4876 | } |
| 4877 | } |
| 4878 | return false; |
| 4879 | } |
| 4880 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4881 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4882 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4883 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4884 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4885 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4886 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4887 | final long identity = Binder.clearCallingIdentity(); |
| 4888 | try { |
| 4889 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4890 | int slotId = getSlotIndex(subId); |
| 4891 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4892 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4893 | + subId + "' for key:" + key); |
| 4894 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4895 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4896 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4897 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4898 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4899 | + subId + "' for key:" + key); |
| 4900 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4901 | } finally { |
| 4902 | Binder.restoreCallingIdentity(identity); |
| 4903 | } |
| 4904 | } |
| 4905 | |
| 4906 | @Override |
| 4907 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4908 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4909 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4910 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4911 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4912 | final long identity = Binder.clearCallingIdentity(); |
| 4913 | try { |
| 4914 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4915 | int slotId = getSlotIndex(subId); |
| 4916 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4917 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4918 | + subId + "' for key:" + key); |
| 4919 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4920 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4921 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4922 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4923 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4924 | + subId + "' for key:" + key); |
| 4925 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4926 | } finally { |
| 4927 | Binder.restoreCallingIdentity(identity); |
| 4928 | } |
| 4929 | } |
| 4930 | |
| 4931 | @Override |
| 4932 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4933 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4934 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4935 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4936 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4937 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4938 | final long identity = Binder.clearCallingIdentity(); |
| 4939 | try { |
| 4940 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4941 | int slotId = getSlotIndex(subId); |
| 4942 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4943 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4944 | + subId + "' for key:" + key); |
| 4945 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4946 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4947 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4948 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4949 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4950 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4951 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4952 | } finally { |
| 4953 | Binder.restoreCallingIdentity(identity); |
| 4954 | } |
| 4955 | } |
| 4956 | |
| 4957 | @Override |
| 4958 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4959 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4960 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4961 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4962 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4963 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4964 | final long identity = Binder.clearCallingIdentity(); |
| 4965 | try { |
| 4966 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4967 | int slotId = getSlotIndex(subId); |
| 4968 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4969 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4970 | + subId + "' for key:" + key); |
| 4971 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4972 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4973 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4974 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4975 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4976 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4977 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4978 | } finally { |
| 4979 | Binder.restoreCallingIdentity(identity); |
| 4980 | } |
| 4981 | } |
| 4982 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4983 | /** |
| 4984 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 4985 | * for the given slot ID or no ImsResolver instance has been created. |
| 4986 | * @param slotId The slot ID that the IMS service is created for. |
| 4987 | * @throws ImsException If there is no ImsService configured for this slot. |
| 4988 | */ |
| 4989 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 4990 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 4991 | ImsFeature.FEATURE_MMTEL)) { |
| 4992 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 4993 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4994 | } |
| 4995 | } |
| 4996 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4997 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4998 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4999 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5000 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5001 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5002 | } |
| 5003 | return slotId; |
| 5004 | } |
| 5005 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5006 | private int getSlotIndex(int subId) { |
| 5007 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5008 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5009 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5010 | } |
| 5011 | return slotId; |
| 5012 | } |
| 5013 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5014 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5015 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5016 | */ |
| 5017 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5018 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5019 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5020 | try { |
| 5021 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5022 | } catch (SecurityException se) { |
| 5023 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5024 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5025 | + Binder.getCallingUid()); |
| 5026 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5027 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5028 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5029 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5030 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5031 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5032 | mApp, subId, callingPackage, callingFeatureId, |
| 5033 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5034 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5035 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5036 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5037 | final long identity = Binder.clearCallingIdentity(); |
| 5038 | try { |
| 5039 | final Phone phone = getPhone(subId); |
| 5040 | if (phone != null) { |
| 5041 | return phone.getServiceState().getDataNetworkType(); |
| 5042 | } else { |
| 5043 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5044 | } |
| 5045 | } finally { |
| 5046 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5047 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5048 | } |
| 5049 | |
| 5050 | /** |
| 5051 | * Returns the data network type |
| 5052 | */ |
| 5053 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5054 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5055 | return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(), |
| 5056 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5057 | } |
| 5058 | |
| 5059 | /** |
| 5060 | * Returns the data network type for a subId |
| 5061 | */ |
| 5062 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5063 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5064 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5065 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5066 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5067 | mApp, functionName)) { |
| 5068 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5069 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5070 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5071 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5072 | } |
| 5073 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5074 | final long identity = Binder.clearCallingIdentity(); |
| 5075 | try { |
| 5076 | final Phone phone = getPhone(subId); |
| 5077 | if (phone != null) { |
| 5078 | return phone.getServiceState().getDataNetworkType(); |
| 5079 | } else { |
| 5080 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5081 | } |
| 5082 | } finally { |
| 5083 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5084 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5085 | } |
| 5086 | |
| 5087 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5088 | * Returns the Voice network type for a subId |
| 5089 | */ |
| 5090 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5091 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5092 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5093 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5094 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5095 | mApp, functionName)) { |
| 5096 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5097 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5098 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5099 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5100 | } |
| 5101 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5102 | final long identity = Binder.clearCallingIdentity(); |
| 5103 | try { |
| 5104 | final Phone phone = getPhone(subId); |
| 5105 | if (phone != null) { |
| 5106 | return phone.getServiceState().getVoiceNetworkType(); |
| 5107 | } else { |
| 5108 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5109 | } |
| 5110 | } finally { |
| 5111 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5112 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5113 | } |
| 5114 | |
| 5115 | /** |
| 5116 | * @return true if a ICC card is present |
| 5117 | */ |
| 5118 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5119 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5120 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 5121 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5122 | } |
| 5123 | |
| 5124 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5125 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5126 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5127 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5128 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5129 | final long identity = Binder.clearCallingIdentity(); |
| 5130 | try { |
| 5131 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5132 | if (phone != null) { |
| 5133 | return phone.getIccCard().hasIccCard(); |
| 5134 | } else { |
| 5135 | return false; |
| 5136 | } |
| 5137 | } finally { |
| 5138 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5139 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5140 | } |
| 5141 | |
| 5142 | /** |
| 5143 | * Return if the current radio is LTE on CDMA. This |
| 5144 | * is a tri-state return value as for a period of time |
| 5145 | * the mode may be unknown. |
| 5146 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5147 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5148 | * @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] | 5149 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5150 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5151 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5152 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5153 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5154 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5155 | } |
| 5156 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5157 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5158 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5159 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5160 | try { |
| 5161 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5162 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5163 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5164 | } |
| 5165 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5166 | final long identity = Binder.clearCallingIdentity(); |
| 5167 | try { |
| 5168 | final Phone phone = getPhone(subId); |
| 5169 | if (phone == null) { |
| 5170 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5171 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5172 | return TelephonyProperties.lte_on_cdma_device() |
| 5173 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5174 | } |
| 5175 | } finally { |
| 5176 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5177 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5178 | } |
| 5179 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5180 | /** |
| 5181 | * {@hide} |
| 5182 | * Returns Default subId, 0 in the case of single standby. |
| 5183 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5184 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5185 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5186 | } |
| 5187 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5188 | private int getSlotForDefaultSubscription() { |
| 5189 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 5190 | } |
| 5191 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5192 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5193 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5194 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5195 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5196 | private boolean isActiveSubscription(int subId) { |
| 5197 | return mSubscriptionController.isActiveSubId(subId); |
| 5198 | } |
| 5199 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5200 | /** |
| 5201 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5202 | */ |
| 5203 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5204 | final long identity = Binder.clearCallingIdentity(); |
| 5205 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5206 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5207 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5208 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5209 | } finally { |
| 5210 | Binder.restoreCallingIdentity(identity); |
| 5211 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5212 | } |
| 5213 | |
| 5214 | /** |
| 5215 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5216 | */ |
| 5217 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5218 | final long identity = Binder.clearCallingIdentity(); |
| 5219 | try { |
| 5220 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5221 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5222 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5223 | } finally { |
| 5224 | Binder.restoreCallingIdentity(identity); |
| 5225 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5226 | } |
| 5227 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5228 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5229 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5230 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5231 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5232 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5233 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 5234 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 5235 | if (phoneId == -1) { |
| 5236 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 5237 | + " does not correspond to an active phone"); |
| 5238 | } |
| 5239 | return PhoneFactory.getPhone(phoneId); |
| 5240 | } |
| 5241 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5242 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5243 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 5244 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5245 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5246 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5247 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5248 | if (DBG) { |
| 5249 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 5250 | } |
| 5251 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 5252 | p2); |
| 5253 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5254 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5255 | |
| 5256 | @Override |
| 5257 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 5258 | int slotIndex, String callingPackage, String aid, int p2) { |
| 5259 | enforceModifyPermission(); |
| 5260 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5261 | if (DBG) { |
| 5262 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 5263 | } |
| 5264 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 5265 | callingPackage, aid, p2); |
| 5266 | } |
| 5267 | |
| 5268 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 5269 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5270 | final long identity = Binder.clearCallingIdentity(); |
| 5271 | try { |
| 5272 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 5273 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5274 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5275 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5276 | if (bestComponent == null |
| 5277 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5278 | loge("The calling package is not allowed to access ISD-R."); |
| 5279 | throw new SecurityException( |
| 5280 | "The calling package is not allowed to access ISD-R."); |
| 5281 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5282 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5283 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5284 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5285 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 5286 | null /* workSource */); |
| 5287 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5288 | return response; |
| 5289 | } finally { |
| 5290 | Binder.restoreCallingIdentity(identity); |
| 5291 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5292 | } |
| 5293 | |
| 5294 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5295 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5296 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5297 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5298 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 5299 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 5300 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5301 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5302 | @Override |
| 5303 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 5304 | enforceModifyPermission(); |
| 5305 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 5306 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 5307 | channel); |
| 5308 | } |
| 5309 | |
| 5310 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5311 | final long identity = Binder.clearCallingIdentity(); |
| 5312 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5313 | if (channel < 0) { |
| 5314 | return false; |
| 5315 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5316 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 5317 | null /* workSource */); |
| 5318 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5319 | return success; |
| 5320 | } finally { |
| 5321 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5322 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5323 | } |
| 5324 | |
| 5325 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5326 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5327 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5328 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5329 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5330 | if (DBG) { |
| 5331 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5332 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5333 | + p3 + " data=" + data); |
| 5334 | } |
| 5335 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5336 | command, p1, p2, p3, data); |
| 5337 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5338 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5339 | @Override |
| 5340 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 5341 | int command, int p1, int p2, int p3, String data) { |
| 5342 | enforceModifyPermission(); |
| 5343 | if (DBG) { |
| 5344 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 5345 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5346 | + p3 + " data=" + data); |
| 5347 | } |
| 5348 | return iccTransmitApduLogicalChannelWithPermission( |
| 5349 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 5350 | data); |
| 5351 | } |
| 5352 | |
| 5353 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5354 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5355 | final long identity = Binder.clearCallingIdentity(); |
| 5356 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5357 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5358 | return ""; |
| 5359 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5360 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5361 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5362 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5363 | null /* workSource */); |
| 5364 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5365 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5366 | // Append the returned status code to the end of the response payload. |
| 5367 | String s = Integer.toHexString( |
| 5368 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5369 | if (response.payload != null) { |
| 5370 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5371 | } |
| 5372 | return s; |
| 5373 | } finally { |
| 5374 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5375 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5376 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5377 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5378 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5379 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5380 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5381 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5382 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5383 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5384 | if (DBG) { |
| 5385 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5386 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5387 | } |
| 5388 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5389 | cla, command, p1, p2, p3, data); |
| 5390 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5391 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5392 | @Override |
| 5393 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 5394 | int command, int p1, int p2, int p3, String data) { |
| 5395 | enforceModifyPermission(); |
| 5396 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5397 | if (DBG) { |
| 5398 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 5399 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 5400 | + " data=" + data); |
| 5401 | } |
| 5402 | |
| 5403 | return iccTransmitApduBasicChannelWithPermission( |
| 5404 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 5405 | p2, p3, data); |
| 5406 | } |
| 5407 | |
| 5408 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5409 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5410 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5411 | final long identity = Binder.clearCallingIdentity(); |
| 5412 | try { |
| 5413 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5414 | && TextUtils.equals(ISDR_AID, data)) { |
| 5415 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5416 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5417 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5418 | if (bestComponent == null |
| 5419 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5420 | loge("The calling package is not allowed to select ISD-R."); |
| 5421 | throw new SecurityException( |
| 5422 | "The calling package is not allowed to select ISD-R."); |
| 5423 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5424 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5425 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5426 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5427 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5428 | null /* workSource */); |
| 5429 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5430 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5431 | // Append the returned status code to the end of the response payload. |
| 5432 | String s = Integer.toHexString( |
| 5433 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5434 | if (response.payload != null) { |
| 5435 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5436 | } |
| 5437 | return s; |
| 5438 | } finally { |
| 5439 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5440 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5441 | } |
| 5442 | |
| 5443 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5444 | 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] | 5445 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5446 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5447 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5448 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5449 | final long identity = Binder.clearCallingIdentity(); |
| 5450 | try { |
| 5451 | if (DBG) { |
| 5452 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5453 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5454 | } |
| 5455 | |
| 5456 | IccIoResult response = |
| 5457 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5458 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5459 | subId); |
| 5460 | |
| 5461 | if (DBG) { |
| 5462 | log("Exchange SIM_IO [R]" + response); |
| 5463 | } |
| 5464 | |
| 5465 | byte[] result = null; |
| 5466 | int length = 2; |
| 5467 | if (response.payload != null) { |
| 5468 | length = 2 + response.payload.length; |
| 5469 | result = new byte[length]; |
| 5470 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5471 | } else { |
| 5472 | result = new byte[length]; |
| 5473 | } |
| 5474 | |
| 5475 | result[length - 1] = (byte) response.sw2; |
| 5476 | result[length - 2] = (byte) response.sw1; |
| 5477 | return result; |
| 5478 | } finally { |
| 5479 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5480 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5481 | } |
| 5482 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5483 | /** |
| 5484 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5485 | * on a particular subscription |
| 5486 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5487 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5488 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5489 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5490 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5491 | return null; |
| 5492 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5493 | |
| 5494 | final long identity = Binder.clearCallingIdentity(); |
| 5495 | try { |
| 5496 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5497 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5498 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5499 | return null; |
| 5500 | } |
| 5501 | Object response = sendRequest( |
| 5502 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5503 | if (response instanceof String[]) { |
| 5504 | return (String[]) response; |
| 5505 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5506 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5507 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5508 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5509 | } finally { |
| 5510 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5511 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5512 | } |
| 5513 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5514 | /** |
| 5515 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5516 | * subscription. |
| 5517 | * |
| 5518 | * @param subId the id of the subscription. |
| 5519 | * @param appType the uicc app type, must be USIM or SIM. |
| 5520 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5521 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5522 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5523 | * @return number of fplmns that is successfully written to the SIM. |
| 5524 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5525 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5526 | String callingFeatureId) { |
| 5527 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5528 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5529 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5530 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5531 | } |
| 5532 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5533 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5534 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5535 | } |
| 5536 | if (fplmns == null) { |
| 5537 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5538 | } |
| 5539 | for (String fplmn : fplmns) { |
| 5540 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5541 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5542 | } |
| 5543 | } |
| 5544 | final long identity = Binder.clearCallingIdentity(); |
| 5545 | try { |
| 5546 | Object response = sendRequest( |
| 5547 | CMD_SET_FORBIDDEN_PLMNS, |
| 5548 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5549 | subId); |
| 5550 | return (int) response; |
| 5551 | } finally { |
| 5552 | Binder.restoreCallingIdentity(identity); |
| 5553 | } |
| 5554 | } |
| 5555 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5556 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5557 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5558 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5559 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5560 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5561 | final long identity = Binder.clearCallingIdentity(); |
| 5562 | try { |
| 5563 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5564 | if (response.payload == null) { |
| 5565 | return ""; |
| 5566 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5567 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5568 | // Append the returned status code to the end of the response payload. |
| 5569 | String s = Integer.toHexString( |
| 5570 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5571 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5572 | return s; |
| 5573 | } finally { |
| 5574 | Binder.restoreCallingIdentity(identity); |
| 5575 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5576 | } |
| 5577 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5578 | /** |
| 5579 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5580 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5581 | * |
| 5582 | * @param itemID the ID of the item to read |
| 5583 | * @return the NV item as a String, or null on error. |
| 5584 | */ |
| 5585 | @Override |
| 5586 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5587 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5588 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5589 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5590 | |
| 5591 | final long identity = Binder.clearCallingIdentity(); |
| 5592 | try { |
| 5593 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5594 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5595 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5596 | return value; |
| 5597 | } finally { |
| 5598 | Binder.restoreCallingIdentity(identity); |
| 5599 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5600 | } |
| 5601 | |
| 5602 | /** |
| 5603 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5604 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5605 | * |
| 5606 | * @param itemID the ID of the item to read |
| 5607 | * @param itemValue the value to write, as a String |
| 5608 | * @return true on success; false on any failure |
| 5609 | */ |
| 5610 | @Override |
| 5611 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5612 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5613 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5614 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5615 | |
| 5616 | final long identity = Binder.clearCallingIdentity(); |
| 5617 | try { |
| 5618 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5619 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5620 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5621 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5622 | return success; |
| 5623 | } finally { |
| 5624 | Binder.restoreCallingIdentity(identity); |
| 5625 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5626 | } |
| 5627 | |
| 5628 | /** |
| 5629 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5630 | * Used for device configuration by some CDMA operators. |
| 5631 | * |
| 5632 | * @param preferredRoamingList byte array containing the new PRL |
| 5633 | * @return true on success; false on any failure |
| 5634 | */ |
| 5635 | @Override |
| 5636 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5637 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5638 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5639 | |
| 5640 | final long identity = Binder.clearCallingIdentity(); |
| 5641 | try { |
| 5642 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5643 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5644 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5645 | return success; |
| 5646 | } finally { |
| 5647 | Binder.restoreCallingIdentity(identity); |
| 5648 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5649 | } |
| 5650 | |
| 5651 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5652 | * 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] | 5653 | * Used for device configuration by some CDMA operators. |
| 5654 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5655 | * @param slotIndex - device slot. |
| 5656 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5657 | * @return true on success; false on any failure |
| 5658 | */ |
| 5659 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5660 | public boolean resetModemConfig(int slotIndex) { |
| 5661 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5662 | if (phone != null) { |
| 5663 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5664 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5665 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5666 | final long identity = Binder.clearCallingIdentity(); |
| 5667 | try { |
| 5668 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5669 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5670 | return success; |
| 5671 | } finally { |
| 5672 | Binder.restoreCallingIdentity(identity); |
| 5673 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5674 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5675 | return false; |
| 5676 | } |
| 5677 | |
| 5678 | /** |
| 5679 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5680 | * |
| 5681 | * @param slotIndex - device slot. |
| 5682 | * |
| 5683 | * @return true on success; false on any failure |
| 5684 | */ |
| 5685 | @Override |
| 5686 | public boolean rebootModem(int slotIndex) { |
| 5687 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5688 | if (phone != null) { |
| 5689 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5690 | mApp, phone.getSubId(), "rebootModem"); |
| 5691 | |
| 5692 | final long identity = Binder.clearCallingIdentity(); |
| 5693 | try { |
| 5694 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5695 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5696 | return success; |
| 5697 | } finally { |
| 5698 | Binder.restoreCallingIdentity(identity); |
| 5699 | } |
| 5700 | } |
| 5701 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5702 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5703 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5704 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5705 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5706 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5707 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5708 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5709 | return new String[0]; |
| 5710 | } |
| 5711 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5712 | final long identity = Binder.clearCallingIdentity(); |
| 5713 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5714 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5715 | } finally { |
| 5716 | Binder.restoreCallingIdentity(identity); |
| 5717 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5718 | } |
| 5719 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5720 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5721 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5722 | * {@link #disableIms(int)}. |
| 5723 | * @param slotIndex device slot. |
| 5724 | */ |
| 5725 | public void resetIms(int slotIndex) { |
| 5726 | enforceModifyPermission(); |
| 5727 | |
| 5728 | final long identity = Binder.clearCallingIdentity(); |
| 5729 | try { |
| 5730 | if (mImsResolver == null) { |
| 5731 | // may happen if the does not support IMS. |
| 5732 | return; |
| 5733 | } |
| 5734 | mImsResolver.disableIms(slotIndex); |
| 5735 | mImsResolver.enableIms(slotIndex); |
| 5736 | } finally { |
| 5737 | Binder.restoreCallingIdentity(identity); |
| 5738 | } |
| 5739 | } |
| 5740 | |
| 5741 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5742 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5743 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5744 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5745 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5746 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5747 | |
| 5748 | final long identity = Binder.clearCallingIdentity(); |
| 5749 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5750 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5751 | // may happen if the device does not support IMS. |
| 5752 | return; |
| 5753 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5754 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5755 | } finally { |
| 5756 | Binder.restoreCallingIdentity(identity); |
| 5757 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5758 | } |
| 5759 | |
| 5760 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5761 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5762 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5763 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5764 | public void disableIms(int slotId) { |
| 5765 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5766 | |
| 5767 | final long identity = Binder.clearCallingIdentity(); |
| 5768 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5769 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5770 | // may happen if the device does not support IMS. |
| 5771 | return; |
| 5772 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5773 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5774 | } finally { |
| 5775 | Binder.restoreCallingIdentity(identity); |
| 5776 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5777 | } |
| 5778 | |
| 5779 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5780 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5781 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5782 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5783 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5784 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5785 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5786 | |
| 5787 | final long identity = Binder.clearCallingIdentity(); |
| 5788 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5789 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5790 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5791 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5792 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5793 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5794 | } finally { |
| 5795 | Binder.restoreCallingIdentity(identity); |
| 5796 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5797 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5798 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5799 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5800 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5801 | @Override |
| 5802 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5803 | enforceModifyPermission(); |
| 5804 | |
| 5805 | final long identity = Binder.clearCallingIdentity(); |
| 5806 | try { |
| 5807 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5808 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5809 | } finally { |
| 5810 | Binder.restoreCallingIdentity(identity); |
| 5811 | } |
| 5812 | } |
| 5813 | |
| 5814 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5815 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5816 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5817 | */ |
| 5818 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5819 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5820 | |
| 5821 | final long identity = Binder.clearCallingIdentity(); |
| 5822 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5823 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5824 | // may happen if the device does not support IMS. |
| 5825 | return null; |
| 5826 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5827 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5828 | } finally { |
| 5829 | Binder.restoreCallingIdentity(identity); |
| 5830 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5831 | } |
| 5832 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5833 | /** |
| 5834 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5835 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5836 | */ |
| 5837 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5838 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5839 | |
| 5840 | final long identity = Binder.clearCallingIdentity(); |
| 5841 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5842 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5843 | // may happen if the device does not support IMS. |
| 5844 | return null; |
| 5845 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5846 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5847 | } finally { |
| 5848 | Binder.restoreCallingIdentity(identity); |
| 5849 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5850 | } |
| 5851 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5852 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5853 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5854 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5855 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5856 | * @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] | 5857 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5858 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5859 | * @param packageName The name of the package that the current configuration will be replaced |
| 5860 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5861 | * @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] | 5862 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5863 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5864 | int[] featureTypes, String packageName) { |
| 5865 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5866 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5867 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5868 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5869 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5870 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5871 | final long identity = Binder.clearCallingIdentity(); |
| 5872 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5873 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5874 | // may happen if the device does not support IMS. |
| 5875 | return false; |
| 5876 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5877 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5878 | for (int featureType : featureTypes) { |
| 5879 | featureConfig.put(featureType, packageName); |
| 5880 | } |
| 5881 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5882 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5883 | } finally { |
| 5884 | Binder.restoreCallingIdentity(identity); |
| 5885 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5886 | } |
| 5887 | |
| 5888 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5889 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5890 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5891 | * |
| 5892 | * This should only be used for testing. |
| 5893 | * |
| 5894 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5895 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5896 | */ |
| 5897 | @Override |
| 5898 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5899 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5900 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5901 | "clearCarrierImsServiceOverride"); |
| 5902 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5903 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5904 | "clearCarrierImsServiceOverride"); |
| 5905 | |
| 5906 | final long identity = Binder.clearCallingIdentity(); |
| 5907 | try { |
| 5908 | if (mImsResolver == null) { |
| 5909 | // may happen if the device does not support IMS. |
| 5910 | return false; |
| 5911 | } |
| 5912 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5913 | } finally { |
| 5914 | Binder.restoreCallingIdentity(identity); |
| 5915 | } |
| 5916 | } |
| 5917 | |
| 5918 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5919 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5920 | * |
| 5921 | * @param slotId The slot that the ImsService is associated with. |
| 5922 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5923 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5924 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5925 | * @return the package name of the ImsService configuration. |
| 5926 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5927 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5928 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5929 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5930 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5931 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5932 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5933 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5934 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5935 | final long identity = Binder.clearCallingIdentity(); |
| 5936 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5937 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5938 | // may happen if the device does not support IMS. |
| 5939 | return ""; |
| 5940 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5941 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5942 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5943 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5944 | } finally { |
| 5945 | Binder.restoreCallingIdentity(identity); |
| 5946 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5947 | } |
| 5948 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5949 | /** |
| 5950 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5951 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5952 | * @param callback A callback with an integer containing the |
| 5953 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5954 | */ |
| 5955 | @Override |
| 5956 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5957 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5958 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5959 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5960 | "IMS not available on device."); |
| 5961 | } |
| 5962 | final long token = Binder.clearCallingIdentity(); |
| 5963 | try { |
| 5964 | int slotId = getSlotIndex(subId); |
| 5965 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5966 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5967 | + subId + "'"); |
| 5968 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5969 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5970 | verifyImsMmTelConfiguredOrThrow(slotId); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5971 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5972 | try { |
| 5973 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5974 | } catch (RemoteException e) { |
| 5975 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5976 | + "Ignore"); |
| 5977 | } |
| 5978 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5979 | } catch (ImsException e) { |
| 5980 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5981 | } finally { |
| 5982 | Binder.restoreCallingIdentity(token); |
| 5983 | } |
| 5984 | } |
| 5985 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5986 | /** |
| 5987 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5988 | */ |
| 5989 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5990 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5991 | |
| 5992 | final long identity = Binder.clearCallingIdentity(); |
| 5993 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5994 | // NOTE: Before S, this method only set the default phone. |
| 5995 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5996 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5997 | phone.setImsRegistrationState(registered); |
| 5998 | } |
| 5999 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6000 | } finally { |
| 6001 | Binder.restoreCallingIdentity(identity); |
| 6002 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6003 | } |
| 6004 | |
| 6005 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6006 | * Set the network selection mode to automatic. |
| 6007 | * |
| 6008 | */ |
| 6009 | @Override |
| 6010 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6011 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6012 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6013 | |
| 6014 | final long identity = Binder.clearCallingIdentity(); |
| 6015 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6016 | if (!isActiveSubscription(subId)) { |
| 6017 | return; |
| 6018 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6019 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6020 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6021 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6022 | } finally { |
| 6023 | Binder.restoreCallingIdentity(identity); |
| 6024 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6025 | } |
| 6026 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6027 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6028 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6029 | * |
| 6030 | * @param subId the id of the subscription. |
| 6031 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6032 | * the operator to attach to. |
| 6033 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6034 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6035 | * normal network selection next time. |
| 6036 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6037 | */ |
| 6038 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6039 | public boolean setNetworkSelectionModeManual( |
| 6040 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6041 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6042 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6043 | |
| 6044 | if (!isActiveSubscription(subId)) { |
| 6045 | return false; |
| 6046 | } |
| 6047 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6048 | final long identity = Binder.clearCallingIdentity(); |
| 6049 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6050 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6051 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6052 | if (DBG) { |
| 6053 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6054 | + " operator: " + operatorInfo); |
| 6055 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6056 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6057 | } finally { |
| 6058 | Binder.restoreCallingIdentity(identity); |
| 6059 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6060 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6061 | /** |
| 6062 | * Get the manual network selection |
| 6063 | * |
| 6064 | * @param subId the id of the subscription. |
| 6065 | * |
| 6066 | * @return the previously saved user selected PLMN |
| 6067 | */ |
| 6068 | @Override |
| 6069 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6070 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6071 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6072 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 6073 | |
| 6074 | final long identity = Binder.clearCallingIdentity(); |
| 6075 | try { |
| 6076 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6077 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6078 | } |
| 6079 | |
| 6080 | final Phone phone = getPhone(subId); |
| 6081 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6082 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6083 | } |
| 6084 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6085 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6086 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6087 | } finally { |
| 6088 | Binder.restoreCallingIdentity(identity); |
| 6089 | } |
| 6090 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6091 | |
| 6092 | /** |
| 6093 | * Scans for available networks. |
| 6094 | */ |
| 6095 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6096 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6097 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6098 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6099 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6100 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6101 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6102 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6103 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6104 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6105 | .setCallingPid(Binder.getCallingPid()) |
| 6106 | .setCallingUid(Binder.getCallingUid()) |
| 6107 | .setMethod("getCellNetworkScanResults") |
| 6108 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6109 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6110 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6111 | .build()); |
| 6112 | switch (locationResult) { |
| 6113 | case DENIED_HARD: |
| 6114 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6115 | case DENIED_SOFT: |
| 6116 | return null; |
| 6117 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6118 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6119 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6120 | try { |
| 6121 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6122 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6123 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6124 | } finally { |
| 6125 | Binder.restoreCallingIdentity(identity); |
| 6126 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6127 | } |
| 6128 | |
| 6129 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6130 | * Get the call forwarding info, given the call forwarding reason. |
| 6131 | */ |
| 6132 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6133 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6134 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6135 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6136 | long identity = Binder.clearCallingIdentity(); |
| 6137 | try { |
| 6138 | if (DBG) { |
| 6139 | log("getCallForwarding: subId " + subId |
| 6140 | + " callForwardingReason" + callForwardingReason); |
| 6141 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6142 | |
| 6143 | Phone phone = getPhone(subId); |
| 6144 | if (phone == null) { |
| 6145 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6146 | callback.onError( |
| 6147 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6148 | } catch (RemoteException e) { |
| 6149 | // ignore |
| 6150 | } |
| 6151 | return; |
| 6152 | } |
| 6153 | |
| 6154 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6155 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6156 | @Override |
| 6157 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6158 | try { |
| 6159 | callback.onCallForwardingInfoAvailable(info); |
| 6160 | } catch (RemoteException e) { |
| 6161 | // ignore |
| 6162 | } |
| 6163 | } |
| 6164 | |
| 6165 | @Override |
| 6166 | public void onError(int error) { |
| 6167 | try { |
| 6168 | callback.onError(error); |
| 6169 | } catch (RemoteException e) { |
| 6170 | // ignore |
| 6171 | } |
| 6172 | } |
| 6173 | }); |
| 6174 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6175 | } finally { |
| 6176 | Binder.restoreCallingIdentity(identity); |
| 6177 | } |
| 6178 | } |
| 6179 | |
| 6180 | /** |
| 6181 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6182 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6183 | */ |
| 6184 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6185 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6186 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6187 | enforceModifyPermission(); |
| 6188 | long identity = Binder.clearCallingIdentity(); |
| 6189 | try { |
| 6190 | if (DBG) { |
| 6191 | log("setCallForwarding: subId " + subId |
| 6192 | + " callForwardingInfo" + callForwardingInfo); |
| 6193 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6194 | |
| 6195 | Phone phone = getPhone(subId); |
| 6196 | if (phone == null) { |
| 6197 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6198 | callback.accept( |
| 6199 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6200 | } catch (RemoteException e) { |
| 6201 | // ignore |
| 6202 | } |
| 6203 | return; |
| 6204 | } |
| 6205 | |
| 6206 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6207 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6208 | |
| 6209 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6210 | } finally { |
| 6211 | Binder.restoreCallingIdentity(identity); |
| 6212 | } |
| 6213 | } |
| 6214 | |
| 6215 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6216 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6217 | */ |
| 6218 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6219 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6220 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6221 | long identity = Binder.clearCallingIdentity(); |
| 6222 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6223 | Phone phone = getPhone(subId); |
| 6224 | if (phone == null) { |
| 6225 | try { |
| 6226 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6227 | } catch (RemoteException e) { |
| 6228 | // ignore |
| 6229 | } |
| 6230 | return; |
| 6231 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6232 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6233 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6234 | boolean requireUssd = c.getBoolean( |
| 6235 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6236 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6237 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6238 | if (requireUssd) { |
| 6239 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6240 | getSubscriptionCarrierId(subId)); |
| 6241 | String newUssdCommand = ""; |
| 6242 | try { |
| 6243 | newUssdCommand = carrierXmlParser.getFeature( |
| 6244 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6245 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6246 | } catch (NullPointerException e) { |
| 6247 | loge("Failed to generate USSD number" + e); |
| 6248 | } |
| 6249 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6250 | mMainThreadHandler, callback, carrierXmlParser, |
| 6251 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6252 | final String ussdCommand = newUssdCommand; |
| 6253 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6254 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6255 | }); |
| 6256 | } else { |
| 6257 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6258 | callback::accept); |
| 6259 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6260 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6261 | } finally { |
| 6262 | Binder.restoreCallingIdentity(identity); |
| 6263 | } |
| 6264 | } |
| 6265 | |
| 6266 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6267 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6268 | */ |
| 6269 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6270 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6271 | enforceModifyPermission(); |
| 6272 | long identity = Binder.clearCallingIdentity(); |
| 6273 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6274 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6275 | |
| 6276 | Phone phone = getPhone(subId); |
| 6277 | if (phone == null) { |
| 6278 | try { |
| 6279 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6280 | } catch (RemoteException e) { |
| 6281 | // ignore |
| 6282 | } |
| 6283 | return; |
| 6284 | } |
| 6285 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6286 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6287 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6288 | boolean requireUssd = c.getBoolean( |
| 6289 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6290 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6291 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6292 | if (requireUssd) { |
| 6293 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6294 | getSubscriptionCarrierId(subId)); |
| 6295 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6296 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6297 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6298 | String newUssdCommand = ""; |
| 6299 | try { |
| 6300 | newUssdCommand = carrierXmlParser.getFeature( |
| 6301 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6302 | .makeCommand(ssAction, null); |
| 6303 | } catch (NullPointerException e) { |
| 6304 | loge("Failed to generate USSD number" + e); |
| 6305 | } |
| 6306 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6307 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6308 | final String ussdCommand = newUssdCommand; |
| 6309 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6310 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6311 | }); |
| 6312 | } else { |
| 6313 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6314 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6315 | |
| 6316 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6317 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6318 | } finally { |
| 6319 | Binder.restoreCallingIdentity(identity); |
| 6320 | } |
| 6321 | } |
| 6322 | |
| 6323 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6324 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6325 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6326 | * @param subId id of the subscription |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6327 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6328 | * location related information which will be sent if the caller already possess |
| 6329 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6330 | * @param request contains the radio access networks with bands/channels to scan |
| 6331 | * @param messenger callback messenger for scan results or errors |
| 6332 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6333 | * @return the id of the requested scan which can be used to stop the scan. |
| 6334 | */ |
| 6335 | @Override |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6336 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6337 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6338 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6339 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6340 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6341 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6342 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6343 | if (!renounceFineLocationAccess) { |
| 6344 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
| 6345 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6346 | .setCallingPackage(callingPackage) |
| 6347 | .setCallingFeatureId(callingFeatureId) |
| 6348 | .setCallingPid(Binder.getCallingPid()) |
| 6349 | .setCallingUid(Binder.getCallingUid()) |
| 6350 | .setMethod("requestNetworkScan") |
| 6351 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6352 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6353 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6354 | .build()); |
| 6355 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6356 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6357 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6358 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6359 | if (e != null) { |
| 6360 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6361 | throw e; |
| 6362 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6363 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6364 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6365 | } |
| 6366 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6367 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6368 | int callingUid = Binder.getCallingUid(); |
| 6369 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6370 | final long identity = Binder.clearCallingIdentity(); |
| 6371 | try { |
| 6372 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6373 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6374 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6375 | } finally { |
| 6376 | Binder.restoreCallingIdentity(identity); |
| 6377 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6378 | } |
| 6379 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6380 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6381 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6382 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6383 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6384 | boolean hasNetworkScanPermission = |
| 6385 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6386 | == PERMISSION_GRANTED; |
| 6387 | |
| 6388 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6389 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6390 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6391 | } |
| 6392 | |
| 6393 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6394 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6395 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6396 | return new SecurityException("Specific channels must not be" |
| 6397 | + " scanned without location access."); |
| 6398 | } |
| 6399 | } |
| 6400 | } |
| 6401 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6402 | return null; |
| 6403 | } |
| 6404 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6405 | /** |
| 6406 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6407 | * |
| 6408 | * @param subId id of the subscription |
| 6409 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6410 | */ |
| 6411 | @Override |
| 6412 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6413 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6414 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6415 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6416 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6417 | final long identity = Binder.clearCallingIdentity(); |
| 6418 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6419 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6420 | } finally { |
| 6421 | Binder.restoreCallingIdentity(identity); |
| 6422 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6423 | } |
| 6424 | |
| 6425 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6426 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6427 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6428 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6429 | */ |
| 6430 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6431 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6432 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6433 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6434 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6435 | |
| 6436 | final long identity = Binder.clearCallingIdentity(); |
| 6437 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6438 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6439 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6440 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6441 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6442 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6443 | } finally { |
| 6444 | Binder.restoreCallingIdentity(identity); |
| 6445 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6446 | } |
| 6447 | |
| 6448 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6449 | * Get the allowed network types for certain reason. |
| 6450 | * |
| 6451 | * @param subId the id of the subscription. |
| 6452 | * @param reason the reason the allowed network type change is taking place |
| 6453 | * @return the allowed network types. |
| 6454 | */ |
| 6455 | @Override |
| 6456 | public long getAllowedNetworkTypesForReason(int subId, |
| 6457 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6458 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6459 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6460 | final long identity = Binder.clearCallingIdentity(); |
| 6461 | try { |
| 6462 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6463 | } finally { |
| 6464 | Binder.restoreCallingIdentity(identity); |
| 6465 | } |
| 6466 | } |
| 6467 | |
| 6468 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6469 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6470 | * @param subId subscription id of the sim card |
| 6471 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6472 | * This can be passed following states |
| 6473 | * <ol> |
| 6474 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6475 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6476 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6477 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6478 | * </ol> |
| 6479 | * @return operation result. |
| 6480 | */ |
| 6481 | @Override |
| 6482 | public int setNrDualConnectivityState(int subId, |
| 6483 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6484 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6485 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6486 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6487 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6488 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6489 | } |
| 6490 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6491 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6492 | final long identity = Binder.clearCallingIdentity(); |
| 6493 | try { |
| 6494 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6495 | nrDualConnectivityState, subId, |
| 6496 | workSource); |
| 6497 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6498 | return result; |
| 6499 | } finally { |
| 6500 | Binder.restoreCallingIdentity(identity); |
| 6501 | } |
| 6502 | } |
| 6503 | |
| 6504 | /** |
| 6505 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6506 | * @return true if dual connectivity is enabled else false |
| 6507 | */ |
| 6508 | @Override |
| 6509 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6510 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6511 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6512 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6513 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6514 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6515 | return false; |
| 6516 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6517 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6518 | final long identity = Binder.clearCallingIdentity(); |
| 6519 | try { |
| 6520 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6521 | null, subId, workSource); |
| 6522 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6523 | return isEnabled; |
| 6524 | } finally { |
| 6525 | Binder.restoreCallingIdentity(identity); |
| 6526 | } |
| 6527 | } |
| 6528 | |
| 6529 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6530 | * Set the allowed network types of the device and |
| 6531 | * provide the reason triggering the allowed network change. |
| 6532 | * |
| 6533 | * @param subId the id of the subscription. |
| 6534 | * @param reason the reason the allowed network type change is taking place |
| 6535 | * @param allowedNetworkTypes the allowed network types. |
| 6536 | * @return true on success; false on any failure. |
| 6537 | */ |
| 6538 | @Override |
| 6539 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6540 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6541 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6542 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6543 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6544 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6545 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6546 | return false; |
| 6547 | } |
| 6548 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6549 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6550 | return false; |
| 6551 | } |
| 6552 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6553 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6554 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6555 | |
| 6556 | |
| 6557 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6558 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6559 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6560 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6561 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6562 | final long identity = Binder.clearCallingIdentity(); |
| 6563 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6564 | Boolean success = (Boolean) sendRequest( |
| 6565 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6566 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6567 | |
| 6568 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6569 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6570 | } finally { |
| 6571 | Binder.restoreCallingIdentity(identity); |
| 6572 | } |
| 6573 | } |
| 6574 | |
| 6575 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6576 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6577 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6578 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6579 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6580 | * @hide |
| 6581 | */ |
| 6582 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6583 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6584 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6585 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6586 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6587 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6588 | if (phone != null) { |
| 6589 | return phone.hasMatchedTetherApnSetting(); |
| 6590 | } else { |
| 6591 | return false; |
| 6592 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6593 | } finally { |
| 6594 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6595 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6596 | } |
| 6597 | |
| 6598 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6599 | * Get the user enabled state of Mobile Data. |
| 6600 | * |
| 6601 | * TODO: remove and use isUserDataEnabled. |
| 6602 | * This can't be removed now because some vendor codes |
| 6603 | * calls through ITelephony directly while they should |
| 6604 | * use TelephonyManager. |
| 6605 | * |
| 6606 | * @return true on enabled |
| 6607 | */ |
| 6608 | @Override |
| 6609 | public boolean getDataEnabled(int subId) { |
| 6610 | return isUserDataEnabled(subId); |
| 6611 | } |
| 6612 | |
| 6613 | /** |
| 6614 | * Get whether mobile data is enabled per user setting. |
| 6615 | * |
| 6616 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6617 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6618 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6619 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6620 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6621 | * |
| 6622 | * @return {@code true} if data is enabled else {@code false} |
| 6623 | */ |
| 6624 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6625 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6626 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6627 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6628 | try { |
| 6629 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6630 | functionName); |
| 6631 | } catch (Exception e) { |
| 6632 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6633 | } |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6634 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6635 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6636 | mApp, subId, functionName); |
| 6637 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6638 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6639 | |
| 6640 | final long identity = Binder.clearCallingIdentity(); |
| 6641 | try { |
| 6642 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6643 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6644 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6645 | if (phone != null) { |
| 6646 | boolean retVal = phone.isUserDataEnabled(); |
| 6647 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6648 | return retVal; |
| 6649 | } else { |
| 6650 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6651 | return false; |
| 6652 | } |
| 6653 | } finally { |
| 6654 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6655 | } |
| 6656 | } |
| 6657 | |
| 6658 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6659 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6660 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6661 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6662 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6663 | * @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] | 6664 | */ |
| 6665 | @Override |
| 6666 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6667 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6668 | try { |
| 6669 | try { |
| 6670 | mApp.enforceCallingOrSelfPermission( |
| 6671 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6672 | functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6673 | } catch (Exception e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6674 | try { |
| 6675 | mApp.enforceCallingOrSelfPermission( |
| 6676 | android.Manifest.permission.READ_PHONE_STATE, |
| 6677 | functionName); |
| 6678 | } catch (Exception e2) { |
| 6679 | mApp.enforceCallingOrSelfPermission( |
| 6680 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6681 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6682 | } |
| 6683 | } catch (Exception e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6684 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6685 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6686 | |
| 6687 | final long identity = Binder.clearCallingIdentity(); |
| 6688 | try { |
| 6689 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6690 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6691 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6692 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6693 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6694 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6695 | return retVal; |
| 6696 | } else { |
| 6697 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6698 | return false; |
| 6699 | } |
| 6700 | } finally { |
| 6701 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6702 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6703 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6704 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6705 | /** |
| 6706 | * Check if data is enabled for a specific reason |
| 6707 | * @param subId Subscription index |
| 6708 | * @param reason the reason the data enable change is taking place |
| 6709 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6710 | */ |
| 6711 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6712 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6713 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6714 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6715 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6716 | try { |
| 6717 | mApp.enforceCallingOrSelfPermission( |
| 6718 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6719 | functionName); |
| 6720 | } catch (Exception e) { |
| 6721 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6722 | functionName); |
| 6723 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6724 | } catch (Exception e) { |
Sooraj Sasindran | 72a2276 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6725 | try { |
| 6726 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6727 | functionName); |
Sooraj Sasindran | 72a2276 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6728 | } catch (Exception e2) { |
| 6729 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6730 | mApp, subId, functionName); |
Sooraj Sasindran | 72a2276 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6731 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6732 | } |
| 6733 | |
| 6734 | |
| 6735 | final long identity = Binder.clearCallingIdentity(); |
| 6736 | try { |
| 6737 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6738 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6739 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6740 | + " reason=" + reason); |
| 6741 | } |
| 6742 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6743 | if (phone != null) { |
| 6744 | boolean retVal; |
| 6745 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6746 | retVal = phone.isUserDataEnabled(); |
| 6747 | } else { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6748 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6749 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6750 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6751 | return retVal; |
| 6752 | } else { |
| 6753 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6754 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6755 | + subId + " retVal=false"); |
| 6756 | } |
| 6757 | return false; |
| 6758 | } |
| 6759 | } finally { |
| 6760 | Binder.restoreCallingIdentity(identity); |
| 6761 | } |
| 6762 | } |
| 6763 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6764 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6765 | Phone phone) { |
Sarah Chin | 3394efe | 2021-04-09 10:37:15 -0700 | [diff] [blame] | 6766 | if (uid == Process.PHONE_UID) { |
| 6767 | // Skip the check if it's the phone UID (system UID removed in b/184713596) |
| 6768 | // 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] | 6769 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6770 | } |
| 6771 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6772 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6773 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6774 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6775 | || subController == null) return privilegeFromSim; |
| 6776 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6777 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6778 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6779 | |
| 6780 | final long identity = Binder.clearCallingIdentity(); |
| 6781 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6782 | int subId = phone.getSubId(); |
| 6783 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6784 | // A test override is in place for the privileges for this subId, so don't try to |
| 6785 | // read the subscription privileges. |
| 6786 | return privilegeFromSim; |
| 6787 | } |
| 6788 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6789 | SubscriptionManager subManager = (SubscriptionManager) |
| 6790 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6791 | for (String pkg : packages) { |
| 6792 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6793 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6794 | } |
| 6795 | } |
| 6796 | return privilegeFromSim; |
| 6797 | } finally { |
| 6798 | Binder.restoreCallingIdentity(identity); |
| 6799 | } |
| 6800 | } |
| 6801 | |
| 6802 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6803 | String pkgName) { |
| 6804 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6805 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6806 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6807 | || subController == null) return privilegeFromSim; |
| 6808 | |
| 6809 | final long identity = Binder.clearCallingIdentity(); |
| 6810 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6811 | int subId = phone.getSubId(); |
| 6812 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6813 | // A test override is in place for the privileges for this subId, so don't try to |
| 6814 | // read the subscription privileges. |
| 6815 | return privilegeFromSim; |
| 6816 | } |
| 6817 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6818 | SubscriptionManager subManager = (SubscriptionManager) |
| 6819 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6820 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6821 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6822 | } finally { |
| 6823 | Binder.restoreCallingIdentity(identity); |
| 6824 | } |
| 6825 | } |
| 6826 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6827 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6828 | public int getCarrierPrivilegeStatus(int subId) { |
| 6829 | final Phone phone = getPhone(subId); |
| 6830 | if (phone == null) { |
| 6831 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6832 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6833 | } |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6834 | UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
| 6835 | if (port == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6836 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6837 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6838 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6839 | |
| 6840 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6841 | port.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6842 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6843 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6844 | |
| 6845 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6846 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6847 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6848 | final Phone phone = getPhone(subId); |
| 6849 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6850 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6851 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6852 | } |
| 6853 | UiccProfile profile = |
| 6854 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6855 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6856 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6857 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6858 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6859 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6860 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6861 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6862 | } |
| 6863 | |
| 6864 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6865 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6866 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6867 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6868 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6869 | } |
| 6870 | |
| 6871 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6872 | UiccPort port = UiccController.getInstance().getUiccPort(phoneId); |
| 6873 | if (port == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6874 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6875 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6876 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6877 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6878 | port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6879 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6880 | } |
| 6881 | |
| 6882 | @Override |
| 6883 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Sarah Chin | fc3169b | 2021-04-28 20:21:03 -0700 | [diff] [blame] | 6884 | // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6885 | if (TextUtils.isEmpty(pkgName)) |
| 6886 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6887 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6888 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6889 | UiccPort port = UiccController.getInstance().getUiccPort(i); |
| 6890 | if (port == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6891 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6892 | continue; |
| 6893 | } |
| 6894 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6895 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6896 | port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6897 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6898 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6899 | break; |
| 6900 | } |
| 6901 | } |
| 6902 | |
| 6903 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6904 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6905 | |
| 6906 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6907 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6908 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6909 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6910 | loge("phoneId " + phoneId + " is not valid."); |
| 6911 | return null; |
| 6912 | } |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6913 | UiccPort port = UiccController.getInstance().getUiccPort(phoneId); |
| 6914 | if (port == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6915 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6916 | return null ; |
| 6917 | } |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6918 | return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6919 | } |
| 6920 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6921 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6922 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6923 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6924 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6925 | List<String> privilegedPackages = new ArrayList<>(); |
| 6926 | List<PackageInfo> packages = null; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6927 | UiccPort port = UiccController.getInstance().getUiccPort(phoneId); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6928 | // has UICC in that slot. |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6929 | if (port != null) { |
| 6930 | if (port.hasCarrierPrivilegeRules()) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6931 | if (packages == null) { |
| 6932 | // Only check packages in user 0 for now |
| 6933 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6934 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6935 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6936 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6937 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6938 | } |
| 6939 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6940 | PackageInfo pkgInfo = packages.get(p); |
| 6941 | if (pkgInfo != null && pkgInfo.packageName != null |
Sooraj Sasindran | 6c442bf | 2021-09-28 21:37:29 +0000 | [diff] [blame] | 6942 | && getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6943 | port.getCarrierPrivilegeStatus(pkgInfo), |
Sooraj Sasindran | 6c442bf | 2021-09-28 21:37:29 +0000 | [diff] [blame] | 6944 | getPhone(phoneId), pkgInfo.packageName) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6945 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6946 | privilegedPackages.add(pkgInfo.packageName); |
| 6947 | } |
| 6948 | } |
| 6949 | } |
| 6950 | } |
| 6951 | return privilegedPackages; |
| 6952 | } |
| 6953 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6954 | @Override |
| 6955 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6956 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6957 | |
| 6958 | final long identity = Binder.clearCallingIdentity(); |
| 6959 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6960 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6961 | try { |
| 6962 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6963 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6964 | } |
| 6965 | } finally { |
| 6966 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6967 | } |
| 6968 | return privilegedPackages; |
| 6969 | } |
| 6970 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6971 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6972 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6973 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 6974 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6975 | return null; |
| 6976 | } |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6977 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6978 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6979 | return null; |
| 6980 | } |
| 6981 | return iccId; |
| 6982 | } |
| 6983 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6984 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6985 | public void setCallComposerStatus(int subId, int status) { |
| 6986 | enforceModifyPermission(); |
| 6987 | |
| 6988 | final long identity = Binder.clearCallingIdentity(); |
| 6989 | try { |
| 6990 | Phone phone = getPhone(subId); |
| 6991 | if (phone != null) { |
| 6992 | Phone defaultPhone = phone.getImsPhone(); |
| 6993 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6994 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6995 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6996 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6997 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6998 | } |
| 6999 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7000 | } catch (ImsException e) { |
| 7001 | throw new ServiceSpecificException(e.getCode()); |
| 7002 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7003 | Binder.restoreCallingIdentity(identity); |
| 7004 | } |
| 7005 | } |
| 7006 | |
| 7007 | @Override |
| 7008 | public int getCallComposerStatus(int subId) { |
| 7009 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7010 | |
| 7011 | final long identity = Binder.clearCallingIdentity(); |
| 7012 | try { |
| 7013 | Phone phone = getPhone(subId); |
| 7014 | if (phone != null) { |
| 7015 | Phone defaultPhone = phone.getImsPhone(); |
| 7016 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7017 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7018 | return imsPhone.getCallComposerStatus(); |
| 7019 | } |
| 7020 | } |
| 7021 | } finally { |
| 7022 | Binder.restoreCallingIdentity(identity); |
| 7023 | } |
| 7024 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7025 | } |
| 7026 | |
| 7027 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7028 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7029 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7030 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7031 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7032 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7033 | final long identity = Binder.clearCallingIdentity(); |
| 7034 | try { |
| 7035 | final String iccId = getIccId(subId); |
| 7036 | final Phone phone = getPhone(subId); |
| 7037 | if (phone == null) { |
| 7038 | return false; |
| 7039 | } |
| 7040 | final String subscriberId = phone.getSubscriberId(); |
| 7041 | |
| 7042 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7043 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7044 | + subscriberId + " to " + number); |
| 7045 | } |
| 7046 | |
| 7047 | if (TextUtils.isEmpty(iccId)) { |
| 7048 | return false; |
| 7049 | } |
| 7050 | |
| 7051 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7052 | |
| 7053 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7054 | if (alphaTag == null) { |
| 7055 | editor.remove(alphaTagPrefKey); |
| 7056 | } else { |
| 7057 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7058 | } |
| 7059 | |
| 7060 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7061 | // track all merged IMSIs based on line number |
| 7062 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7063 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7064 | if (number == null) { |
| 7065 | editor.remove(numberPrefKey); |
| 7066 | editor.remove(subscriberPrefKey); |
| 7067 | } else { |
| 7068 | editor.putString(numberPrefKey, number); |
| 7069 | editor.putString(subscriberPrefKey, subscriberId); |
| 7070 | } |
| 7071 | |
| 7072 | editor.commit(); |
| 7073 | return true; |
| 7074 | } finally { |
| 7075 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7076 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7077 | } |
| 7078 | |
| 7079 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7080 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7081 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7082 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7083 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7084 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7085 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7086 | return null; |
| 7087 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7088 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7089 | final long identity = Binder.clearCallingIdentity(); |
| 7090 | try { |
| 7091 | String iccId = getIccId(subId); |
| 7092 | if (iccId != null) { |
| 7093 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7094 | if (DBG_MERGE) { |
| 7095 | log("getLine1NumberForDisplay returning " |
| 7096 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7097 | } |
| 7098 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7099 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7100 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7101 | return null; |
| 7102 | } finally { |
| 7103 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7104 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7105 | } |
| 7106 | |
| 7107 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7108 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7109 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7110 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7111 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7112 | return null; |
| 7113 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7114 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7115 | final long identity = Binder.clearCallingIdentity(); |
| 7116 | try { |
| 7117 | String iccId = getIccId(subId); |
| 7118 | if (iccId != null) { |
| 7119 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7120 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7121 | } |
| 7122 | return null; |
| 7123 | } finally { |
| 7124 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7125 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7126 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7127 | |
| 7128 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7129 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7130 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7131 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7132 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7133 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7134 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7135 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7136 | return null; |
| 7137 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7138 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7139 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7140 | // the process, where TelephonyManager was instantiated. |
| 7141 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7142 | final long identity = Binder.clearCallingIdentity(); |
| 7143 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7144 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7145 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7146 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7147 | |
| 7148 | // Figure out what subscribers are currently active |
| 7149 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7150 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7151 | // Only consider subs which match the current subId |
| 7152 | // This logic can be simplified. See b/131189269 for progress. |
| 7153 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7154 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7155 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7156 | |
| 7157 | // First pass, find a number override for an active subscriber |
| 7158 | String mergeNumber = null; |
| 7159 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7160 | for (String key : prefs.keySet()) { |
| 7161 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7162 | final String subscriberId = (String) prefs.get(key); |
| 7163 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7164 | final String iccId = key.substring( |
| 7165 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7166 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7167 | mergeNumber = (String) prefs.get(numberKey); |
| 7168 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7169 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7170 | + " for active subscriber " + subscriberId); |
| 7171 | } |
| 7172 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7173 | break; |
| 7174 | } |
| 7175 | } |
| 7176 | } |
| 7177 | } |
| 7178 | |
| 7179 | // Shortcut when no active merged subscribers |
| 7180 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7181 | return null; |
| 7182 | } |
| 7183 | |
| 7184 | // Second pass, find all subscribers under that line override |
| 7185 | final ArraySet<String> result = new ArraySet<>(); |
| 7186 | for (String key : prefs.keySet()) { |
| 7187 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7188 | final String number = (String) prefs.get(key); |
| 7189 | if (mergeNumber.equals(number)) { |
| 7190 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7191 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7192 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7193 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7194 | result.add(subscriberId); |
| 7195 | } |
| 7196 | } |
| 7197 | } |
| 7198 | } |
| 7199 | |
| 7200 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7201 | Arrays.sort(resultArray); |
| 7202 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7203 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7204 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7205 | } |
| 7206 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7207 | } finally { |
| 7208 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7209 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7210 | } |
| 7211 | |
| 7212 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7213 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7214 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7215 | |
| 7216 | final long identity = Binder.clearCallingIdentity(); |
| 7217 | try { |
| 7218 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7219 | TelephonyManager.class); |
| 7220 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7221 | if (subscriberId == null) { |
| 7222 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7223 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7224 | + subId); |
| 7225 | } |
| 7226 | return null; |
| 7227 | } |
| 7228 | |
| 7229 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 7230 | .getSubscriptionInfo(subId); |
| 7231 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 7232 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7233 | if (groupUuid == null) { |
| 7234 | return new String[]{subscriberId}; |
| 7235 | } |
| 7236 | |
| 7237 | // Get all subscriberIds from the group. |
| 7238 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 7239 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7240 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7241 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7242 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7243 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7244 | if (subscriberId != null) { |
| 7245 | mergedSubscriberIds.add(subscriberId); |
| 7246 | } |
| 7247 | } |
| 7248 | |
| 7249 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7250 | } finally { |
| 7251 | Binder.restoreCallingIdentity(identity); |
| 7252 | |
| 7253 | } |
| 7254 | } |
| 7255 | |
| 7256 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7257 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7258 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7259 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7260 | |
| 7261 | final long identity = Binder.clearCallingIdentity(); |
| 7262 | try { |
| 7263 | final Phone phone = getPhone(subId); |
| 7264 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7265 | } finally { |
| 7266 | Binder.restoreCallingIdentity(identity); |
| 7267 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7268 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7269 | |
| 7270 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7271 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7272 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7273 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7274 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7275 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7276 | |
| 7277 | final long identity = Binder.clearCallingIdentity(); |
| 7278 | try { |
| 7279 | final Phone phone = getPhone(subId); |
| 7280 | if (phone == null) { |
| 7281 | return false; |
| 7282 | } |
| 7283 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7284 | cdmaNonRoamingList); |
| 7285 | } finally { |
| 7286 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7287 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7288 | } |
| 7289 | |
| 7290 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7291 | @Deprecated |
| 7292 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7293 | enforceModifyPermission(); |
| 7294 | |
| 7295 | int returnValue = 0; |
| 7296 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7297 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7298 | if(result.exception == null) { |
| 7299 | if (result.result != null) { |
| 7300 | byte[] responseData = (byte[])(result.result); |
| 7301 | if(responseData.length > oemResp.length) { |
| 7302 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7303 | responseData.length + "bytes. Buffer Size is " + |
| 7304 | oemResp.length + "bytes."); |
| 7305 | } |
| 7306 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7307 | returnValue = responseData.length; |
| 7308 | } |
| 7309 | } else { |
| 7310 | CommandException ex = (CommandException) result.exception; |
| 7311 | returnValue = ex.getCommandError().ordinal(); |
| 7312 | if(returnValue > 0) returnValue *= -1; |
| 7313 | } |
| 7314 | } catch (RuntimeException e) { |
| 7315 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7316 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7317 | if(returnValue > 0) returnValue *= -1; |
| 7318 | } |
| 7319 | |
| 7320 | return returnValue; |
| 7321 | } |
| 7322 | |
| 7323 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7324 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7325 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7326 | try { |
| 7327 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7328 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7329 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7330 | } catch (SecurityException e) { |
| 7331 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7332 | throw e; |
| 7333 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7334 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7335 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7336 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7337 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7338 | final long identity = Binder.clearCallingIdentity(); |
| 7339 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7340 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7341 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7342 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7343 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7344 | } finally { |
| 7345 | Binder.restoreCallingIdentity(identity); |
| 7346 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7347 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7348 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7349 | |
| 7350 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7351 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7352 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7353 | try { |
| 7354 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7355 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7356 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7357 | } |
| 7358 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7359 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7360 | } |
| 7361 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7362 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7363 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7364 | throw new SecurityException("App must be the dialer role holder to" |
| 7365 | + " upload a call composer pic"); |
| 7366 | } |
| 7367 | |
| 7368 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7369 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7370 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7371 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7372 | boolean readUntilEnd = false; |
| 7373 | int totalBytesRead = 0; |
| 7374 | byte[] buffer = new byte[16 * 1024]; |
| 7375 | while (true) { |
| 7376 | int numRead; |
| 7377 | try { |
| 7378 | numRead = input.read(buffer); |
| 7379 | } catch (IOException e) { |
| 7380 | try { |
| 7381 | fd.checkError(); |
| 7382 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7383 | null); |
| 7384 | } catch (IOException e1) { |
| 7385 | // This means that the other side closed explicitly with an error. If this |
| 7386 | // happens, log and ignore. |
| 7387 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7388 | } |
| 7389 | break; |
| 7390 | } |
| 7391 | if (numRead == -1) { |
| 7392 | readUntilEnd = true; |
| 7393 | break; |
| 7394 | } |
| 7395 | totalBytesRead += numRead; |
| 7396 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7397 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7398 | try { |
| 7399 | input.close(); |
| 7400 | } catch (IOException e) { |
| 7401 | // ignore |
| 7402 | } |
| 7403 | break; |
| 7404 | } |
| 7405 | output.write(buffer, 0, numRead); |
| 7406 | } |
| 7407 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7408 | // close is above, where the picture size is too big. |
| 7409 | |
| 7410 | try { |
| 7411 | fd.checkError(); |
| 7412 | } catch (IOException e) { |
| 7413 | loge("Remote end for call composer closed with an error: " + e); |
| 7414 | return; |
| 7415 | } |
| 7416 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7417 | if (!readUntilEnd) { |
| 7418 | loge("Did not finish reading entire image; aborting"); |
| 7419 | return; |
| 7420 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7421 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7422 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7423 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7424 | new CallComposerPictureTransfer.Factory() {}, |
| 7425 | imageData, |
| 7426 | (result) -> { |
| 7427 | if (result.first != null) { |
| 7428 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7429 | Bundle outputResult = new Bundle(); |
| 7430 | outputResult.putParcelable( |
| 7431 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7432 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7433 | outputResult); |
| 7434 | } else { |
| 7435 | callback.send(result.second, null); |
| 7436 | } |
| 7437 | } |
| 7438 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7439 | }); |
| 7440 | } |
| 7441 | |
| 7442 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7443 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7444 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7445 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7446 | |
| 7447 | final long identity = Binder.clearCallingIdentity(); |
| 7448 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7449 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7450 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7451 | } finally { |
| 7452 | Binder.restoreCallingIdentity(identity); |
| 7453 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7454 | } |
| 7455 | |
| 7456 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7457 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7458 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7459 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7460 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7461 | return false; |
| 7462 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7463 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7464 | final long identity = Binder.clearCallingIdentity(); |
| 7465 | try { |
| 7466 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7467 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7468 | // In the long run, we may instead need to check if there exists a connection service |
| 7469 | // which can support video calling. |
| 7470 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7471 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7472 | return imsManager.isVtEnabledByPlatform() |
| 7473 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7474 | && imsManager.isVtEnabledByUser(); |
| 7475 | } finally { |
| 7476 | Binder.restoreCallingIdentity(identity); |
| 7477 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7478 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7479 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7480 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7481 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7482 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7483 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7484 | mApp, subId, callingPackage, callingFeatureId, |
| 7485 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7486 | return false; |
| 7487 | } |
| 7488 | |
| 7489 | final long identity = Binder.clearCallingIdentity(); |
| 7490 | try { |
| 7491 | CarrierConfigManager configManager = |
| 7492 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7493 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7494 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7495 | } finally { |
| 7496 | Binder.restoreCallingIdentity(identity); |
| 7497 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7498 | } |
| 7499 | |
| 7500 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7501 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7502 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7503 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7504 | return false; |
| 7505 | } |
| 7506 | |
| 7507 | final long identity = Binder.clearCallingIdentity(); |
| 7508 | try { |
| 7509 | CarrierConfigManager configManager = |
| 7510 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7511 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7512 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7513 | } finally { |
| 7514 | Binder.restoreCallingIdentity(identity); |
| 7515 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7516 | } |
| 7517 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7518 | @Override |
| 7519 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7520 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7521 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7522 | } |
| 7523 | |
| 7524 | @Override |
| 7525 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7526 | final long identity = Binder.clearCallingIdentity(); |
| 7527 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7528 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7529 | } finally { |
| 7530 | Binder.restoreCallingIdentity(identity); |
| 7531 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7532 | } |
| 7533 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7534 | /** |
| 7535 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7536 | * support for the feature and device firmware support. |
| 7537 | * |
| 7538 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7539 | */ |
| 7540 | @Override |
| 7541 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7542 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7543 | final Phone phone = getPhone(subscriptionId); |
| 7544 | if (phone == null) { |
| 7545 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7546 | return false; |
| 7547 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7548 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7549 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7550 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7551 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7552 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7553 | return isCarrierSupported && isDeviceSupported; |
| 7554 | } finally { |
| 7555 | Binder.restoreCallingIdentity(identity); |
| 7556 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7557 | } |
| 7558 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7559 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7560 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7561 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7562 | * 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] | 7563 | */ |
| 7564 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7565 | final long identity = Binder.clearCallingIdentity(); |
| 7566 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7567 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7568 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7569 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7570 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7571 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7572 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7573 | } finally { |
| 7574 | Binder.restoreCallingIdentity(identity); |
| 7575 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7576 | } |
| 7577 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7578 | @Deprecated |
| 7579 | @Override |
| 7580 | public String getDeviceId(String callingPackage) { |
| 7581 | return getDeviceIdWithFeature(callingPackage, null); |
| 7582 | } |
| 7583 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7584 | /** |
| 7585 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7586 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7587 | * |
| 7588 | * <p>Requires Permission: |
| 7589 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7590 | */ |
| 7591 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7592 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7593 | try { |
| 7594 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7595 | } catch (SecurityException se) { |
| 7596 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7597 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7598 | + Binder.getCallingUid()); |
| 7599 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7600 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7601 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7602 | return null; |
| 7603 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7604 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7605 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7606 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7607 | return null; |
| 7608 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7609 | |
| 7610 | final long identity = Binder.clearCallingIdentity(); |
| 7611 | try { |
| 7612 | return phone.getDeviceId(); |
| 7613 | } finally { |
| 7614 | Binder.restoreCallingIdentity(identity); |
| 7615 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7616 | } |
| 7617 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7618 | /** |
| 7619 | * {@hide} |
| 7620 | * Returns the IMS Registration Status on a particular subid |
| 7621 | * |
| 7622 | * @param subId |
| 7623 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7624 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7625 | Phone phone = getPhone(subId); |
| 7626 | if (phone != null) { |
| 7627 | return phone.isImsRegistered(); |
| 7628 | } else { |
| 7629 | return false; |
| 7630 | } |
| 7631 | } |
| 7632 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7633 | @Override |
| 7634 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7635 | final long identity = Binder.clearCallingIdentity(); |
| 7636 | try { |
| 7637 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7638 | } finally { |
| 7639 | Binder.restoreCallingIdentity(identity); |
| 7640 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7641 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7642 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7643 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7644 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7645 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7646 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7647 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7648 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7649 | } |
| 7650 | final long identity = Binder.clearCallingIdentity(); |
| 7651 | try { |
| 7652 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7653 | } finally { |
| 7654 | Binder.restoreCallingIdentity(identity); |
| 7655 | } |
| 7656 | } |
| 7657 | |
| 7658 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7659 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7660 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7661 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7662 | mApp, |
| 7663 | subscriptionId, |
| 7664 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7665 | final long identity = Binder.clearCallingIdentity(); |
| 7666 | try { |
| 7667 | Phone phone = getPhone(subscriptionId); |
| 7668 | if (phone == null) { |
| 7669 | return null; |
| 7670 | } |
| 7671 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7672 | } finally { |
| 7673 | Binder.restoreCallingIdentity(identity); |
| 7674 | } |
| 7675 | } |
| 7676 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7677 | /** |
| 7678 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7679 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7680 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7681 | final long identity = Binder.clearCallingIdentity(); |
| 7682 | try { |
| 7683 | Phone phone = getPhone(subId); |
| 7684 | if (phone != null) { |
| 7685 | return phone.isWifiCallingEnabled(); |
| 7686 | } else { |
| 7687 | return false; |
| 7688 | } |
| 7689 | } finally { |
| 7690 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7691 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7692 | } |
| 7693 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7694 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7695 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7696 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7697 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7698 | final long identity = Binder.clearCallingIdentity(); |
| 7699 | try { |
| 7700 | Phone phone = getPhone(subId); |
| 7701 | if (phone != null) { |
| 7702 | return phone.isVideoEnabled(); |
| 7703 | } else { |
| 7704 | return false; |
| 7705 | } |
| 7706 | } finally { |
| 7707 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7708 | } |
| 7709 | } |
| 7710 | |
| 7711 | /** |
| 7712 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7713 | * defined in {@link ImsRegistrationImplBase}. |
| 7714 | */ |
| 7715 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7716 | final long identity = Binder.clearCallingIdentity(); |
| 7717 | try { |
| 7718 | Phone phone = getPhone(subId); |
| 7719 | if (phone != null) { |
| 7720 | return phone.getImsRegistrationTech(); |
| 7721 | } else { |
| 7722 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7723 | } |
| 7724 | } finally { |
| 7725 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7726 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7727 | } |
| 7728 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7729 | @Override |
| 7730 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7731 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7732 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7733 | return; |
| 7734 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7735 | Phone defaultPhone = getDefaultPhone(); |
| 7736 | if (defaultPhone != null) { |
| 7737 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7738 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7739 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7740 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7741 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7742 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7743 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7744 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7745 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7746 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7747 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7748 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7749 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7750 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7751 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7752 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7753 | // There has been issues when Sms raw table somehow stores orphan |
| 7754 | // fragments. They lead to garbled message when new fragments come |
| 7755 | // in and combined with those stale ones. In case this happens again, |
| 7756 | // user can reset all network settings which will clean up this table. |
| 7757 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7758 | // Clean up IMS settings as well here. |
| 7759 | int slotId = getSlotIndex(subId); |
| 7760 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7761 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7762 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7763 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7764 | if (defaultPhone == null) { |
| 7765 | return; |
| 7766 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7767 | // Erase modem config if erase modem on network setting is enabled. |
| 7768 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7769 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7770 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7771 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7772 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7773 | |
| 7774 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7775 | } finally { |
| 7776 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7777 | } |
| 7778 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7779 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7780 | @VisibleForTesting |
| 7781 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7782 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7783 | return; |
| 7784 | } |
| 7785 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7786 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7787 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7788 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7789 | "user=" + defaultNetworkType); |
| 7790 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7791 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7792 | defaultNetworkType, null); |
| 7793 | } |
| 7794 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7795 | private void cleanUpSmsRawTable(Context context) { |
| 7796 | ContentResolver resolver = context.getContentResolver(); |
| 7797 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7798 | resolver.delete(uri, null, null); |
| 7799 | } |
| 7800 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7801 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7802 | public String getSimLocaleForSubscriber(int subId) { |
| 7803 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7804 | final Phone phone = getPhone(subId); |
| 7805 | if (phone == null) { |
| 7806 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7807 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7808 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7809 | final long identity = Binder.clearCallingIdentity(); |
| 7810 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7811 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7812 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7813 | if (info == null) { |
| 7814 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7815 | return null; |
| 7816 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7817 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7818 | // preferences (EF-PL and EF-LI)... |
| 7819 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7820 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7821 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7822 | if (localeFromDefaultSim != null) { |
| 7823 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7824 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7825 | + localeFromDefaultSim); |
| 7826 | return localeFromDefaultSim.toLanguageTag(); |
| 7827 | } else { |
| 7828 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7829 | } |
| 7830 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7831 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7832 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7833 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7834 | // the SIM and carrier preferences does not include a country we add the country |
| 7835 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7836 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7837 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7838 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7839 | return mccLocale.toLanguageTag(); |
| 7840 | } |
| 7841 | |
| 7842 | if (DBG) log("No locale found - returning null"); |
| 7843 | return null; |
| 7844 | } finally { |
| 7845 | Binder.restoreCallingIdentity(identity); |
| 7846 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7847 | } |
| 7848 | |
| 7849 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7850 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7851 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7852 | } |
| 7853 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7854 | /** |
| 7855 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7856 | */ |
| 7857 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7858 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7859 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7860 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7861 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7862 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7863 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7864 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7865 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7866 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7867 | * representing the state of the modem. |
| 7868 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7869 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7870 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7871 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7872 | */ |
| 7873 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7874 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7875 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7876 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7877 | |
| 7878 | final long identity = Binder.clearCallingIdentity(); |
| 7879 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7880 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7881 | } finally { |
| 7882 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7883 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7884 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7885 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7886 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7887 | // less than total activity duration. |
| 7888 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7889 | if (info == null) { |
| 7890 | return false; |
| 7891 | } |
| 7892 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7893 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7894 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7895 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7896 | return (info.isValid() |
| 7897 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7898 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7899 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7900 | && (totalTxTimeMs <= activityDurationMs)); |
| 7901 | } |
| 7902 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7903 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7904 | * Returns the service state information on specified subscription. |
| 7905 | */ |
| 7906 | @Override |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7907 | public ServiceState getServiceStateForSubscriber(int subId, |
| 7908 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 7909 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7910 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7911 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7912 | return null; |
| 7913 | } |
| 7914 | |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7915 | boolean hasFinePermission = false; |
| 7916 | boolean hasCoarsePermission = false; |
| 7917 | if (!renounceFineLocationAccess) { |
| 7918 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7919 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7920 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7921 | .setCallingPackage(callingPackage) |
| 7922 | .setCallingFeatureId(callingFeatureId) |
| 7923 | .setCallingPid(Binder.getCallingPid()) |
| 7924 | .setCallingUid(Binder.getCallingUid()) |
| 7925 | .setMethod("getServiceStateForSubscriber") |
| 7926 | .setLogAsInfo(true) |
| 7927 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7928 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7929 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7930 | .build()); |
| 7931 | hasFinePermission = |
| 7932 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7933 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7934 | |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7935 | if (!renounceCoarseLocationAccess) { |
| 7936 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7937 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7938 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7939 | .setCallingPackage(callingPackage) |
| 7940 | .setCallingFeatureId(callingFeatureId) |
| 7941 | .setCallingPid(Binder.getCallingPid()) |
| 7942 | .setCallingUid(Binder.getCallingUid()) |
| 7943 | .setMethod("getServiceStateForSubscriber") |
| 7944 | .setLogAsInfo(true) |
| 7945 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7946 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7947 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7948 | .build()); |
| 7949 | hasCoarsePermission = |
| 7950 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7951 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7952 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7953 | final Phone phone = getPhone(subId); |
| 7954 | if (phone == null) { |
| 7955 | return null; |
| 7956 | } |
| 7957 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7958 | final long identity = Binder.clearCallingIdentity(); |
| 7959 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7960 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7961 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7962 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7963 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7964 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7965 | Rlog.d(LOG_TAG, |
| 7966 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7967 | return null; |
| 7968 | } |
| 7969 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7970 | ServiceState ss = phone.getServiceState(); |
| 7971 | |
| 7972 | // Scrub out the location info in ServiceState depending on what level of access |
| 7973 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7974 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7975 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7976 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7977 | } finally { |
| 7978 | Binder.restoreCallingIdentity(identity); |
| 7979 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7980 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7981 | |
| 7982 | /** |
| 7983 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7984 | * |
| 7985 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7986 | * voicemail ringtone. |
| 7987 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7988 | * PhoneAccount. |
| 7989 | */ |
| 7990 | @Override |
| 7991 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7992 | final long identity = Binder.clearCallingIdentity(); |
| 7993 | try { |
| 7994 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7995 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7996 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7997 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7998 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7999 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8000 | } finally { |
| 8001 | Binder.restoreCallingIdentity(identity); |
| 8002 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8003 | } |
| 8004 | |
| 8005 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8006 | * Sets the per-account voicemail ringtone. |
| 8007 | * |
| 8008 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8009 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8010 | * |
| 8011 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8012 | * voicemail ringtone. |
| 8013 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8014 | * PhoneAccount. |
| 8015 | */ |
| 8016 | @Override |
| 8017 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8018 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8019 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8020 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8021 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8022 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8023 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8024 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8025 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8026 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8027 | |
| 8028 | final long identity = Binder.clearCallingIdentity(); |
| 8029 | try { |
| 8030 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8031 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8032 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8033 | } |
| 8034 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8035 | } finally { |
| 8036 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8037 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8038 | } |
| 8039 | |
| 8040 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8041 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8042 | * |
| 8043 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8044 | * voicemail vibration setting. |
| 8045 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8046 | */ |
| 8047 | @Override |
| 8048 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8049 | final long identity = Binder.clearCallingIdentity(); |
| 8050 | try { |
| 8051 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8052 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8053 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8054 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8055 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8056 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8057 | } finally { |
| 8058 | Binder.restoreCallingIdentity(identity); |
| 8059 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8060 | } |
| 8061 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8062 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8063 | * Sets the per-account voicemail vibration. |
| 8064 | * |
| 8065 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8066 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8067 | * |
| 8068 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8069 | * voicemail vibration setting. |
| 8070 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8071 | * specific PhoneAccount. |
| 8072 | */ |
| 8073 | @Override |
| 8074 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8075 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8076 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8077 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8078 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8079 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8080 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8081 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8082 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8083 | } |
| 8084 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8085 | final long identity = Binder.clearCallingIdentity(); |
| 8086 | try { |
| 8087 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8088 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8089 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8090 | } |
| 8091 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8092 | } finally { |
| 8093 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8094 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8095 | } |
| 8096 | |
| 8097 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8098 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8099 | * |
| 8100 | * @throws SecurityException if the caller does not have the required permission |
| 8101 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8102 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8103 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8104 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8105 | } |
| 8106 | |
| 8107 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8108 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8109 | * permission. |
| 8110 | * |
| 8111 | * @throws SecurityException if the caller does not have the required permission |
| 8112 | */ |
| 8113 | private void enforceSendSmsPermission() { |
| 8114 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8115 | } |
| 8116 | |
| 8117 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8118 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8119 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8120 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8121 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8122 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8123 | final long identity = Binder.clearCallingIdentity(); |
| 8124 | try { |
| 8125 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8126 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8127 | if (componentName == null) { |
| 8128 | throw new SecurityException( |
| 8129 | "Caller not current active visual voicemail package[null]"); |
| 8130 | } |
| 8131 | String vvmPackage = componentName.getPackageName(); |
| 8132 | if (!callingPackage.equals(vvmPackage)) { |
| 8133 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 8134 | + vvmPackage + "]"); |
| 8135 | } |
| 8136 | } finally { |
| 8137 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8138 | } |
| 8139 | } |
| 8140 | |
| 8141 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8142 | * Return the application ID for the app type. |
| 8143 | * |
| 8144 | * @param subId the subscription ID that this request applies to. |
| 8145 | * @param appType the uicc app type. |
| 8146 | * @return Application ID for specificied app type, or null if no uicc. |
| 8147 | */ |
| 8148 | @Override |
| 8149 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8150 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8151 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8152 | |
| 8153 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8154 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8155 | if (phone == null) { |
| 8156 | return null; |
| 8157 | } |
| 8158 | String aid = null; |
| 8159 | try { |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8160 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8161 | .getApplicationByType(appType).getAid(); |
| 8162 | } catch (Exception e) { |
| 8163 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8164 | } |
| 8165 | return aid; |
| 8166 | } finally { |
| 8167 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8168 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8169 | } |
| 8170 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8171 | /** |
| 8172 | * Return the Electronic Serial Number. |
| 8173 | * |
| 8174 | * @param subId the subscription ID that this request applies to. |
| 8175 | * @return ESN or null if error. |
| 8176 | */ |
| 8177 | @Override |
| 8178 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8179 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8180 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8181 | |
| 8182 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8183 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8184 | if (phone == null) { |
| 8185 | return null; |
| 8186 | } |
| 8187 | String esn = null; |
| 8188 | try { |
| 8189 | esn = phone.getEsn(); |
| 8190 | } catch (Exception e) { |
| 8191 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8192 | } |
| 8193 | return esn; |
| 8194 | } finally { |
| 8195 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8196 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8197 | } |
| 8198 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8199 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8200 | * Return the Preferred Roaming List Version. |
| 8201 | * |
| 8202 | * @param subId the subscription ID that this request applies to. |
| 8203 | * @return PRLVersion or null if error. |
| 8204 | */ |
| 8205 | @Override |
| 8206 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8207 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8208 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8209 | |
| 8210 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8211 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8212 | if (phone == null) { |
| 8213 | return null; |
| 8214 | } |
| 8215 | String cdmaPrlVersion = null; |
| 8216 | try { |
| 8217 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8218 | } catch (Exception e) { |
| 8219 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8220 | } |
| 8221 | return cdmaPrlVersion; |
| 8222 | } finally { |
| 8223 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8224 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8225 | } |
| 8226 | |
| 8227 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8228 | * Get snapshot of Telephony histograms |
| 8229 | * @return List of Telephony histograms |
| 8230 | * @hide |
| 8231 | */ |
| 8232 | @Override |
| 8233 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8234 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8235 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8236 | |
| 8237 | final long identity = Binder.clearCallingIdentity(); |
| 8238 | try { |
| 8239 | return RIL.getTelephonyRILTimingHistograms(); |
| 8240 | } finally { |
| 8241 | Binder.restoreCallingIdentity(identity); |
| 8242 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8243 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8244 | |
| 8245 | /** |
| 8246 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8247 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8248 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8249 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8250 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8251 | * @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] | 8252 | */ |
| 8253 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8254 | @TelephonyManager.SetCarrierRestrictionResult |
| 8255 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8256 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8257 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8258 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8259 | if (carrierRestrictionRules == null) { |
| 8260 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8261 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8262 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8263 | final long identity = Binder.clearCallingIdentity(); |
| 8264 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8265 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8266 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8267 | } finally { |
| 8268 | Binder.restoreCallingIdentity(identity); |
| 8269 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8270 | } |
| 8271 | |
| 8272 | /** |
| 8273 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8274 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8275 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8276 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8277 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8278 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8279 | */ |
| 8280 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8281 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8282 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8283 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8284 | |
| 8285 | final long identity = Binder.clearCallingIdentity(); |
| 8286 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8287 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8288 | if (response instanceof CarrierRestrictionRules) { |
| 8289 | return (CarrierRestrictionRules) response; |
| 8290 | } |
| 8291 | // Response is an Exception of some kind, |
| 8292 | // which is signalled to the user as a NULL retval |
| 8293 | return null; |
| 8294 | } catch (Exception e) { |
| 8295 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8296 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8297 | } finally { |
| 8298 | Binder.restoreCallingIdentity(identity); |
| 8299 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8300 | } |
| 8301 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8302 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8303 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8304 | * @param subId the subscription ID that this action applies to. |
| 8305 | * @param enabled control enable or disable radio. |
| 8306 | * {@hide} |
| 8307 | */ |
| 8308 | @Override |
| 8309 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8310 | enforceModifyPermission(); |
| 8311 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8312 | |
| 8313 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8314 | if (phone == null) { |
| 8315 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8316 | return; |
| 8317 | } |
| 8318 | try { |
| 8319 | phone.carrierActionSetRadioEnabled(enabled); |
| 8320 | } catch (Exception e) { |
| 8321 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8322 | } finally { |
| 8323 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8324 | } |
| 8325 | } |
| 8326 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8327 | /** |
Sooraj Sasindran | bf5c79c | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8328 | * Enable or disable Voice over NR (VoNR) |
| 8329 | * @param subId the subscription ID that this action applies to. |
| 8330 | * @param enabled enable or disable VoNR. |
| 8331 | * @return operation result. |
| 8332 | */ |
| 8333 | @Override |
| 8334 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8335 | enforceModifyPermission(); |
| 8336 | final Phone phone = getPhone(subId); |
| 8337 | |
| 8338 | final long identity = Binder.clearCallingIdentity(); |
| 8339 | if (phone == null) { |
| 8340 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8341 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8342 | } |
| 8343 | |
| 8344 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8345 | try { |
| 8346 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8347 | workSource); |
| 8348 | if (DBG) log("setVoNrEnabled result: " + result); |
| 8349 | return result; |
| 8350 | } finally { |
| 8351 | Binder.restoreCallingIdentity(identity); |
| 8352 | } |
| 8353 | } |
| 8354 | |
| 8355 | /** |
| 8356 | * Is voice over NR enabled |
| 8357 | * @return true if VoNR is enabled else false |
| 8358 | */ |
| 8359 | @Override |
| 8360 | public boolean isVoNrEnabled(int subId) { |
| 8361 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8362 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8363 | final long identity = Binder.clearCallingIdentity(); |
| 8364 | try { |
| 8365 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8366 | null, subId, workSource); |
| 8367 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8368 | return isEnabled; |
| 8369 | } finally { |
| 8370 | Binder.restoreCallingIdentity(identity); |
| 8371 | } |
| 8372 | } |
| 8373 | |
| 8374 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8375 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8376 | * network status based on which carrier apps could apply actions accordingly, |
| 8377 | * enable/disable default url handler for example. |
| 8378 | * |
| 8379 | * @param subId the subscription ID that this action applies to. |
| 8380 | * @param report control start/stop reporting the default network status. |
| 8381 | * {@hide} |
| 8382 | */ |
| 8383 | @Override |
| 8384 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8385 | enforceModifyPermission(); |
| 8386 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8387 | |
| 8388 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8389 | if (phone == null) { |
| 8390 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8391 | return; |
| 8392 | } |
| 8393 | try { |
| 8394 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8395 | } catch (Exception e) { |
| 8396 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8397 | } finally { |
| 8398 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8399 | } |
| 8400 | } |
| 8401 | |
| 8402 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8403 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8404 | * @param subId the subscription ID that this action applies to. |
| 8405 | * {@hide} |
| 8406 | */ |
| 8407 | @Override |
| 8408 | public void carrierActionResetAll(int subId) { |
| 8409 | enforceModifyPermission(); |
| 8410 | final Phone phone = getPhone(subId); |
| 8411 | if (phone == null) { |
| 8412 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8413 | return; |
| 8414 | } |
| 8415 | try { |
| 8416 | phone.carrierActionResetAll(); |
| 8417 | } catch (Exception e) { |
| 8418 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8419 | } |
| 8420 | } |
| 8421 | |
| 8422 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8423 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8424 | * bug report is being generated. |
| 8425 | */ |
| 8426 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8427 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8428 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8429 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8430 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8431 | + Binder.getCallingPid() |
| 8432 | + ", uid=" + Binder.getCallingUid() |
| 8433 | + "without permission " |
| 8434 | + android.Manifest.permission.DUMP); |
| 8435 | return; |
| 8436 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8437 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8438 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8439 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8440 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8441 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8442 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8443 | @NonNull String[] args) { |
| 8444 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8445 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8446 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8447 | } |
| 8448 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8449 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8450 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8451 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8452 | * @param reason the reason the data enable change is taking place |
| 8453 | * @param enabled True if enabling the data, otherwise disabling. |
| 8454 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8455 | */ |
| 8456 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8457 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8458 | boolean enabled) { |
| 8459 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8460 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8461 | try { |
| 8462 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8463 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8464 | } catch (SecurityException se) { |
| 8465 | enforceModifyPermission(); |
| 8466 | } |
| 8467 | } else { |
| 8468 | enforceModifyPermission(); |
| 8469 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8470 | |
| 8471 | final long identity = Binder.clearCallingIdentity(); |
| 8472 | try { |
| 8473 | Phone phone = getPhone(subId); |
| 8474 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8475 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8476 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8477 | } else { |
| 8478 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 8479 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8480 | } |
| 8481 | } finally { |
| 8482 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8483 | } |
| 8484 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8485 | |
| 8486 | /** |
| 8487 | * Get Client request stats |
| 8488 | * @return List of Client Request Stats |
| 8489 | * @hide |
| 8490 | */ |
| 8491 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8492 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8493 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8494 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8495 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8496 | return null; |
| 8497 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8498 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8499 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8500 | final long identity = Binder.clearCallingIdentity(); |
| 8501 | try { |
| 8502 | if (phone != null) { |
| 8503 | return phone.getClientRequestStats(); |
| 8504 | } |
| 8505 | |
| 8506 | return null; |
| 8507 | } finally { |
| 8508 | Binder.restoreCallingIdentity(identity); |
| 8509 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8510 | } |
| 8511 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8512 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8513 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8514 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8515 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8516 | |
| 8517 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8518 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8519 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8520 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8521 | * @param state State of SIM (power down, power up, pass through) |
| 8522 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8523 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8524 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8525 | * |
| 8526 | **/ |
| 8527 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8528 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8529 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8530 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8531 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8532 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8533 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8534 | final long identity = Binder.clearCallingIdentity(); |
| 8535 | try { |
| 8536 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8537 | phone.setSimPowerState(state, null, workSource); |
| 8538 | } |
| 8539 | } finally { |
| 8540 | Binder.restoreCallingIdentity(identity); |
| 8541 | } |
| 8542 | } |
| 8543 | |
| 8544 | /** |
| 8545 | * Set SIM card power state. |
| 8546 | * |
| 8547 | * @param slotIndex SIM slot id. |
| 8548 | * @param state State of SIM (power down, power up, pass through) |
| 8549 | * @param callback callback to trigger after success or failure |
| 8550 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8551 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8552 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8553 | * |
| 8554 | **/ |
| 8555 | @Override |
| 8556 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8557 | IIntegerConsumer callback) { |
| 8558 | enforceModifyPermission(); |
| 8559 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8560 | |
| 8561 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8562 | |
| 8563 | final long identity = Binder.clearCallingIdentity(); |
| 8564 | try { |
| 8565 | if (phone != null) { |
| 8566 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8567 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8568 | } |
| 8569 | } finally { |
| 8570 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8571 | } |
| 8572 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8573 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8574 | private boolean isUssdApiAllowed(int subId) { |
| 8575 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8576 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8577 | if (configManager == null) { |
| 8578 | return false; |
| 8579 | } |
| 8580 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8581 | if (pb == null) { |
| 8582 | return false; |
| 8583 | } |
| 8584 | return pb.getBoolean( |
| 8585 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8586 | } |
| 8587 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8588 | /** |
| 8589 | * Check if phone is in emergency callback mode |
| 8590 | * @return true if phone is in emergency callback mode |
| 8591 | * @param subId sub id |
| 8592 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8593 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8594 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8595 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8596 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8597 | |
| 8598 | final long identity = Binder.clearCallingIdentity(); |
| 8599 | try { |
| 8600 | if (phone != null) { |
| 8601 | return phone.isInEcm(); |
| 8602 | } else { |
| 8603 | return false; |
| 8604 | } |
| 8605 | } finally { |
| 8606 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8607 | } |
| 8608 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8609 | |
| 8610 | /** |
| 8611 | * Get the current signal strength information for the given subscription. |
| 8612 | * Because this information is not updated when the device is in a low power state |
| 8613 | * it should not be relied-upon to be current. |
| 8614 | * @param subId Subscription index |
| 8615 | * @return the most recent cached signal strength info from the modem |
| 8616 | */ |
| 8617 | @Override |
| 8618 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8619 | final long identity = Binder.clearCallingIdentity(); |
| 8620 | try { |
| 8621 | Phone p = getPhone(subId); |
| 8622 | if (p == null) { |
| 8623 | return null; |
| 8624 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8625 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8626 | return p.getSignalStrength(); |
| 8627 | } finally { |
| 8628 | Binder.restoreCallingIdentity(identity); |
| 8629 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8630 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8631 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8632 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8633 | * Get the current modem radio state for the given slot. |
| 8634 | * @param slotIndex slot index. |
| 8635 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8636 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8637 | * @return the current radio power state from the modem |
| 8638 | */ |
| 8639 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8640 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8641 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8642 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8643 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8644 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8645 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8646 | } |
| 8647 | |
| 8648 | final long identity = Binder.clearCallingIdentity(); |
| 8649 | try { |
| 8650 | return phone.getRadioPowerState(); |
| 8651 | } finally { |
| 8652 | Binder.restoreCallingIdentity(identity); |
| 8653 | } |
| 8654 | } |
| 8655 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8656 | } |
| 8657 | |
| 8658 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8659 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8660 | * |
| 8661 | * <p>Requires one of the following permissions: |
| 8662 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8663 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8664 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8665 | * privileges. |
| 8666 | * |
| 8667 | * @param subId subscription id |
| 8668 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8669 | * {@code false}. |
| 8670 | */ |
| 8671 | @Override |
| 8672 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8673 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8674 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8675 | try { |
| 8676 | mApp.enforceCallingOrSelfPermission( |
| 8677 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8678 | functionName); |
| 8679 | } catch (Exception e) { |
| 8680 | mApp.enforceCallingOrSelfPermission( |
| 8681 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 8682 | } |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8683 | } catch (Exception e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8684 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8685 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8686 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8687 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8688 | boolean isEnabled = false; |
| 8689 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8690 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8691 | Phone phone = getPhone(subId); |
| 8692 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8693 | } finally { |
| 8694 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8695 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8696 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8697 | } |
| 8698 | |
| 8699 | |
| 8700 | /** |
| 8701 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8702 | * |
| 8703 | * <p> Requires permission: |
| 8704 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8705 | * privileges. |
| 8706 | * |
| 8707 | * @param subId subscription id |
| 8708 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8709 | */ |
| 8710 | @Override |
| 8711 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8712 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8713 | mApp, subId, "setDataRoamingEnabled"); |
| 8714 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8715 | final long identity = Binder.clearCallingIdentity(); |
| 8716 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8717 | Phone phone = getPhone(subId); |
| 8718 | if (phone != null) { |
| 8719 | phone.setDataRoamingEnabled(isEnabled); |
| 8720 | } |
| 8721 | } finally { |
| 8722 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8723 | } |
| 8724 | } |
| 8725 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8726 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8727 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8728 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8729 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8730 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8731 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8732 | boolean isAllowed = true; |
| 8733 | final long identity = Binder.clearCallingIdentity(); |
| 8734 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8735 | Phone phone = getPhone(subId); |
| 8736 | if (phone != null) { |
| 8737 | isAllowed = phone.isCspPlmnEnabled(); |
| 8738 | } |
| 8739 | } finally { |
| 8740 | Binder.restoreCallingIdentity(identity); |
| 8741 | } |
| 8742 | return isAllowed; |
| 8743 | } |
| 8744 | |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8745 | private boolean haveCarrierPrivilegeAccess(UiccCard card, String callingPackage) { |
| 8746 | // TODO once MEP API refactoring CL is merged, loop port list from UiccCardInfo, |
| 8747 | // and if find the matching UiccPort by UiccController.getUiccPortForSlot(slot, portIdx) |
| 8748 | // Update each UiccPort object based on privilege access |
| 8749 | UiccPort[] uiccPorts = card.getUiccPortList(); |
| 8750 | for (UiccPort port : uiccPorts) { |
| 8751 | UiccProfile profile = port.getUiccProfile(); |
| 8752 | if (profile == null || |
| 8753 | profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8754 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8755 | return false; |
| 8756 | } |
| 8757 | } |
| 8758 | return true; |
| 8759 | } |
| 8760 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8761 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8762 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8763 | // Verify that tha callingPackage belongs to the calling UID |
| 8764 | mApp.getSystemService(AppOpsManager.class) |
| 8765 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8766 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8767 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8768 | try { |
| 8769 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8770 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8771 | } catch (SecurityException e) { |
| 8772 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8773 | // has carrier privileges on an active UICC |
| 8774 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8775 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8776 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8777 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8778 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8779 | |
| 8780 | final long identity = Binder.clearCallingIdentity(); |
| 8781 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8782 | UiccController uiccController = UiccController.getInstance(); |
| 8783 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8784 | if (hasReadPermission) { |
| 8785 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8786 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8787 | |
| 8788 | // Remove private info if the caller doesn't have access |
| 8789 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8790 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8791 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8792 | // is available |
| 8793 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8794 | // TODO remove card.getUiccPortList().length once MEP API refactoring CL is merged |
| 8795 | // Get UiccPortInfo from CardInfo and process further based on each UiccPort |
| 8796 | if (card == null || card.getUiccPortList().length == 0) { |
| 8797 | // assume no access if the card or ports are unavailable |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8798 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8799 | continue; |
| 8800 | } |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8801 | |
| 8802 | if (haveCarrierPrivilegeAccess(card, callingPackage)) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8803 | filteredInfos.add(cardInfo); |
| 8804 | } else { |
| 8805 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8806 | } |
| 8807 | } |
| 8808 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8809 | } finally { |
| 8810 | Binder.restoreCallingIdentity(identity); |
| 8811 | } |
| 8812 | } |
| 8813 | |
| 8814 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8815 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8816 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8817 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8818 | final long identity = Binder.clearCallingIdentity(); |
| 8819 | try { |
| 8820 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8821 | if (slots == null) { |
| 8822 | Rlog.i(LOG_TAG, "slots is null."); |
| 8823 | return null; |
| 8824 | } |
| 8825 | |
| 8826 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8827 | for (int i = 0; i < slots.length; i++) { |
| 8828 | UiccSlot slot = slots[i]; |
| 8829 | if (slot == null) { |
| 8830 | continue; |
| 8831 | } |
| 8832 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8833 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8834 | UiccCard card = slot.getUiccCard(); |
| 8835 | if (card != null) { |
| 8836 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8837 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8838 | cardId = slot.getEid(); |
| 8839 | if (TextUtils.isEmpty(cardId)) { |
| 8840 | cardId = slot.getIccId(); |
| 8841 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8842 | } |
| 8843 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8844 | if (cardId != null) { |
| 8845 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8846 | // if cardId is an EID, it's all digits so this is fine |
| 8847 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8848 | } |
| 8849 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8850 | int cardState = 0; |
| 8851 | switch (slot.getCardState()) { |
| 8852 | case CARDSTATE_ABSENT: |
| 8853 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8854 | break; |
| 8855 | case CARDSTATE_PRESENT: |
| 8856 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8857 | break; |
| 8858 | case CARDSTATE_ERROR: |
| 8859 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8860 | break; |
| 8861 | case CARDSTATE_RESTRICTED: |
| 8862 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8863 | break; |
| 8864 | default: |
| 8865 | break; |
| 8866 | |
| 8867 | } |
| 8868 | |
| 8869 | infos[i] = new UiccSlotInfo( |
| 8870 | slot.isActive(), |
| 8871 | slot.isEuicc(), |
| 8872 | cardId, |
| 8873 | cardState, |
| 8874 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8875 | slot.isExtendedApduSupported(), |
| 8876 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8877 | } |
| 8878 | return infos; |
| 8879 | } finally { |
| 8880 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8881 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8882 | } |
| 8883 | |
| 8884 | @Override |
| 8885 | public boolean switchSlots(int[] physicalSlots) { |
| 8886 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8887 | |
| 8888 | final long identity = Binder.clearCallingIdentity(); |
| 8889 | try { |
| 8890 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8891 | } finally { |
| 8892 | Binder.restoreCallingIdentity(identity); |
| 8893 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8894 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8895 | |
| 8896 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8897 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8898 | final long identity = Binder.clearCallingIdentity(); |
| 8899 | try { |
| 8900 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8901 | } finally { |
| 8902 | Binder.restoreCallingIdentity(identity); |
| 8903 | } |
| 8904 | } |
| 8905 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8906 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8907 | * A test API to reload the UICC profile. |
| 8908 | * |
| 8909 | * <p>Requires that the calling app has permission |
| 8910 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8911 | * @hide |
| 8912 | */ |
| 8913 | @Override |
| 8914 | public void refreshUiccProfile(int subId) { |
| 8915 | enforceModifyPermission(); |
| 8916 | |
| 8917 | final long identity = Binder.clearCallingIdentity(); |
| 8918 | try { |
| 8919 | Phone phone = getPhone(subId); |
| 8920 | if (phone == null) { |
| 8921 | return; |
| 8922 | } |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8923 | UiccPort uiccPort = phone.getUiccPort(); |
| 8924 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8925 | return; |
| 8926 | } |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8927 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8928 | if (uiccProfile == null) { |
| 8929 | return; |
| 8930 | } |
| 8931 | uiccProfile.refresh(); |
| 8932 | } finally { |
| 8933 | Binder.restoreCallingIdentity(identity); |
| 8934 | } |
| 8935 | } |
| 8936 | |
| 8937 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8938 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8939 | */ |
| 8940 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8941 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8942 | } |
| 8943 | |
| 8944 | /** |
| 8945 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8946 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8947 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8948 | */ |
| 8949 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8950 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8951 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8952 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8953 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8954 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8955 | return isDataRoamingEnabled; |
| 8956 | } |
| 8957 | |
| 8958 | /** |
| 8959 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8960 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8961 | */ |
| 8962 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8963 | List<Integer> list = TelephonyProperties.default_network(); |
| 8964 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8965 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8966 | return list.get(phoneId); |
| 8967 | } |
| 8968 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8969 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8970 | |
| 8971 | @Override |
| 8972 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8973 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8974 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8975 | |
| 8976 | final long identity = Binder.clearCallingIdentity(); |
| 8977 | try { |
| 8978 | final Phone phone = getPhone(subId); |
| 8979 | if (phone == null) { |
| 8980 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8981 | return; |
| 8982 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8983 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8984 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8985 | if (carrierPrivilegeRules == null) { |
| 8986 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8987 | } else { |
| 8988 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8989 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8990 | } finally { |
| 8991 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8992 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8993 | } |
| 8994 | |
| 8995 | @Override |
| 8996 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8997 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8998 | |
| 8999 | final long identity = Binder.clearCallingIdentity(); |
| 9000 | try { |
| 9001 | final Phone phone = getPhone(subId); |
| 9002 | if (phone == null) { |
| 9003 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9004 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9005 | } |
| 9006 | return phone.getCarrierIdListVersion(); |
| 9007 | } finally { |
| 9008 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9009 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9010 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9011 | |
| 9012 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9013 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9014 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9015 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9016 | mApp, subId, callingPackage, callingFeatureId, |
| 9017 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9018 | return -1; |
| 9019 | } |
| 9020 | |
| 9021 | final long identity = Binder.clearCallingIdentity(); |
| 9022 | try { |
| 9023 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9024 | } finally { |
| 9025 | Binder.restoreCallingIdentity(identity); |
| 9026 | } |
| 9027 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9028 | |
| 9029 | @Override |
| 9030 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9031 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9032 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9033 | mApp, subId, "getCdmaRoamingMode"); |
| 9034 | |
| 9035 | final long identity = Binder.clearCallingIdentity(); |
| 9036 | try { |
| 9037 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9038 | } finally { |
| 9039 | Binder.restoreCallingIdentity(identity); |
| 9040 | } |
| 9041 | } |
| 9042 | |
| 9043 | @Override |
| 9044 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9045 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9046 | mApp, subId, "setCdmaRoamingMode"); |
| 9047 | |
| 9048 | final long identity = Binder.clearCallingIdentity(); |
| 9049 | try { |
| 9050 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9051 | } finally { |
| 9052 | Binder.restoreCallingIdentity(identity); |
| 9053 | } |
| 9054 | } |
| 9055 | |
| 9056 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9057 | public int getCdmaSubscriptionMode(int subId) { |
| 9058 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9059 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9060 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9061 | |
| 9062 | final long identity = Binder.clearCallingIdentity(); |
| 9063 | try { |
| 9064 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9065 | } finally { |
| 9066 | Binder.restoreCallingIdentity(identity); |
| 9067 | } |
| 9068 | } |
| 9069 | |
| 9070 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9071 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9072 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9073 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9074 | |
| 9075 | final long identity = Binder.clearCallingIdentity(); |
| 9076 | try { |
| 9077 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9078 | } finally { |
| 9079 | Binder.restoreCallingIdentity(identity); |
| 9080 | } |
| 9081 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9082 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9083 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9084 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9085 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9086 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9087 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9088 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9089 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9090 | } |
| 9091 | final long identity = Binder.clearCallingIdentity(); |
| 9092 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9093 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9094 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9095 | if (phone.getEmergencyNumberTracker() != null |
| 9096 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9097 | emergencyNumberListInternal.put( |
| 9098 | phone.getSubId(), |
| 9099 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9100 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9101 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9102 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9103 | } finally { |
| 9104 | Binder.restoreCallingIdentity(identity); |
| 9105 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9106 | } |
| 9107 | |
| 9108 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9109 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9110 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9111 | if (!exactMatch) { |
| 9112 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9113 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9114 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9115 | } |
| 9116 | final long identity = Binder.clearCallingIdentity(); |
| 9117 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9118 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9119 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9120 | && phone.getEmergencyNumberTracker() |
| 9121 | .isEmergencyNumber(number, exactMatch)) { |
| 9122 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9123 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9124 | } |
| 9125 | return false; |
| 9126 | } finally { |
| 9127 | Binder.restoreCallingIdentity(identity); |
| 9128 | } |
| 9129 | } |
| 9130 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9131 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9132 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9133 | */ |
| 9134 | @Override |
| 9135 | public void startEmergencyCallbackMode() { |
| 9136 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9137 | "startEmergencyCallbackMode"); |
| 9138 | enforceModifyPermission(); |
| 9139 | final long identity = Binder.clearCallingIdentity(); |
| 9140 | try { |
| 9141 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9142 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9143 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9144 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9145 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9146 | gsmCdmaPhone.obtainMessage( |
| 9147 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9148 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9149 | } |
| 9150 | } |
| 9151 | } finally { |
| 9152 | Binder.restoreCallingIdentity(identity); |
| 9153 | } |
| 9154 | } |
| 9155 | |
| 9156 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9157 | * Update emergency number list for test mode. |
| 9158 | */ |
| 9159 | @Override |
| 9160 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9161 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9162 | "updateEmergencyNumberListTestMode"); |
| 9163 | |
| 9164 | final long identity = Binder.clearCallingIdentity(); |
| 9165 | try { |
| 9166 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9167 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9168 | if (tracker != null) { |
| 9169 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9170 | } |
| 9171 | } |
| 9172 | } finally { |
| 9173 | Binder.restoreCallingIdentity(identity); |
| 9174 | } |
| 9175 | } |
| 9176 | |
| 9177 | /** |
| 9178 | * Get the full emergency number list for test mode. |
| 9179 | */ |
| 9180 | @Override |
| 9181 | public List<String> getEmergencyNumberListTestMode() { |
| 9182 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9183 | "getEmergencyNumberListTestMode"); |
| 9184 | |
| 9185 | final long identity = Binder.clearCallingIdentity(); |
| 9186 | try { |
| 9187 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9188 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9189 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9190 | if (tracker != null) { |
| 9191 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9192 | emergencyNumbers.add(num.getNumber()); |
| 9193 | } |
| 9194 | } |
| 9195 | } |
| 9196 | return new ArrayList<>(emergencyNumbers); |
| 9197 | } finally { |
| 9198 | Binder.restoreCallingIdentity(identity); |
| 9199 | } |
| 9200 | } |
| 9201 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9202 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9203 | public int getEmergencyNumberDbVersion(int subId) { |
| 9204 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9205 | |
| 9206 | final long identity = Binder.clearCallingIdentity(); |
| 9207 | try { |
| 9208 | final Phone phone = getPhone(subId); |
| 9209 | if (phone == null) { |
| 9210 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9211 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9212 | } |
| 9213 | return phone.getEmergencyNumberDbVersion(); |
| 9214 | } finally { |
| 9215 | Binder.restoreCallingIdentity(identity); |
| 9216 | } |
| 9217 | } |
| 9218 | |
| 9219 | @Override |
| 9220 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9221 | enforceModifyPermission(); |
| 9222 | |
| 9223 | final long identity = Binder.clearCallingIdentity(); |
| 9224 | try { |
| 9225 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9226 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9227 | if (tracker != null) { |
| 9228 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9229 | } |
| 9230 | } |
| 9231 | } finally { |
| 9232 | Binder.restoreCallingIdentity(identity); |
| 9233 | } |
| 9234 | } |
| 9235 | |
| 9236 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9237 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9238 | enforceActiveEmergencySessionPermission(); |
| 9239 | |
| 9240 | final long identity = Binder.clearCallingIdentity(); |
| 9241 | try { |
| 9242 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9243 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9244 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9245 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9246 | } |
| 9247 | } |
| 9248 | } finally { |
| 9249 | Binder.restoreCallingIdentity(identity); |
| 9250 | } |
| 9251 | } |
| 9252 | |
| 9253 | @Override |
| 9254 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9255 | enforceActiveEmergencySessionPermission(); |
| 9256 | |
| 9257 | final long identity = Binder.clearCallingIdentity(); |
| 9258 | try { |
| 9259 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9260 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9261 | if (tracker != null) { |
| 9262 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9263 | } |
| 9264 | } |
| 9265 | } finally { |
| 9266 | Binder.restoreCallingIdentity(identity); |
| 9267 | } |
| 9268 | } |
| 9269 | |
| 9270 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9271 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9272 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9273 | Phone phone = getPhone(subId); |
| 9274 | if (phone == null) { |
| 9275 | return null; |
| 9276 | } |
| 9277 | final long identity = Binder.clearCallingIdentity(); |
| 9278 | try { |
| 9279 | UiccProfile profile = UiccController.getInstance() |
| 9280 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9281 | if (profile != null) { |
| 9282 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9283 | } |
| 9284 | } finally { |
| 9285 | Binder.restoreCallingIdentity(identity); |
| 9286 | } |
| 9287 | return null; |
| 9288 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9289 | |
| 9290 | /** |
| 9291 | * Enable or disable a modem stack. |
| 9292 | */ |
| 9293 | @Override |
| 9294 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9295 | enforceModifyPermission(); |
| 9296 | |
| 9297 | final long identity = Binder.clearCallingIdentity(); |
| 9298 | try { |
| 9299 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9300 | if (phone == null) { |
| 9301 | return false; |
| 9302 | } else { |
| 9303 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9304 | } |
| 9305 | } finally { |
| 9306 | Binder.restoreCallingIdentity(identity); |
| 9307 | } |
| 9308 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9309 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9310 | /** |
| 9311 | * Whether a modem stack is enabled or not. |
| 9312 | */ |
| 9313 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9314 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9315 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9316 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9317 | if (phone == null) return false; |
| 9318 | |
| 9319 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9320 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9321 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9322 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9323 | } |
| 9324 | |
| 9325 | final long identity = Binder.clearCallingIdentity(); |
| 9326 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9327 | try { |
| 9328 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9329 | } catch (NoSuchElementException ex) { |
| 9330 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9331 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9332 | } finally { |
| 9333 | Binder.restoreCallingIdentity(identity); |
| 9334 | } |
| 9335 | } |
| 9336 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9337 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9338 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9339 | enforceModifyPermission(); |
| 9340 | |
| 9341 | final long identity = Binder.clearCallingIdentity(); |
| 9342 | try { |
| 9343 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9344 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9345 | .commit(); |
| 9346 | } finally { |
| 9347 | Binder.restoreCallingIdentity(identity); |
| 9348 | } |
| 9349 | } |
| 9350 | |
| 9351 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9352 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9353 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9354 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9355 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9356 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9357 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9358 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9359 | |
| 9360 | final long identity = Binder.clearCallingIdentity(); |
| 9361 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9362 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9363 | } finally { |
| 9364 | Binder.restoreCallingIdentity(identity); |
| 9365 | } |
| 9366 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9367 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9368 | @TelephonyManager.IsMultiSimSupportedResult |
| 9369 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9370 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9371 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9372 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9373 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9374 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9375 | } |
| 9376 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9377 | // supported by the modem, indicate that it is restricted. |
| 9378 | PhoneCapability staticCapability = |
| 9379 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9380 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9381 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9382 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9383 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9384 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9385 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9386 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9387 | } |
| 9388 | // Check if support of multiple SIMs is restricted by carrier |
| 9389 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9390 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9391 | } |
| 9392 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9393 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9394 | } |
| 9395 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9396 | /** |
| 9397 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9398 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9399 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9400 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9401 | * @param numOfSims number of active sims we want to switch to |
| 9402 | */ |
| 9403 | @Override |
| 9404 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9405 | if (numOfSims == 1) { |
| 9406 | enforceModifyPermission(); |
| 9407 | } else { |
| 9408 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9409 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9410 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9411 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9412 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9413 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9414 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9415 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9416 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9417 | return; |
| 9418 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9419 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9420 | } finally { |
| 9421 | Binder.restoreCallingIdentity(identity); |
| 9422 | } |
| 9423 | } |
| 9424 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9425 | @Override |
| 9426 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9427 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9428 | Phone phone = getPhone(subId); |
| 9429 | if (phone == null) { |
| 9430 | return false; |
| 9431 | } |
| 9432 | final long identity = Binder.clearCallingIdentity(); |
| 9433 | try { |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9434 | UiccPort uiccPort = phone.getUiccPort(); |
| 9435 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9436 | return false; |
| 9437 | } |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9438 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9439 | if (uiccProfile == null) { |
| 9440 | return false; |
| 9441 | } |
| 9442 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9443 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9444 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9445 | } |
| 9446 | return false; |
| 9447 | } finally { |
| 9448 | Binder.restoreCallingIdentity(identity); |
| 9449 | } |
| 9450 | } |
| 9451 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9452 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9453 | * Get whether making changes to modem configurations will trigger reboot. |
| 9454 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9455 | */ |
| 9456 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9457 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9458 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9459 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9460 | mApp, subId, callingPackage, callingFeatureId, |
| 9461 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9462 | return false; |
| 9463 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9464 | final long identity = Binder.clearCallingIdentity(); |
| 9465 | try { |
| 9466 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9467 | } finally { |
| 9468 | Binder.restoreCallingIdentity(identity); |
| 9469 | } |
| 9470 | } |
| 9471 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9472 | private void updateModemStateMetrics() { |
| 9473 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9474 | // TODO: check the state for each modem if the api is ready. |
| 9475 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9476 | } |
| 9477 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9478 | @Override |
| 9479 | public int[] getSlotsMapping() { |
| 9480 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 9481 | |
| 9482 | final long identity = Binder.clearCallingIdentity(); |
| 9483 | try { |
| 9484 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 9485 | // All logical slots should have a mapping to a physical slot. |
| 9486 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 9487 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 9488 | for (int i = 0; i < slotInfos.length; i++) { |
| 9489 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 9490 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 9491 | } |
| 9492 | } |
| 9493 | return logicalSlotsMapping; |
| 9494 | } finally { |
| 9495 | Binder.restoreCallingIdentity(identity); |
| 9496 | } |
| 9497 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9498 | |
| 9499 | /** |
| 9500 | * Get the IRadio HAL Version |
| 9501 | */ |
| 9502 | @Override |
| 9503 | public int getRadioHalVersion() { |
| 9504 | Phone phone = getDefaultPhone(); |
| 9505 | if (phone == null) return -1; |
| 9506 | HalVersion hv = phone.getHalVersion(); |
| 9507 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9508 | return hv.major * 100 + hv.minor; |
| 9509 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9510 | |
| 9511 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9512 | * Get the current calling package name. |
| 9513 | * @return the current calling package name |
| 9514 | */ |
| 9515 | @Override |
| 9516 | public String getCurrentPackageName() { |
| 9517 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9518 | } |
| 9519 | |
| 9520 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9521 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9522 | * corresponding network requests on a subId. |
| 9523 | * |
| 9524 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9525 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9526 | * 2) APN is un-metered for this subscription, or |
| 9527 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9528 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9529 | * |
| 9530 | * @return whether data is allowed for a apn type. |
| 9531 | * |
| 9532 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9533 | */ |
| 9534 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9535 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9536 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9537 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9538 | |
| 9539 | // Now that all security checks passes, perform the operation as ourselves. |
| 9540 | final long identity = Binder.clearCallingIdentity(); |
| 9541 | try { |
| 9542 | Phone phone = getPhone(subId); |
| 9543 | if (phone == null) return false; |
| 9544 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9545 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9546 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9547 | } finally { |
| 9548 | Binder.restoreCallingIdentity(identity); |
| 9549 | } |
| 9550 | } |
| 9551 | |
| 9552 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9553 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9554 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9555 | |
| 9556 | // Now that all security checks passes, perform the operation as ourselves. |
| 9557 | final long identity = Binder.clearCallingIdentity(); |
| 9558 | try { |
| 9559 | Phone phone = getPhone(subId); |
| 9560 | if (phone == null) return true; // By default return true. |
| 9561 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9562 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9563 | } finally { |
| 9564 | Binder.restoreCallingIdentity(identity); |
| 9565 | } |
| 9566 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9567 | |
| 9568 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9569 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9570 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9571 | enforceModifyPermission(); |
| 9572 | long token = Binder.clearCallingIdentity(); |
| 9573 | try { |
| 9574 | Phone phone = getPhone(subscriptionId); |
| 9575 | if (phone == null) { |
| 9576 | try { |
| 9577 | if (resultCallback != null) { |
| 9578 | resultCallback.accept(false); |
| 9579 | } |
| 9580 | } catch (RemoteException e) { |
| 9581 | // ignore |
| 9582 | } |
| 9583 | return; |
| 9584 | } |
| 9585 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9586 | Pair.create(specifiers, (x) -> { |
| 9587 | try { |
| 9588 | if (resultCallback != null) { |
| 9589 | resultCallback.accept(x); |
| 9590 | } |
| 9591 | } catch (RemoteException e) { |
| 9592 | // ignore |
| 9593 | } |
| 9594 | }); |
| 9595 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9596 | } finally { |
| 9597 | Binder.restoreCallingIdentity(token); |
| 9598 | } |
| 9599 | } |
| 9600 | |
| 9601 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9602 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9603 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9604 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9605 | mApp, subId, "getSystemSelectionChannels"); |
| 9606 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9607 | final long identity = Binder.clearCallingIdentity(); |
| 9608 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 9609 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 9610 | if (result instanceof IllegalStateException) { |
| 9611 | throw (IllegalStateException) result; |
| 9612 | } |
| 9613 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9614 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9615 | return specifiers; |
| 9616 | } finally { |
| 9617 | Binder.restoreCallingIdentity(identity); |
| 9618 | } |
| 9619 | } |
| 9620 | |
| 9621 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9622 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9623 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9624 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9625 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9626 | if (iccRecords == null) { |
| 9627 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9628 | return false; |
| 9629 | } |
| 9630 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9631 | } |
| 9632 | |
| 9633 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9634 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9635 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9636 | if (callingPackage == null) { |
| 9637 | callingPackage = getCurrentPackageName(); |
| 9638 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9639 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9640 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9641 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9642 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9643 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9644 | } |
| 9645 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9646 | Intent intent = new Intent(); |
| 9647 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9648 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9649 | // Bring up choose default SMS subscription dialog right now |
| 9650 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9651 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9652 | mApp.startActivity(intent); |
| 9653 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9654 | |
| 9655 | @Override |
| 9656 | public String getMmsUAProfUrl(int subId) { |
| 9657 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9658 | final long identity = Binder.clearCallingIdentity(); |
| 9659 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9660 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9661 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9662 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9663 | return carrierUAProfUrl; |
| 9664 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9665 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9666 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9667 | } finally { |
| 9668 | Binder.restoreCallingIdentity(identity); |
| 9669 | } |
| 9670 | } |
| 9671 | |
| 9672 | @Override |
| 9673 | public String getMmsUserAgent(int subId) { |
| 9674 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9675 | final long identity = Binder.clearCallingIdentity(); |
| 9676 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9677 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9678 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9679 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9680 | return carrierUserAgent; |
| 9681 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9682 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9683 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9684 | } finally { |
| 9685 | Binder.restoreCallingIdentity(identity); |
| 9686 | } |
| 9687 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9688 | |
| 9689 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9690 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9691 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9692 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9693 | final long identity = Binder.clearCallingIdentity(); |
| 9694 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9695 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9696 | if (phone == null) return false; |
| 9697 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9698 | switch (policy) { |
| 9699 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9700 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9701 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9702 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9703 | default: |
| 9704 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9705 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9706 | } finally { |
| 9707 | Binder.restoreCallingIdentity(identity); |
| 9708 | } |
| 9709 | } |
| 9710 | |
| 9711 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9712 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9713 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9714 | enforceModifyPermission(); |
| 9715 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9716 | final long identity = Binder.clearCallingIdentity(); |
| 9717 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9718 | Phone phone = getPhone(subscriptionId); |
| 9719 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9720 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9721 | switch (policy) { |
| 9722 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9723 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9724 | break; |
| 9725 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9726 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9727 | break; |
| 9728 | default: |
| 9729 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9730 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9731 | } finally { |
| 9732 | Binder.restoreCallingIdentity(identity); |
| 9733 | } |
| 9734 | } |
| 9735 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9736 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9737 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9738 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9739 | * otherwise. |
| 9740 | */ |
| 9741 | @Override |
| 9742 | public void setCepEnabled(boolean isCepEnabled) { |
| 9743 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9744 | |
| 9745 | final long identity = Binder.clearCallingIdentity(); |
| 9746 | try { |
| 9747 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9748 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9749 | Phone defaultPhone = phone.getImsPhone(); |
| 9750 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9751 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9752 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9753 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9754 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9755 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9756 | + imsPhone.getMsisdn()); |
| 9757 | } |
| 9758 | } |
| 9759 | } finally { |
| 9760 | Binder.restoreCallingIdentity(identity); |
| 9761 | } |
| 9762 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9763 | |
| 9764 | /** |
| 9765 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9766 | * |
| 9767 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9768 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9769 | * before being read. |
| 9770 | */ |
| 9771 | @Override |
| 9772 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9773 | isCompressed) { |
| 9774 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9775 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9776 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9777 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9778 | } |
| 9779 | if (!isImsAvailableOnDevice()) { |
| 9780 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9781 | "IMS not available on device."); |
| 9782 | } |
| 9783 | |
| 9784 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9785 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9786 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9787 | } finally { |
| 9788 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9789 | } |
| 9790 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9791 | |
| 9792 | @Override |
| 9793 | public boolean isIccLockEnabled(int subId) { |
| 9794 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9795 | |
| 9796 | // Now that all security checks passes, perform the operation as ourselves. |
| 9797 | final long identity = Binder.clearCallingIdentity(); |
| 9798 | try { |
| 9799 | Phone phone = getPhone(subId); |
| 9800 | if (phone != null && phone.getIccCard() != null) { |
| 9801 | return phone.getIccCard().getIccLockEnabled(); |
| 9802 | } else { |
| 9803 | return false; |
| 9804 | } |
| 9805 | } finally { |
| 9806 | Binder.restoreCallingIdentity(identity); |
| 9807 | } |
| 9808 | } |
| 9809 | |
| 9810 | /** |
| 9811 | * Set the ICC pin lock enabled or disabled. |
| 9812 | * |
| 9813 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9814 | * three cases: |
| 9815 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9816 | * successfully. |
| 9817 | * - Positive number and zero for remaining password attempts. |
| 9818 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9819 | * |
| 9820 | */ |
| 9821 | @Override |
| 9822 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9823 | enforceModifyPermission(); |
| 9824 | |
| 9825 | Phone phone = getPhone(subId); |
| 9826 | if (phone == null) { |
| 9827 | return 0; |
| 9828 | } |
| 9829 | // Now that all security checks passes, perform the operation as ourselves. |
| 9830 | final long identity = Binder.clearCallingIdentity(); |
| 9831 | try { |
| 9832 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9833 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9834 | return attemptsRemaining; |
| 9835 | |
| 9836 | } catch (Exception e) { |
| 9837 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9838 | } finally { |
| 9839 | Binder.restoreCallingIdentity(identity); |
| 9840 | } |
| 9841 | return 0; |
| 9842 | } |
| 9843 | |
| 9844 | /** |
| 9845 | * Change the ICC password used in ICC pin lock. |
| 9846 | * |
| 9847 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9848 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9849 | * - Positive number and zero for remaining password attempts. |
| 9850 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9851 | * |
| 9852 | */ |
| 9853 | @Override |
| 9854 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9855 | enforceModifyPermission(); |
| 9856 | |
| 9857 | Phone phone = getPhone(subId); |
| 9858 | if (phone == null) { |
| 9859 | return 0; |
| 9860 | } |
| 9861 | // Now that all security checks passes, perform the operation as ourselves. |
| 9862 | final long identity = Binder.clearCallingIdentity(); |
| 9863 | try { |
| 9864 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9865 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9866 | return attemptsRemaining; |
| 9867 | |
| 9868 | } catch (Exception e) { |
| 9869 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9870 | } finally { |
| 9871 | Binder.restoreCallingIdentity(identity); |
| 9872 | } |
| 9873 | return 0; |
| 9874 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9875 | |
| 9876 | /** |
| 9877 | * Request for receiving user activity notification |
| 9878 | */ |
| 9879 | @Override |
| 9880 | public void requestUserActivityNotification() { |
| 9881 | if (!mNotifyUserActivity.get() |
| 9882 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9883 | mNotifyUserActivity.set(true); |
| 9884 | } |
| 9885 | } |
| 9886 | |
| 9887 | /** |
| 9888 | * Called when userActivity is signalled in the power manager. |
| 9889 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9890 | */ |
| 9891 | @Override |
| 9892 | public void userActivity() { |
| 9893 | // *************************************** |
| 9894 | // * Inherited from PhoneWindowManager * |
| 9895 | // *************************************** |
| 9896 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9897 | // WITH ITS LOCKS HELD. |
| 9898 | // |
| 9899 | // This code must be VERY careful about the locks |
| 9900 | // it acquires. |
| 9901 | // In fact, the current code acquires way too many, |
| 9902 | // and probably has lurking deadlocks. |
| 9903 | |
| 9904 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9905 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9906 | } |
| 9907 | |
| 9908 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9909 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9910 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9911 | } |
| 9912 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9913 | |
| 9914 | @Override |
| 9915 | public boolean canConnectTo5GInDsdsMode() { |
| 9916 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9917 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9918 | |
| 9919 | @Override |
| 9920 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9921 | String callingFeatureId) { |
| 9922 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9923 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9924 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9925 | } |
| 9926 | |
| 9927 | Phone phone = getPhone(subId); |
| 9928 | if (phone == null) { |
| 9929 | throw new RuntimeException("phone is not available"); |
| 9930 | } |
| 9931 | // Now that all security checks passes, perform the operation as ourselves. |
| 9932 | final long identity = Binder.clearCallingIdentity(); |
| 9933 | try { |
| 9934 | return phone.getEquivalentHomePlmns(); |
| 9935 | } finally { |
| 9936 | Binder.restoreCallingIdentity(identity); |
| 9937 | } |
| 9938 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9939 | |
| 9940 | @Override |
| 9941 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 9942 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 9943 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 9944 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9945 | if (radioInterfaceCapabilities == null) { |
| 9946 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9947 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 9948 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9949 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9950 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9951 | @Override |
| 9952 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9953 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9954 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 9955 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9956 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 9957 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9958 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9959 | if (DBG) { |
| 9960 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9961 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9962 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9963 | } |
| 9964 | |
| 9965 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9966 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9967 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9968 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9969 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9970 | if (callback != null) { |
| 9971 | try { |
| 9972 | callback.onAuthenticationFailure( |
| 9973 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9974 | } catch (RemoteException exception) { |
| 9975 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9976 | } |
| 9977 | return; |
| 9978 | } |
| 9979 | } |
| 9980 | |
| 9981 | final long token = Binder.clearCallingIdentity(); |
| 9982 | try { |
| 9983 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9984 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9985 | forceBootStrapping, callback)); |
| 9986 | } finally { |
| 9987 | Binder.restoreCallingIdentity(token); |
| 9988 | } |
| 9989 | } |
| 9990 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9991 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 9992 | * Attempts to set the radio power state for all phones for thermal reason. |
| 9993 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9994 | * requested radio power state will actually be set. See {@link |
| 9995 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9996 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9997 | * @param enable {@code true} if trying to turn radio on. |
| 9998 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9999 | * false}. |
| 10000 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10001 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10002 | boolean isPhoneAvailable = false; |
| 10003 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10004 | Phone phone = PhoneFactory.getPhone(i); |
| 10005 | if (phone != null) { |
| 10006 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 10007 | isPhoneAvailable = true; |
| 10008 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10009 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10010 | |
| 10011 | // return true if successfully informed the phone object about the thermal radio power |
| 10012 | // request. |
| 10013 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10014 | } |
| 10015 | |
| 10016 | private int handleDataThrottlingRequest(int subId, |
| 10017 | DataThrottlingRequest dataThrottlingRequest) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10018 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10019 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10020 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10021 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10022 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10023 | } |
| 10024 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10025 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10026 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10027 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10028 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10029 | } |
| 10030 | |
| 10031 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 10032 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10033 | if (isDataThrottlingSupported) { |
| 10034 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10035 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10036 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10037 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10038 | } else if (thermalMitigationResult |
| 10039 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10040 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10041 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10042 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10043 | } |
| 10044 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10045 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10046 | |
| 10047 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10048 | } |
| 10049 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10050 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10051 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10052 | for (String pckg : context.getResources() |
| 10053 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10054 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10055 | } |
| 10056 | } |
| 10057 | |
| 10058 | return sThermalMitigationAllowlistedPackages; |
| 10059 | } |
| 10060 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10061 | private boolean isAnyPhoneInEmergencyState() { |
| 10062 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10063 | if (tm.isInEmergencyCall()) { |
| 10064 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10065 | return true; |
| 10066 | } |
| 10067 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10068 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10069 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10070 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10071 | + phone.isInEcm()); |
| 10072 | return true; |
| 10073 | } |
| 10074 | } |
| 10075 | |
| 10076 | return false; |
| 10077 | } |
| 10078 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10079 | /** |
| 10080 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10081 | * @param packageName name of package to be allowlisted |
| 10082 | * @param context |
| 10083 | */ |
| 10084 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10085 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10086 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10087 | } |
| 10088 | |
| 10089 | /** |
| 10090 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10091 | * @param packageName name of package to remove from allowlist |
| 10092 | * @param context |
| 10093 | */ |
| 10094 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10095 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10096 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10097 | } |
| 10098 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10099 | /** |
| 10100 | * Thermal mitigation request to control functionalities at modem. |
| 10101 | * |
| 10102 | * @param subId the id of the subscription. |
| 10103 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10104 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10105 | * |
| 10106 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10107 | */ |
| 10108 | @Override |
| 10109 | @ThermalMitigationResult |
| 10110 | public int sendThermalMitigationRequest( |
| 10111 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10112 | ThermalMitigationRequest thermalMitigationRequest, |
| 10113 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10114 | enforceModifyPermission(); |
| 10115 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10116 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10117 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10118 | .contains(callingPackage)) { |
| 10119 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10120 | + "calling package: " + callingPackage); |
| 10121 | } |
| 10122 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10123 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10124 | final long identity = Binder.clearCallingIdentity(); |
| 10125 | |
| 10126 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10127 | try { |
| 10128 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10129 | switch (thermalMitigationAction) { |
| 10130 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10131 | thermalMitigationResult = |
| 10132 | handleDataThrottlingRequest(subId, |
| 10133 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 10134 | break; |
| 10135 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10136 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10137 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10138 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10139 | } |
| 10140 | |
| 10141 | // Ensure that radio is on. If not able to power on due to phone being |
| 10142 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10143 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10144 | thermalMitigationResult = |
| 10145 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10146 | break; |
| 10147 | } |
| 10148 | |
| 10149 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 10150 | false); |
| 10151 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10152 | break; |
| 10153 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10154 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10155 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10156 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10157 | } |
| 10158 | |
| 10159 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10160 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10161 | Phone phone = getPhone(subId); |
| 10162 | if (phone == null) { |
| 10163 | thermalMitigationResult = |
| 10164 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10165 | break; |
| 10166 | } |
| 10167 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10168 | TelephonyConnectionService service = |
| 10169 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10170 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10171 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10172 | thermalMitigationResult = |
| 10173 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10174 | break; |
| 10175 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10176 | thermalMitigationResult = |
| 10177 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10178 | break; |
| 10179 | } |
| 10180 | } else { |
| 10181 | thermalMitigationResult = |
| 10182 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10183 | break; |
| 10184 | } |
| 10185 | |
| 10186 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10187 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10188 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10189 | thermalMitigationResult = |
| 10190 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10191 | break; |
| 10192 | } |
| 10193 | thermalMitigationResult = |
| 10194 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10195 | break; |
| 10196 | default: |
| 10197 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10198 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10199 | } |
| 10200 | } catch (IllegalArgumentException e) { |
| 10201 | throw e; |
| 10202 | } catch (Exception e) { |
| 10203 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10204 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10205 | } finally { |
| 10206 | Binder.restoreCallingIdentity(identity); |
| 10207 | } |
| 10208 | |
| 10209 | if (DBG) { |
| 10210 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10211 | + thermalMitigationResult); |
| 10212 | } |
| 10213 | |
| 10214 | return thermalMitigationResult; |
| 10215 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10216 | |
| 10217 | /** |
| 10218 | * Set the GbaService Package Name that Telephony will bind to. |
| 10219 | * |
| 10220 | * @param subId The sim that the GbaService is associated with. |
| 10221 | * @param packageName The name of the package to be replaced with. |
| 10222 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10223 | */ |
| 10224 | @Override |
| 10225 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10226 | enforceModifyPermission(); |
| 10227 | |
| 10228 | final long identity = Binder.clearCallingIdentity(); |
| 10229 | try { |
| 10230 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10231 | } finally { |
| 10232 | Binder.restoreCallingIdentity(identity); |
| 10233 | } |
| 10234 | } |
| 10235 | |
| 10236 | /** |
| 10237 | * Return the package name of the currently bound GbaService. |
| 10238 | * |
| 10239 | * @param subId The sim that the GbaService is associated with. |
| 10240 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10241 | */ |
| 10242 | @Override |
| 10243 | public String getBoundGbaService(int subId) { |
| 10244 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10245 | |
| 10246 | final long identity = Binder.clearCallingIdentity(); |
| 10247 | try { |
| 10248 | return getGbaManager(subId).getServicePackage(); |
| 10249 | } finally { |
| 10250 | Binder.restoreCallingIdentity(identity); |
| 10251 | } |
| 10252 | } |
| 10253 | |
| 10254 | /** |
| 10255 | * Set the release time for telephony to unbind GbaService. |
| 10256 | * |
| 10257 | * @param subId The sim that the GbaService is associated with. |
| 10258 | * @param interval The release time to unbind GbaService by millisecond. |
| 10259 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10260 | */ |
| 10261 | @Override |
| 10262 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10263 | enforceModifyPermission(); |
| 10264 | |
| 10265 | final long identity = Binder.clearCallingIdentity(); |
| 10266 | try { |
| 10267 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10268 | } finally { |
| 10269 | Binder.restoreCallingIdentity(identity); |
| 10270 | } |
| 10271 | } |
| 10272 | |
| 10273 | /** |
| 10274 | * Return the release time for telephony to unbind GbaService. |
| 10275 | * |
| 10276 | * @param subId The sim that the GbaService is associated with. |
| 10277 | * @return The release time to unbind GbaService by millisecond. |
| 10278 | */ |
| 10279 | @Override |
| 10280 | public int getGbaReleaseTime(int subId) { |
| 10281 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10282 | |
| 10283 | final long identity = Binder.clearCallingIdentity(); |
| 10284 | try { |
| 10285 | return getGbaManager(subId).getReleaseTime(); |
| 10286 | } finally { |
| 10287 | Binder.restoreCallingIdentity(identity); |
| 10288 | } |
| 10289 | } |
| 10290 | |
| 10291 | private GbaManager getGbaManager(int subId) { |
| 10292 | GbaManager instance = GbaManager.getInstance(subId); |
| 10293 | if (instance == null) { |
| 10294 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10295 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10296 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10297 | } |
| 10298 | return instance; |
| 10299 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10300 | |
| 10301 | /** |
| 10302 | * indicate whether the device and the carrier can support |
| 10303 | * RCS VoLTE single registration. |
| 10304 | */ |
| 10305 | @Override |
| 10306 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10307 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10308 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10309 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10310 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10311 | |
| 10312 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10313 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10314 | } |
| 10315 | |
| 10316 | final long identity = Binder.clearCallingIdentity(); |
| 10317 | try { |
| 10318 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10319 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10320 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10321 | if (isCapable != null) { |
| 10322 | return isCapable; |
| 10323 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10324 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10325 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10326 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10327 | } finally { |
| 10328 | Binder.restoreCallingIdentity(identity); |
| 10329 | } |
| 10330 | } |
| 10331 | |
| 10332 | /** |
| 10333 | * Register RCS provisioning callback. |
| 10334 | */ |
| 10335 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10336 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10337 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10338 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10339 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10340 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10341 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10342 | |
| 10343 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10344 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10345 | } |
| 10346 | if (!isImsAvailableOnDevice()) { |
| 10347 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10348 | "IMS not available on device."); |
| 10349 | } |
| 10350 | |
| 10351 | final long identity = Binder.clearCallingIdentity(); |
| 10352 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10353 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10354 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10355 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10356 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10357 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10358 | } finally { |
| 10359 | Binder.restoreCallingIdentity(identity); |
| 10360 | } |
| 10361 | } |
| 10362 | |
| 10363 | /** |
| 10364 | * Unregister RCS provisioning callback. |
| 10365 | */ |
| 10366 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10367 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10368 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10369 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10370 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10371 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10372 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10373 | |
| 10374 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10375 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10376 | } |
| 10377 | if (!isImsAvailableOnDevice()) { |
| 10378 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10379 | "IMS not available on device."); |
| 10380 | } |
| 10381 | |
| 10382 | final long identity = Binder.clearCallingIdentity(); |
| 10383 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10384 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10385 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10386 | } finally { |
| 10387 | Binder.restoreCallingIdentity(identity); |
| 10388 | } |
| 10389 | } |
| 10390 | |
| 10391 | /** |
| 10392 | * trigger RCS reconfiguration. |
| 10393 | */ |
| 10394 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10395 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10396 | "triggerRcsReconfiguration", |
| 10397 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10398 | |
| 10399 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10400 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10401 | } |
| 10402 | if (!isImsAvailableOnDevice()) { |
| 10403 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10404 | "IMS not available on device."); |
| 10405 | } |
| 10406 | |
| 10407 | final long identity = Binder.clearCallingIdentity(); |
| 10408 | try { |
| 10409 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10410 | } finally { |
| 10411 | Binder.restoreCallingIdentity(identity); |
| 10412 | } |
| 10413 | } |
| 10414 | |
| 10415 | /** |
| 10416 | * Provide the client configuration parameters of the RCS application. |
| 10417 | */ |
| 10418 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10419 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10420 | "setRcsClientConfiguration", |
| 10421 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10422 | |
| 10423 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10424 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10425 | } |
| 10426 | if (!isImsAvailableOnDevice()) { |
| 10427 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10428 | "IMS not available on device."); |
| 10429 | } |
| 10430 | |
| 10431 | final long identity = Binder.clearCallingIdentity(); |
| 10432 | |
| 10433 | try { |
| 10434 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10435 | if (configBinder == null) { |
| 10436 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10437 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10438 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10439 | } else { |
| 10440 | configBinder.setRcsClientConfiguration(rcc); |
| 10441 | } |
| 10442 | } catch (RemoteException e) { |
| 10443 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10444 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10445 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10446 | } finally { |
| 10447 | Binder.restoreCallingIdentity(identity); |
| 10448 | } |
| 10449 | } |
| 10450 | |
| 10451 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10452 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10453 | */ |
| 10454 | @Override |
| 10455 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10456 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10457 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10458 | |
| 10459 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10460 | } |
| 10461 | |
| 10462 | /** |
| 10463 | * Gets the test mode for RCS VoLTE single registration. |
| 10464 | */ |
| 10465 | @Override |
| 10466 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10467 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10468 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10469 | |
| 10470 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10471 | } |
| 10472 | |
| 10473 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10474 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10475 | */ |
| 10476 | @Override |
| 10477 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10478 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10479 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10480 | enforceModifyPermission(); |
| 10481 | |
| 10482 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10483 | : Boolean.parseBoolean(enabledStr); |
| 10484 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10485 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10486 | } |
| 10487 | |
| 10488 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10489 | * Sends a device to device communication message. Only usable via shell. |
| 10490 | * @param message message to send. |
| 10491 | * @param value message value. |
| 10492 | */ |
| 10493 | @Override |
| 10494 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10495 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10496 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10497 | enforceModifyPermission(); |
| 10498 | |
| 10499 | final long identity = Binder.clearCallingIdentity(); |
| 10500 | try { |
| 10501 | TelephonyConnectionService service = |
| 10502 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10503 | if (service == null) { |
| 10504 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10505 | return; |
| 10506 | } |
| 10507 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10508 | } finally { |
| 10509 | Binder.restoreCallingIdentity(identity); |
| 10510 | } |
| 10511 | } |
| 10512 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10513 | /** |
| 10514 | * Sets the specified device to device transport active. |
| 10515 | * @param transport The transport to set active. |
| 10516 | */ |
| 10517 | @Override |
| 10518 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10519 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10520 | "setActiveDeviceToDeviceTransport"); |
| 10521 | enforceModifyPermission(); |
| 10522 | |
| 10523 | final long identity = Binder.clearCallingIdentity(); |
| 10524 | try { |
| 10525 | TelephonyConnectionService service = |
| 10526 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10527 | if (service == null) { |
| 10528 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10529 | return; |
| 10530 | } |
| 10531 | service.setActiveDeviceToDeviceTransport(transport); |
| 10532 | } finally { |
| 10533 | Binder.restoreCallingIdentity(identity); |
| 10534 | } |
| 10535 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10536 | |
Tyler Gunn | d457521 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10537 | @Override |
| 10538 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10539 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10540 | "setDeviceToDeviceForceEnabled"); |
| 10541 | |
| 10542 | final long identity = Binder.clearCallingIdentity(); |
| 10543 | try { |
| 10544 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10545 | p -> { |
| 10546 | Phone thePhone = p.getImsPhone(); |
| 10547 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10548 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10549 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10550 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10551 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10552 | (ImsPhoneCallTracker) tracker; |
| 10553 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10554 | } |
| 10555 | } |
| 10556 | } |
| 10557 | ); |
| 10558 | } finally { |
| 10559 | Binder.restoreCallingIdentity(identity); |
| 10560 | } |
| 10561 | } |
| 10562 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10563 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10564 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10565 | */ |
| 10566 | @Override |
| 10567 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10568 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10569 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10570 | } |
| 10571 | |
| 10572 | /** |
| 10573 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10574 | */ |
| 10575 | @Override |
| 10576 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10577 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10578 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10579 | enforceModifyPermission(); |
| 10580 | |
| 10581 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10582 | : Boolean.parseBoolean(enabledStr); |
| 10583 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10584 | subId, enabled); |
| 10585 | } |
| 10586 | |
| 10587 | /** |
| 10588 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10589 | */ |
| 10590 | @Override |
| 10591 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10592 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10593 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10594 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10595 | |
| 10596 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 10597 | * Overrides the ims feature validation result |
| 10598 | */ |
| 10599 | @Override |
| 10600 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 10601 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10602 | "setImsFeatureValidationOverride"); |
| 10603 | |
| 10604 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10605 | : Boolean.parseBoolean(enabledStr); |
| 10606 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 10607 | subId, enabled); |
| 10608 | } |
| 10609 | |
| 10610 | /** |
| 10611 | * Gets the ims feature validation override value |
| 10612 | */ |
| 10613 | @Override |
| 10614 | public boolean getImsFeatureValidationOverride(int subId) { |
| 10615 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10616 | "getImsFeatureValidationOverride"); |
| 10617 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 10618 | } |
| 10619 | |
| 10620 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10621 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10622 | * their mobile plan. |
| 10623 | */ |
| 10624 | @Override |
| 10625 | public String getMobileProvisioningUrl() { |
| 10626 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10627 | final long identity = Binder.clearCallingIdentity(); |
| 10628 | try { |
| 10629 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10630 | } finally { |
| 10631 | Binder.restoreCallingIdentity(identity); |
| 10632 | } |
| 10633 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10634 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10635 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10636 | * Get the EAB contact from the EAB database. |
| 10637 | */ |
| 10638 | @Override |
| 10639 | public String getContactFromEab(String contact) { |
| 10640 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10641 | enforceModifyPermission(); |
| 10642 | final long identity = Binder.clearCallingIdentity(); |
| 10643 | try { |
| 10644 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10645 | } finally { |
| 10646 | Binder.restoreCallingIdentity(identity); |
| 10647 | } |
| 10648 | } |
| 10649 | |
| 10650 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 10651 | * Get the EAB capability from the EAB database. |
| 10652 | */ |
| 10653 | @Override |
| 10654 | public String getCapabilityFromEab(String contact) { |
| 10655 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 10656 | enforceModifyPermission(); |
| 10657 | final long identity = Binder.clearCallingIdentity(); |
| 10658 | try { |
| 10659 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 10660 | } finally { |
| 10661 | Binder.restoreCallingIdentity(identity); |
| 10662 | } |
| 10663 | } |
| 10664 | |
| 10665 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10666 | * Remove the EAB contacts from the EAB database. |
| 10667 | */ |
| 10668 | @Override |
| 10669 | public int removeContactFromEab(int subId, String contacts) { |
| 10670 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10671 | enforceModifyPermission(); |
| 10672 | final long identity = Binder.clearCallingIdentity(); |
| 10673 | try { |
| 10674 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10675 | } finally { |
| 10676 | Binder.restoreCallingIdentity(identity); |
| 10677 | } |
| 10678 | } |
| 10679 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10680 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10681 | public boolean getDeviceUceEnabled() { |
| 10682 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10683 | final long identity = Binder.clearCallingIdentity(); |
| 10684 | try { |
| 10685 | return mApp.getDeviceUceEnabled(); |
| 10686 | } finally { |
| 10687 | Binder.restoreCallingIdentity(identity); |
| 10688 | } |
| 10689 | } |
| 10690 | |
| 10691 | @Override |
| 10692 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10693 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10694 | final long identity = Binder.clearCallingIdentity(); |
| 10695 | try { |
| 10696 | mApp.setDeviceUceEnabled(isEnabled); |
| 10697 | } finally { |
| 10698 | Binder.restoreCallingIdentity(identity); |
| 10699 | } |
| 10700 | } |
| 10701 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10702 | /** |
| 10703 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10704 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10705 | */ |
| 10706 | // Used for SHELL command only right now. |
| 10707 | @Override |
| 10708 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 10709 | List<String> featureTags) { |
| 10710 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10711 | "addUceRegistrationOverrideShell"); |
| 10712 | final long identity = Binder.clearCallingIdentity(); |
| 10713 | try { |
| 10714 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 10715 | new ArraySet<>(featureTags)); |
| 10716 | } catch (ImsException e) { |
| 10717 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10718 | } finally { |
| 10719 | Binder.restoreCallingIdentity(identity); |
| 10720 | } |
| 10721 | } |
| 10722 | |
| 10723 | /** |
| 10724 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10725 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10726 | */ |
| 10727 | // Used for SHELL command only right now. |
| 10728 | @Override |
| 10729 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 10730 | List<String> featureTags) { |
| 10731 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10732 | "removeUceRegistrationOverrideShell"); |
| 10733 | final long identity = Binder.clearCallingIdentity(); |
| 10734 | try { |
| 10735 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 10736 | new ArraySet<>(featureTags)); |
| 10737 | } catch (ImsException e) { |
| 10738 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10739 | } finally { |
| 10740 | Binder.restoreCallingIdentity(identity); |
| 10741 | } |
| 10742 | } |
| 10743 | |
| 10744 | /** |
| 10745 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 10746 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10747 | */ |
| 10748 | // Used for SHELL command only right now. |
| 10749 | @Override |
| 10750 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 10751 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10752 | "clearUceRegistrationOverrideShell"); |
| 10753 | final long identity = Binder.clearCallingIdentity(); |
| 10754 | try { |
| 10755 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 10756 | } catch (ImsException e) { |
| 10757 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10758 | } finally { |
| 10759 | Binder.restoreCallingIdentity(identity); |
| 10760 | } |
| 10761 | } |
| 10762 | |
| 10763 | /** |
| 10764 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10765 | */ |
| 10766 | // Used for SHELL command only right now. |
| 10767 | @Override |
| 10768 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 10769 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10770 | "getLatestRcsContactUceCapabilityShell"); |
| 10771 | final long identity = Binder.clearCallingIdentity(); |
| 10772 | try { |
| 10773 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 10774 | } catch (ImsException e) { |
| 10775 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10776 | } finally { |
| 10777 | Binder.restoreCallingIdentity(identity); |
| 10778 | } |
| 10779 | } |
| 10780 | |
| 10781 | /** |
| 10782 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 10783 | * device does not have an active PUBLISH. |
| 10784 | */ |
| 10785 | // Used for SHELL command only right now. |
| 10786 | @Override |
| 10787 | public String getLastUcePidfXmlShell(int subId) { |
| 10788 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 10789 | final long identity = Binder.clearCallingIdentity(); |
| 10790 | try { |
| 10791 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 10792 | } catch (ImsException e) { |
| 10793 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10794 | } finally { |
| 10795 | Binder.restoreCallingIdentity(identity); |
| 10796 | } |
| 10797 | } |
| 10798 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 10799 | /** |
| 10800 | * Remove UCE requests cannot be sent to the network status. |
| 10801 | */ |
| 10802 | // Used for SHELL command only right now. |
| 10803 | @Override |
| 10804 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 10805 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 10806 | final long identity = Binder.clearCallingIdentity(); |
| 10807 | try { |
| 10808 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 10809 | } catch (ImsException e) { |
| 10810 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10811 | } finally { |
| 10812 | Binder.restoreCallingIdentity(identity); |
| 10813 | } |
| 10814 | } |
| 10815 | |
James.cf Lin | 0fc71b0 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 10816 | /** |
| 10817 | * Remove UCE requests cannot be sent to the network status. |
| 10818 | */ |
| 10819 | // Used for SHELL command only. |
| 10820 | @Override |
| 10821 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 10822 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 10823 | final long identity = Binder.clearCallingIdentity(); |
| 10824 | try { |
| 10825 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 10826 | } catch (ImsException e) { |
| 10827 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10828 | } finally { |
| 10829 | Binder.restoreCallingIdentity(identity); |
| 10830 | } |
| 10831 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10832 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10833 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10834 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10835 | String callingPackage) { |
| 10836 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10837 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 10838 | |
| 10839 | final int callingUid = Binder.getCallingUid(); |
| 10840 | // Verify that tha callingPackage belongs to the calling UID |
| 10841 | mApp.getSystemService(AppOpsManager.class) |
| 10842 | .checkPackage(callingUid, callingPackage); |
| 10843 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 10844 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10845 | |
| 10846 | final long identity = Binder.clearCallingIdentity(); |
| 10847 | try { |
| 10848 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10849 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10850 | |
| 10851 | if (result instanceof IllegalStateException) { |
| 10852 | throw (IllegalStateException) result; |
| 10853 | } |
| 10854 | } finally { |
| 10855 | Binder.restoreCallingIdentity(identity); |
| 10856 | } |
| 10857 | } |
| 10858 | |
| 10859 | @Override |
| 10860 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10861 | String callingPackage) { |
| 10862 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10863 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 10864 | |
| 10865 | final int callingUid = Binder.getCallingUid(); |
| 10866 | // Verify that tha callingPackage belongs to the calling UID |
| 10867 | mApp.getSystemService(AppOpsManager.class) |
| 10868 | .checkPackage(callingUid, callingPackage); |
| 10869 | |
| 10870 | final long identity = Binder.clearCallingIdentity(); |
| 10871 | try { |
| 10872 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10873 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10874 | |
| 10875 | if (result instanceof IllegalStateException) { |
| 10876 | throw (IllegalStateException) result; |
| 10877 | } |
| 10878 | } finally { |
| 10879 | Binder.restoreCallingIdentity(identity); |
| 10880 | } |
| 10881 | } |
| 10882 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 10883 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 10884 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10885 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 10886 | // phone/system process do not have further restriction on request |
| 10887 | return; |
| 10888 | } |
| 10889 | |
| 10890 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 10891 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10892 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 10893 | context.enforceCallingOrSelfPermission( |
| 10894 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 10895 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10896 | } |
| 10897 | |
| 10898 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 10899 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 10900 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 10901 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 10902 | || info.isEnabled()) { |
| 10903 | throw new IllegalArgumentException( |
| 10904 | "Only system can set hide fields in SignalThresholdInfo"); |
| 10905 | } |
| 10906 | |
| 10907 | // Thresholds length for each RAN need in range. This has been validated in |
| 10908 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 10909 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 10910 | final int[] thresholds = info.getThresholds(); |
| 10911 | Objects.requireNonNull(thresholds); |
| 10912 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 10913 | || thresholds.length |
| 10914 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 10915 | throw new IllegalArgumentException( |
| 10916 | "thresholds length is out of range: " + thresholds.length); |
| 10917 | } |
| 10918 | } |
| 10919 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10920 | |
| 10921 | /** |
| 10922 | * Gets the current phone capability. |
| 10923 | * |
| 10924 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 10925 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 10926 | * It's used to evaluate possible phone config change, for example from single |
| 10927 | * SIM device to multi-SIM device. |
| 10928 | */ |
| 10929 | @Override |
| 10930 | public PhoneCapability getPhoneCapability() { |
| 10931 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 10932 | final long identity = Binder.clearCallingIdentity(); |
| 10933 | try { |
| 10934 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 10935 | } finally { |
| 10936 | Binder.restoreCallingIdentity(identity); |
| 10937 | } |
| 10938 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 10939 | |
| 10940 | /** |
| 10941 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 10942 | * required to be done shortly after the API is invoked. |
| 10943 | */ |
| 10944 | @Override |
| 10945 | @TelephonyManager.PrepareUnattendedRebootResult |
| 10946 | public int prepareForUnattendedReboot() { |
| 10947 | enforceRebootPermission(); |
| 10948 | |
| 10949 | final long identity = Binder.clearCallingIdentity(); |
| 10950 | try { |
| 10951 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null); |
| 10952 | } finally { |
| 10953 | Binder.restoreCallingIdentity(identity); |
| 10954 | } |
| 10955 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 10956 | |
| 10957 | /** |
| 10958 | * Request to get the current slicing configuration including URSP rules and |
| 10959 | * NSSAIs (configured, allowed and rejected). |
| 10960 | * |
| 10961 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 10962 | */ |
| 10963 | @Override |
| 10964 | public void getSlicingConfig(ResultReceiver callback) { |
| 10965 | enforceReadPrivilegedPermission("getSlicingConfig"); |
| 10966 | |
| 10967 | final long identity = Binder.clearCallingIdentity(); |
| 10968 | try { |
| 10969 | Phone phone = getDefaultPhone(); |
| 10970 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 10971 | } finally { |
| 10972 | Binder.restoreCallingIdentity(identity); |
| 10973 | } |
| 10974 | } |
Hunsuk Choi | c7ebc0f | 2021-11-15 23:46:41 +0000 | [diff] [blame] | 10975 | |
| 10976 | /** |
| 10977 | * Register an IMS connection state callback |
| 10978 | */ |
| 10979 | @Override |
| 10980 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 10981 | String callingPackage) { |
| 10982 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 10983 | // ImsMmTelManager |
| 10984 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 10985 | TelephonyPermissions |
| 10986 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 10987 | mApp, subId, "registerImsStateCallback"); |
| 10988 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 10989 | // ImsRcsManager or SipDelegateManager |
| 10990 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10991 | Binder.getCallingUid(), "registerImsStateCallback", |
| 10992 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 10993 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 10994 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 10995 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 10996 | } |
| 10997 | |
| 10998 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 10999 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11000 | "IMS not available on device."); |
| 11001 | } |
| 11002 | |
| 11003 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11004 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11005 | } |
| 11006 | |
| 11007 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11008 | if (controller == null) { |
| 11009 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11010 | "IMS not available on device."); |
| 11011 | } |
| 11012 | |
| 11013 | if (callingPackage == null) { |
| 11014 | callingPackage = getCurrentPackageName(); |
| 11015 | } |
| 11016 | |
| 11017 | final long token = Binder.clearCallingIdentity(); |
| 11018 | try { |
| 11019 | int slotId = getSlotIndexOrException(subId); |
| 11020 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
| 11021 | } catch (ImsException e) { |
| 11022 | throw new ServiceSpecificException(e.getCode()); |
| 11023 | } finally { |
| 11024 | Binder.restoreCallingIdentity(token); |
| 11025 | } |
| 11026 | } |
| 11027 | |
| 11028 | /** |
| 11029 | * Unregister an IMS connection state callback |
| 11030 | */ |
| 11031 | @Override |
| 11032 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11033 | final long token = Binder.clearCallingIdentity(); |
| 11034 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11035 | if (controller == null) { |
| 11036 | return; |
| 11037 | } |
| 11038 | try { |
| 11039 | controller.unregisterImsStateCallback(cb); |
| 11040 | } finally { |
| 11041 | Binder.restoreCallingIdentity(token); |
| 11042 | } |
| 11043 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11044 | |
| 11045 | /** |
| 11046 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11047 | * |
| 11048 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11049 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11050 | * SecurityException. |
| 11051 | * If there is current registered network this value will be same as the registered cell |
| 11052 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11053 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11054 | * it will be cleared and null will be returned. |
| 11055 | * |
| 11056 | */ |
| 11057 | @Override |
| 11058 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11059 | String callingFeatureId) { |
| 11060 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11061 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11062 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11063 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11064 | .setCallingPackage(callingPackage) |
| 11065 | .setCallingFeatureId(callingFeatureId) |
| 11066 | .setCallingPid(Binder.getCallingPid()) |
| 11067 | .setCallingUid(Binder.getCallingUid()) |
| 11068 | .setMethod("getLastKnownCellIdentity") |
| 11069 | .setLogAsInfo(true) |
| 11070 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11071 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11072 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11073 | .build()); |
| 11074 | |
| 11075 | boolean hasFinePermission = |
| 11076 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11077 | if (!hasFinePermission |
| 11078 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11079 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
| 11080 | + "and BIND_CONNECTION_SERVICE permission."); |
| 11081 | } |
| 11082 | |
| 11083 | final long identity = Binder.clearCallingIdentity(); |
| 11084 | try { |
| 11085 | Phone phone = getPhone(subId); |
| 11086 | if (phone == null) return null; |
| 11087 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 11088 | if (sst == null) return null; |
| 11089 | return sst.getLastKnownCellIdentity(); |
| 11090 | } finally { |
| 11091 | Binder.restoreCallingIdentity(identity); |
| 11092 | } |
| 11093 | } |
jimsun | 38340bf | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11094 | |
| 11095 | /** |
| 11096 | * Sets the modem service class Name that Telephony will bind to. |
| 11097 | * |
| 11098 | * @param serviceName The class name of the modem service. |
| 11099 | * @return true if the operation is succeed, otherwise false. |
| 11100 | */ |
| 11101 | public boolean setModemService(String serviceName) { |
| 11102 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11103 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11104 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 11105 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11106 | "setModemService"); |
| 11107 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11108 | } |
| 11109 | |
| 11110 | /** |
| 11111 | * Return the class name of the currently bounded modem service. |
| 11112 | * |
| 11113 | * @return the class name of the modem service. |
| 11114 | */ |
| 11115 | public String getModemService() { |
| 11116 | String result; |
| 11117 | Log.d(LOG_TAG, "getModemService"); |
| 11118 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11119 | TelephonyPermissions |
| 11120 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11121 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11122 | "getModemService"); |
| 11123 | result = mPhoneConfigurationManager.getModemService(); |
| 11124 | Log.d(LOG_TAG, "result = " + result); |
| 11125 | return result; |
| 11126 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 11127 | } |