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 | d433926 | 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; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 164 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 166 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 169 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 170 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 174 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 175 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 176 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 178 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 179 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 180 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 181 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 182 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 183 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 185 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 186 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 187 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 188 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 189 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 190 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 191 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 192 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 193 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 194 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 195 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 196 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 197 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 198 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 199 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 200 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 201 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 202 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 203 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 204 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 205 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 206 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 207 | import com.android.services.telephony.TelecomAccountRegistry; |
| 208 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 209 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 210 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 211 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 212 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 213 | import java.io.IOException; |
| 214 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 215 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 216 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 217 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 218 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 219 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 220 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 221 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 222 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 223 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 224 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 225 | import java.util.Set; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 226 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 227 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 228 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 229 | |
| 230 | /** |
| 231 | * Implementation of the ITelephony interface. |
| 232 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 233 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 234 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 235 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 236 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 237 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 238 | |
| 239 | // Message codes used with mMainThreadHandler |
| 240 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 241 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 242 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 243 | private static final int CMD_OPEN_CHANNEL = 9; |
| 244 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 245 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 246 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 247 | private static final int CMD_NV_READ_ITEM = 13; |
| 248 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 249 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 250 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 251 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 252 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 253 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 254 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 255 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 256 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 257 | private static final int CMD_SEND_ENVELOPE = 25; |
| 258 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 259 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 260 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 261 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 262 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 263 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 264 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 265 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 266 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 267 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 268 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 269 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 270 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 271 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 272 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 273 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 274 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 275 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 276 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 277 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 278 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 279 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 280 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 281 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 282 | private static final int CMD_SWITCH_SLOTS = 50; |
| 283 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 284 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 285 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 286 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 287 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 288 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 289 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 290 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 291 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 292 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 293 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 294 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 295 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 296 | private static final int CMD_MODEM_REBOOT = 64; |
| 297 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 298 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 299 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 300 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 301 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 302 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 303 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 304 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 305 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 306 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 307 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 308 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 309 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 310 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 311 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 312 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 313 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 314 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 315 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 316 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 317 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 318 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 319 | private static final int CMD_GET_CALL_WAITING = 87; |
| 320 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 321 | private static final int CMD_SET_CALL_WAITING = 89; |
| 322 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 323 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 324 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 325 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 326 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 327 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 328 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 329 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 330 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 331 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 332 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 333 | private static final int CMD_SET_SIM_POWER = 101; |
| 334 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 335 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 336 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 337 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 338 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 339 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 340 | 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] | 341 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 342 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 343 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 344 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 345 | private static final int CMD_ENABLE_VONR = 113; |
| 346 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 347 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 348 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 349 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 350 | // Parameters of select command. |
| 351 | private static final int SELECT_COMMAND = 0xA4; |
| 352 | private static final int SELECT_P1 = 0x04; |
| 353 | private static final int SELECT_P2 = 0; |
| 354 | private static final int SELECT_P3 = 0x10; |
| 355 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 356 | /** The singleton instance. */ |
| 357 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 358 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 359 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 360 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 361 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 362 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 363 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 364 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 365 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 366 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 367 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 368 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 369 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 370 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 371 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 372 | /** User Activity */ |
| 373 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 374 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 375 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 376 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 377 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 378 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 379 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 380 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 381 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 382 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 383 | // String to store multi SIM allowed |
| 384 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 385 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 386 | // The AID of ISD-R. |
| 387 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 388 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 389 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 390 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 391 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 392 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 393 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 394 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 395 | 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] | 396 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 397 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 398 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 399 | */ |
| 400 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 401 | "reset_network_erase_modem_config_enabled"; |
| 402 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 403 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds |
| 404 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 405 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 406 | * A request object to use for transmitting data to an ICC. |
| 407 | */ |
| 408 | private static final class IccAPDUArgument { |
| 409 | public int channel, cla, command, p1, p2, p3; |
| 410 | public String data; |
| 411 | |
| 412 | public IccAPDUArgument(int channel, int cla, int command, |
| 413 | int p1, int p2, int p3, String data) { |
| 414 | this.channel = channel; |
| 415 | this.cla = cla; |
| 416 | this.command = command; |
| 417 | this.p1 = p1; |
| 418 | this.p2 = p2; |
| 419 | this.p3 = p3; |
| 420 | this.data = data; |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 425 | * A request object to use for transmitting data to an ICC. |
| 426 | */ |
| 427 | private static final class ManualNetworkSelectionArgument { |
| 428 | public OperatorInfo operatorInfo; |
| 429 | public boolean persistSelection; |
| 430 | |
| 431 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 432 | this.operatorInfo = operatorInfo; |
| 433 | this.persistSelection = persistSelection; |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 438 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 439 | * request after sending. The main thread will notify the request when it is complete. |
| 440 | */ |
| 441 | private static final class MainThreadRequest { |
| 442 | /** The argument to use for the request */ |
| 443 | public Object argument; |
| 444 | /** The result of the request that is run on the main thread */ |
| 445 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 446 | // The subscriber id that this request applies to. Defaults to |
| 447 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 448 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 449 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 450 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 451 | public Phone phone; |
| 452 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 453 | public WorkSource workSource; |
| 454 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 455 | public MainThreadRequest(Object argument) { |
| 456 | this.argument = argument; |
| 457 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 458 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 459 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 460 | this.argument = argument; |
| 461 | if (phone != null) { |
| 462 | this.phone = phone; |
| 463 | } |
| 464 | this.workSource = workSource; |
| 465 | } |
| 466 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 467 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 468 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 469 | if (subId != null) { |
| 470 | this.subId = subId; |
| 471 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 472 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 473 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 474 | } |
| 475 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 476 | private static final class IncomingThirdPartyCallArgs { |
| 477 | public final ComponentName component; |
| 478 | public final String callId; |
| 479 | public final String callerDisplayName; |
| 480 | |
| 481 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 482 | String callerDisplayName) { |
| 483 | this.component = component; |
| 484 | this.callId = callId; |
| 485 | this.callerDisplayName = callerDisplayName; |
| 486 | } |
| 487 | } |
| 488 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 489 | /** |
| 490 | * A handler that processes messages on the main thread in the phone process. Since many |
| 491 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 492 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 493 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 494 | * on, which will be notified when the operation completes and will contain the result of the |
| 495 | * request. |
| 496 | * |
| 497 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 498 | * note that request.result must be set to something non-null for the calling thread to |
| 499 | * unblock. |
| 500 | */ |
| 501 | private final class MainThreadHandler extends Handler { |
| 502 | @Override |
| 503 | public void handleMessage(Message msg) { |
| 504 | MainThreadRequest request; |
| 505 | Message onCompleted; |
| 506 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 507 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 508 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 509 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 510 | |
| 511 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 512 | case CMD_HANDLE_USSD_REQUEST: { |
| 513 | request = (MainThreadRequest) msg.obj; |
| 514 | final Phone phone = getPhoneFromRequest(request); |
| 515 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 516 | String ussdRequest = ussdObject.first; |
| 517 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 518 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 519 | if (!isUssdApiAllowed(request.subId)) { |
| 520 | // Carrier does not support use of this API, return failure. |
| 521 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 522 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 523 | Bundle returnData = new Bundle(); |
| 524 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 525 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 526 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 527 | request.result = true; |
| 528 | notifyRequester(request); |
| 529 | return; |
| 530 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 531 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 532 | try { |
| 533 | request.result = phone != null |
| 534 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 535 | } catch (CallStateException cse) { |
| 536 | request.result = false; |
| 537 | } |
| 538 | // Wake up the requesting thread |
| 539 | notifyRequester(request); |
| 540 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 541 | } |
| 542 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 543 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 544 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 545 | final Phone phone = getPhoneFromRequest(request); |
| 546 | request.result = phone != null ? |
| 547 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 548 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 549 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 550 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 551 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 552 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 553 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 554 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 555 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 556 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 557 | uiccPort = getUiccPortFromRequest(request); |
| 558 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 559 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 560 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 561 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 562 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 563 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 564 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 565 | uiccPort.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 566 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 567 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 568 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 569 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 570 | break; |
| 571 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 572 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 573 | ar = (AsyncResult) msg.obj; |
| 574 | request = (MainThreadRequest) ar.userObj; |
| 575 | if (ar.exception == null && ar.result != null) { |
| 576 | request.result = ar.result; |
| 577 | } else { |
| 578 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 579 | if (ar.result == null) { |
| 580 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 581 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 582 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 583 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 584 | } else { |
| 585 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 586 | } |
| 587 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 588 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 589 | break; |
| 590 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 591 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 592 | request = (MainThreadRequest) msg.obj; |
| 593 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 594 | uiccPort = getUiccPortFromRequest(request); |
| 595 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 596 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 597 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 598 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 599 | } else { |
| 600 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 601 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 602 | uiccPort.iccTransmitApduBasicChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 603 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 604 | iccArgument.p3, iccArgument.data, onCompleted); |
| 605 | } |
| 606 | break; |
| 607 | |
| 608 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 609 | ar = (AsyncResult) msg.obj; |
| 610 | request = (MainThreadRequest) ar.userObj; |
| 611 | if (ar.exception == null && ar.result != null) { |
| 612 | request.result = ar.result; |
| 613 | } else { |
| 614 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 615 | if (ar.result == null) { |
| 616 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 617 | } else if (ar.exception instanceof CommandException) { |
| 618 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 619 | ar.exception); |
| 620 | } else { |
| 621 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 622 | } |
| 623 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 624 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 625 | break; |
| 626 | |
| 627 | case CMD_EXCHANGE_SIM_IO: |
| 628 | request = (MainThreadRequest) msg.obj; |
| 629 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 630 | uiccPort = getUiccPortFromRequest(request); |
| 631 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 632 | loge("iccExchangeSimIO: No UICC"); |
| 633 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 634 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 635 | } else { |
| 636 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 637 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 638 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 639 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 640 | iccArgument.data, onCompleted); |
| 641 | } |
| 642 | break; |
| 643 | |
| 644 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 645 | ar = (AsyncResult) msg.obj; |
| 646 | request = (MainThreadRequest) ar.userObj; |
| 647 | if (ar.exception == null && ar.result != null) { |
| 648 | request.result = ar.result; |
| 649 | } else { |
| 650 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 651 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 652 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 653 | break; |
| 654 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 655 | case CMD_SEND_ENVELOPE: |
| 656 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 657 | uiccPort = getUiccPortFromRequest(request); |
| 658 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 659 | loge("sendEnvelopeWithStatus: No UICC"); |
| 660 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 661 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 662 | } else { |
| 663 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 664 | uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 665 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 666 | break; |
| 667 | |
| 668 | case EVENT_SEND_ENVELOPE_DONE: |
| 669 | ar = (AsyncResult) msg.obj; |
| 670 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 671 | if (ar.exception == null && ar.result != null) { |
| 672 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 673 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 674 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 675 | if (ar.result == null) { |
| 676 | loge("sendEnvelopeWithStatus: Empty response"); |
| 677 | } else if (ar.exception instanceof CommandException) { |
| 678 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 679 | ar.exception); |
| 680 | } else { |
| 681 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 682 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 683 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 684 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 685 | break; |
| 686 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 687 | case CMD_OPEN_CHANNEL: |
| 688 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 689 | uiccPort = getUiccPortFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 690 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 691 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 692 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 693 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 694 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 695 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 696 | } else { |
| 697 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 698 | uiccPort.iccOpenLogicalChannel(openChannelArgs.first, |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 699 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 700 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 701 | break; |
| 702 | |
| 703 | case EVENT_OPEN_CHANNEL_DONE: |
| 704 | ar = (AsyncResult) msg.obj; |
| 705 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 706 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 707 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 708 | int[] result = (int[]) ar.result; |
| 709 | int channelId = result[0]; |
| 710 | byte[] selectResponse = null; |
| 711 | if (result.length > 1) { |
| 712 | selectResponse = new byte[result.length - 1]; |
| 713 | for (int i = 1; i < result.length; ++i) { |
| 714 | selectResponse[i - 1] = (byte) result[i]; |
| 715 | } |
| 716 | } |
| 717 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 718 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 719 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 720 | if (ar.result == null) { |
| 721 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 722 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 723 | if (ar.exception != null) { |
| 724 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 725 | } |
| 726 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 727 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 728 | if (ar.exception instanceof CommandException) { |
| 729 | CommandException.Error error = |
| 730 | ((CommandException) (ar.exception)).getCommandError(); |
| 731 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 732 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 733 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 734 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 735 | } |
| 736 | } |
| 737 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 738 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 739 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 740 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 741 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 742 | break; |
| 743 | |
| 744 | case CMD_CLOSE_CHANNEL: |
| 745 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 746 | uiccPort = getUiccPortFromRequest(request); |
| 747 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 748 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 749 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 750 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 751 | } else { |
| 752 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 753 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 754 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 755 | break; |
| 756 | |
| 757 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 758 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 759 | break; |
| 760 | |
| 761 | case CMD_NV_READ_ITEM: |
| 762 | request = (MainThreadRequest) msg.obj; |
| 763 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 764 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 765 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 766 | break; |
| 767 | |
| 768 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 769 | ar = (AsyncResult) msg.obj; |
| 770 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 771 | if (ar.exception == null && ar.result != null) { |
| 772 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 773 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 774 | request.result = ""; |
| 775 | if (ar.result == null) { |
| 776 | loge("nvReadItem: Empty response"); |
| 777 | } else if (ar.exception instanceof CommandException) { |
| 778 | loge("nvReadItem: CommandException: " + |
| 779 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 780 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 781 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 782 | } |
| 783 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 784 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 785 | break; |
| 786 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 787 | case CMD_NV_WRITE_ITEM: |
| 788 | request = (MainThreadRequest) msg.obj; |
| 789 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 790 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 791 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 792 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 793 | break; |
| 794 | |
| 795 | case EVENT_NV_WRITE_ITEM_DONE: |
| 796 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 797 | break; |
| 798 | |
| 799 | case CMD_NV_WRITE_CDMA_PRL: |
| 800 | request = (MainThreadRequest) msg.obj; |
| 801 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 802 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 803 | break; |
| 804 | |
| 805 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 806 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 807 | break; |
| 808 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 809 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 810 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 811 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 812 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 813 | break; |
| 814 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 815 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 816 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 817 | break; |
| 818 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 819 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 820 | request = (MainThreadRequest) msg.obj; |
| 821 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 822 | request); |
| 823 | Phone phone = getPhoneFromRequest(request); |
| 824 | if (phone != null) { |
| 825 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 826 | } else { |
| 827 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 828 | request.result = false; |
| 829 | notifyRequester(request); |
| 830 | } |
| 831 | break; |
| 832 | } |
| 833 | |
| 834 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 835 | ar = (AsyncResult) msg.obj; |
| 836 | request = (MainThreadRequest) ar.userObj; |
| 837 | if (ar.exception == null && ar.result != null) { |
| 838 | request.result = ar.result; |
| 839 | } else { |
| 840 | // request.result must be set to something non-null |
| 841 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 842 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 843 | request.result = ar.result; |
| 844 | } else { |
| 845 | request.result = false; |
| 846 | } |
| 847 | if (ar.result == null) { |
| 848 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 849 | } else if (ar.exception instanceof CommandException) { |
| 850 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 851 | + ar.exception); |
| 852 | } else { |
| 853 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 854 | } |
| 855 | } |
| 856 | notifyRequester(request); |
| 857 | break; |
| 858 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 859 | case CMD_IS_VONR_ENABLED: { |
| 860 | request = (MainThreadRequest) msg.obj; |
| 861 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 862 | request); |
| 863 | Phone phone = getPhoneFromRequest(request); |
| 864 | if (phone != null) { |
| 865 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 866 | } else { |
| 867 | loge("isVoNrEnabled: No phone object"); |
| 868 | request.result = false; |
| 869 | notifyRequester(request); |
| 870 | } |
| 871 | break; |
| 872 | } |
| 873 | |
| 874 | case EVENT_IS_VONR_ENABLED_DONE: |
| 875 | ar = (AsyncResult) msg.obj; |
| 876 | request = (MainThreadRequest) ar.userObj; |
| 877 | if (ar.exception == null && ar.result != null) { |
| 878 | request.result = ar.result; |
| 879 | } else { |
| 880 | // request.result must be set to something non-null |
| 881 | // for the calling thread to unblock |
| 882 | if (ar.result != null) { |
| 883 | request.result = ar.result; |
| 884 | } else { |
| 885 | request.result = false; |
| 886 | } |
| 887 | if (ar.result == null) { |
| 888 | loge("isVoNrEnabled: Empty response"); |
| 889 | } else if (ar.exception instanceof CommandException) { |
| 890 | loge("isVoNrEnabled: CommandException: " |
| 891 | + ar.exception); |
| 892 | } else { |
| 893 | loge("isVoNrEnabled: Unknown exception"); |
| 894 | } |
| 895 | } |
| 896 | notifyRequester(request); |
| 897 | break; |
| 898 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 899 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 900 | request = (MainThreadRequest) msg.obj; |
| 901 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 902 | Phone phone = getPhoneFromRequest(request); |
| 903 | if (phone != null) { |
| 904 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 905 | request.workSource); |
| 906 | } else { |
| 907 | loge("enableNrDualConnectivity: No phone object"); |
| 908 | request.result = |
| 909 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 910 | notifyRequester(request); |
| 911 | } |
| 912 | break; |
| 913 | } |
| 914 | |
| 915 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 916 | ar = (AsyncResult) msg.obj; |
| 917 | request = (MainThreadRequest) ar.userObj; |
| 918 | if (ar.exception == null) { |
| 919 | request.result = |
| 920 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 921 | } else { |
| 922 | request.result = |
| 923 | TelephonyManager |
| 924 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 925 | if (ar.exception instanceof CommandException) { |
| 926 | CommandException.Error error = |
| 927 | ((CommandException) (ar.exception)).getCommandError(); |
| 928 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 929 | request.result = |
| 930 | TelephonyManager |
| 931 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 932 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 933 | request.result = |
| 934 | TelephonyManager |
| 935 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 936 | } |
| 937 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 938 | + ar.exception); |
| 939 | } else { |
| 940 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 941 | } |
| 942 | } |
| 943 | notifyRequester(request); |
| 944 | break; |
| 945 | } |
| 946 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 947 | case CMD_ENABLE_VONR: { |
| 948 | request = (MainThreadRequest) msg.obj; |
| 949 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 950 | Phone phone = getPhoneFromRequest(request); |
| 951 | if (phone != null) { |
| 952 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 953 | request.workSource); |
| 954 | } else { |
| 955 | loge("setVoNrEnabled: No phone object"); |
| 956 | request.result = |
| 957 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 958 | notifyRequester(request); |
| 959 | } |
| 960 | break; |
| 961 | } |
| 962 | |
| 963 | case EVENT_ENABLE_VONR_DONE: { |
| 964 | ar = (AsyncResult) msg.obj; |
| 965 | request = (MainThreadRequest) ar.userObj; |
| 966 | if (ar.exception == null) { |
| 967 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 968 | } else { |
| 969 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 970 | if (ar.exception instanceof CommandException) { |
| 971 | CommandException.Error error = |
| 972 | ((CommandException) (ar.exception)).getCommandError(); |
| 973 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 974 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 975 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 976 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 977 | } else { |
| 978 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 979 | } |
| 980 | loge("setVoNrEnabled" + ": CommandException: " |
| 981 | + ar.exception); |
| 982 | } else { |
| 983 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 984 | } |
| 985 | } |
| 986 | notifyRequester(request); |
| 987 | break; |
| 988 | } |
| 989 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 990 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 991 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 992 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 993 | request); |
| 994 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 995 | break; |
| 996 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 997 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 998 | ar = (AsyncResult) msg.obj; |
| 999 | request = (MainThreadRequest) ar.userObj; |
| 1000 | if (ar.exception == null && ar.result != null) { |
| 1001 | request.result = ar.result; // Integer |
| 1002 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1003 | // request.result must be set to something non-null |
| 1004 | // for the calling thread to unblock |
| 1005 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1006 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1007 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1008 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1009 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1010 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1011 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1012 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1013 | } |
| 1014 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1015 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1016 | break; |
| 1017 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1018 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1019 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1020 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1021 | request); |
| 1022 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1023 | (Pair<Integer, Long>) request.argument; |
| 1024 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1025 | reasonWithNetworkTypes.first, |
| 1026 | reasonWithNetworkTypes.second, |
| 1027 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1028 | break; |
| 1029 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1030 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1031 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1032 | break; |
| 1033 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1034 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1035 | request = (MainThreadRequest)msg.obj; |
| 1036 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1037 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1038 | break; |
| 1039 | |
| 1040 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1041 | ar = (AsyncResult)msg.obj; |
| 1042 | request = (MainThreadRequest)ar.userObj; |
| 1043 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1044 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1045 | break; |
| 1046 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1047 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1048 | request = (MainThreadRequest) msg.obj; |
| 1049 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1050 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1051 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1052 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1053 | break; |
| 1054 | |
| 1055 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1056 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1057 | break; |
| 1058 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1059 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1060 | request = (MainThreadRequest) msg.obj; |
| 1061 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1062 | request); |
| 1063 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1064 | break; |
| 1065 | |
| 1066 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1067 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1068 | break; |
| 1069 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1070 | case CMD_PERFORM_NETWORK_SCAN: |
| 1071 | request = (MainThreadRequest) msg.obj; |
| 1072 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1073 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1074 | break; |
| 1075 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1076 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1077 | request = (MainThreadRequest) msg.obj; |
| 1078 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1079 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1080 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1081 | request.argument; |
| 1082 | int callForwardingReason = args.first; |
| 1083 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1084 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1085 | } |
| 1086 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1087 | ar = (AsyncResult) msg.obj; |
| 1088 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1089 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1090 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1091 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1092 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1093 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1094 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1095 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1096 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1097 | // any service for voice call. |
| 1098 | if ((callForwardInfo.serviceClass |
| 1099 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1100 | callForwardingInfo = new CallForwardingInfo(true, |
| 1101 | callForwardInfo.reason, |
| 1102 | callForwardInfo.number, |
| 1103 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1104 | break; |
| 1105 | } |
| 1106 | } |
| 1107 | // Didn't find a call forward info for voice call. |
| 1108 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1109 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1110 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1111 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1112 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1113 | } else { |
| 1114 | if (ar.result == null) { |
| 1115 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1116 | } |
| 1117 | if (ar.exception != null) { |
| 1118 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1119 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1120 | int errorCode = TelephonyManager |
| 1121 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1122 | if (ar.exception instanceof CommandException) { |
| 1123 | CommandException.Error error = |
| 1124 | ((CommandException) (ar.exception)).getCommandError(); |
| 1125 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1126 | errorCode = TelephonyManager |
| 1127 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1128 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1129 | errorCode = TelephonyManager |
| 1130 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1131 | } |
| 1132 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1133 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1134 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1135 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1136 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1137 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1138 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1139 | request = (MainThreadRequest) msg.obj; |
| 1140 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1141 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1142 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1143 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1144 | request.argument).first; |
| 1145 | request.phone.setCallForwardingOption( |
| 1146 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1147 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1148 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1149 | callForwardingInfoToSet.getReason(), |
| 1150 | callForwardingInfoToSet.getNumber(), |
| 1151 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1152 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1153 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1154 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1155 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1156 | ar = (AsyncResult) msg.obj; |
| 1157 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1158 | Consumer<Integer> callback = |
| 1159 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1160 | request.argument).second; |
| 1161 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1162 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1163 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1164 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1165 | if (ar.exception instanceof CommandException) { |
| 1166 | CommandException.Error error = |
| 1167 | ((CommandException) (ar.exception)).getCommandError(); |
| 1168 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1169 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1170 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1171 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1172 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1173 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1174 | } |
| 1175 | } |
| 1176 | callback.accept(errorCode); |
| 1177 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1178 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1179 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1180 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1181 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1182 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1183 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1184 | request = (MainThreadRequest) msg.obj; |
| 1185 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1186 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1187 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1188 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1189 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1190 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1191 | ar = (AsyncResult) msg.obj; |
| 1192 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1193 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1194 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1195 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1196 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1197 | // Service Class is a bit mask per 3gpp 27.007. |
| 1198 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1199 | if (callForwardResults.length > 1 |
| 1200 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1201 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1202 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1203 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1204 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1205 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1206 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1207 | } |
| 1208 | } else { |
| 1209 | if (ar.result == null) { |
| 1210 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1211 | } |
| 1212 | if (ar.exception != null) { |
| 1213 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1214 | } |
| 1215 | if (ar.exception instanceof CommandException) { |
| 1216 | CommandException.Error error = |
| 1217 | ((CommandException) (ar.exception)).getCommandError(); |
| 1218 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1219 | callForwardingStatus = |
| 1220 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1221 | } |
| 1222 | } |
| 1223 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1224 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1225 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1226 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1227 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1228 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1229 | request = (MainThreadRequest) msg.obj; |
| 1230 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1231 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1232 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1233 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1234 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1235 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1236 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1237 | ar = (AsyncResult) msg.obj; |
| 1238 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1239 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1240 | Consumer<Integer> callback = |
| 1241 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1242 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1243 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1244 | if (ar.exception instanceof CommandException) { |
| 1245 | CommandException.Error error = |
| 1246 | ((CommandException) (ar.exception)).getCommandError(); |
| 1247 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1248 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1249 | } else { |
| 1250 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1251 | } |
| 1252 | } else { |
| 1253 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1254 | } |
| 1255 | } else { |
| 1256 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1257 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1258 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1259 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1260 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1261 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1262 | ar = (AsyncResult) msg.obj; |
| 1263 | request = (MainThreadRequest) ar.userObj; |
| 1264 | CellNetworkScanResult cellScanResult; |
| 1265 | if (ar.exception == null && ar.result != null) { |
| 1266 | cellScanResult = new CellNetworkScanResult( |
| 1267 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1268 | (List<OperatorInfo>) ar.result); |
| 1269 | } else { |
| 1270 | if (ar.result == null) { |
| 1271 | loge("getCellNetworkScanResults: Empty response"); |
| 1272 | } |
| 1273 | if (ar.exception != null) { |
| 1274 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1275 | } |
| 1276 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1277 | if (ar.exception instanceof CommandException) { |
| 1278 | CommandException.Error error = |
| 1279 | ((CommandException) (ar.exception)).getCommandError(); |
| 1280 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1281 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1282 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1283 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1284 | } |
| 1285 | } |
| 1286 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1287 | } |
| 1288 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1289 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1290 | break; |
| 1291 | |
| 1292 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1293 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1294 | ManualNetworkSelectionArgument selArg = |
| 1295 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1296 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1297 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1298 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1299 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1300 | break; |
| 1301 | |
| 1302 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1303 | ar = (AsyncResult) msg.obj; |
| 1304 | request = (MainThreadRequest) ar.userObj; |
| 1305 | if (ar.exception == null) { |
| 1306 | request.result = true; |
| 1307 | } else { |
| 1308 | request.result = false; |
| 1309 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1310 | } |
| 1311 | notifyRequester(request); |
| 1312 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1313 | break; |
| 1314 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1315 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1316 | request = (MainThreadRequest) msg.obj; |
| 1317 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1318 | if (defaultPhone != null) { |
| 1319 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1320 | } else { |
| 1321 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1322 | Bundle bundle = new Bundle(); |
| 1323 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1324 | new ModemActivityInfo(0, 0, 0, |
| 1325 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1326 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1327 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1328 | break; |
| 1329 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1330 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1331 | ar = (AsyncResult) msg.obj; |
| 1332 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1333 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1334 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1335 | ModemActivityInfo ret = null; |
| 1336 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1337 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1338 | // Update the last modem activity info and the result of the request. |
| 1339 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1340 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1341 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1342 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1343 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1344 | .getTransmitTimeMillis(); |
| 1345 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1346 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1347 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1348 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1349 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1350 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1351 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1352 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1353 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1354 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1355 | info.getReceiveTimeMillis() |
| 1356 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1357 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1358 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1359 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1360 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1361 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1362 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1363 | } else { |
| 1364 | if (ar.result == null) { |
| 1365 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1366 | error = TelephonyManager.ModemActivityInfoException |
| 1367 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1368 | } else if (ar.exception instanceof CommandException) { |
| 1369 | loge("queryModemActivityInfo: CommandException: " + |
| 1370 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1371 | error = TelephonyManager.ModemActivityInfoException |
| 1372 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1373 | } else { |
| 1374 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1375 | error = TelephonyManager.ModemActivityInfoException |
| 1376 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1377 | } |
| 1378 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1379 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1380 | if (ret != null) { |
| 1381 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1382 | } else { |
| 1383 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1384 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1385 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1386 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1387 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1388 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1389 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1390 | case CMD_SET_ALLOWED_CARRIERS: |
| 1391 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1392 | CarrierRestrictionRules argument = |
| 1393 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1394 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1395 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1396 | break; |
| 1397 | |
| 1398 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1399 | ar = (AsyncResult) msg.obj; |
| 1400 | request = (MainThreadRequest) ar.userObj; |
| 1401 | if (ar.exception == null && ar.result != null) { |
| 1402 | request.result = ar.result; |
| 1403 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1404 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1405 | if (ar.exception instanceof CommandException) { |
| 1406 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1407 | CommandException.Error error = |
| 1408 | ((CommandException) (ar.exception)).getCommandError(); |
| 1409 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1410 | request.result = |
| 1411 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1412 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1413 | } else { |
| 1414 | loge("setAllowedCarriers: Unknown exception"); |
| 1415 | } |
| 1416 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1417 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1418 | break; |
| 1419 | |
| 1420 | case CMD_GET_ALLOWED_CARRIERS: |
| 1421 | request = (MainThreadRequest) msg.obj; |
| 1422 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1423 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1424 | break; |
| 1425 | |
| 1426 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1427 | ar = (AsyncResult) msg.obj; |
| 1428 | request = (MainThreadRequest) ar.userObj; |
| 1429 | if (ar.exception == null && ar.result != null) { |
| 1430 | request.result = ar.result; |
| 1431 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1432 | request.result = new IllegalStateException( |
| 1433 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1434 | if (ar.result == null) { |
| 1435 | loge("getAllowedCarriers: Empty response"); |
| 1436 | } else if (ar.exception instanceof CommandException) { |
| 1437 | loge("getAllowedCarriers: CommandException: " + |
| 1438 | ar.exception); |
| 1439 | } else { |
| 1440 | loge("getAllowedCarriers: Unknown exception"); |
| 1441 | } |
| 1442 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1443 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1444 | break; |
| 1445 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1446 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1447 | ar = (AsyncResult) msg.obj; |
| 1448 | request = (MainThreadRequest) ar.userObj; |
| 1449 | if (ar.exception == null && ar.result != null) { |
| 1450 | request.result = ar.result; |
| 1451 | } else { |
| 1452 | request.result = new IllegalArgumentException( |
| 1453 | "Failed to retrieve Forbidden Plmns"); |
| 1454 | if (ar.result == null) { |
| 1455 | loge("getForbiddenPlmns: Empty response"); |
| 1456 | } else { |
| 1457 | loge("getForbiddenPlmns: Unknown exception"); |
| 1458 | } |
| 1459 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1460 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1461 | break; |
| 1462 | |
| 1463 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1464 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1465 | uiccPort = getUiccPortFromRequest(request); |
| 1466 | if (uiccPort == null) { |
| 1467 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1468 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1469 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1470 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1471 | break; |
| 1472 | } |
| 1473 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1474 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1475 | if (uiccApp == null) { |
| 1476 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1477 | + appType); |
| 1478 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1479 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1480 | break; |
| 1481 | } else { |
| 1482 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1483 | + " specified type -- " + appType); |
| 1484 | } |
| 1485 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1486 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1487 | onCompleted); |
| 1488 | break; |
| 1489 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1490 | case CMD_SWITCH_SLOTS: |
| 1491 | request = (MainThreadRequest) msg.obj; |
| 1492 | int[] physicalSlots = (int[]) request.argument; |
| 1493 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1494 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1495 | break; |
| 1496 | |
| 1497 | case EVENT_SWITCH_SLOTS_DONE: |
| 1498 | ar = (AsyncResult) msg.obj; |
| 1499 | request = (MainThreadRequest) ar.userObj; |
| 1500 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1501 | notifyRequester(request); |
| 1502 | break; |
| 1503 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1504 | request = (MainThreadRequest) msg.obj; |
| 1505 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1506 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1507 | break; |
| 1508 | |
| 1509 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1510 | ar = (AsyncResult) msg.obj; |
| 1511 | request = (MainThreadRequest) ar.userObj; |
| 1512 | if (ar.exception != null) { |
| 1513 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1514 | } else { |
| 1515 | int mode = ((int[]) ar.result)[0]; |
| 1516 | if (mode == 0) { |
| 1517 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1518 | } else { |
| 1519 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1520 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1521 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1522 | notifyRequester(request); |
| 1523 | break; |
| 1524 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1525 | request = (MainThreadRequest) msg.obj; |
| 1526 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1527 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1528 | break; |
| 1529 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1530 | ar = (AsyncResult) msg.obj; |
| 1531 | request = (MainThreadRequest) ar.userObj; |
| 1532 | if (ar.exception != null) { |
| 1533 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1534 | } else { |
| 1535 | request.result = ((int[]) ar.result)[0]; |
| 1536 | } |
| 1537 | notifyRequester(request); |
| 1538 | break; |
| 1539 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1540 | request = (MainThreadRequest) msg.obj; |
| 1541 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1542 | int mode = (int) request.argument; |
| 1543 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1544 | break; |
| 1545 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1546 | ar = (AsyncResult) msg.obj; |
| 1547 | request = (MainThreadRequest) ar.userObj; |
| 1548 | request.result = ar.exception == null; |
| 1549 | notifyRequester(request); |
| 1550 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1551 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1552 | request = (MainThreadRequest) msg.obj; |
| 1553 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1554 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1555 | break; |
| 1556 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1557 | ar = (AsyncResult) msg.obj; |
| 1558 | request = (MainThreadRequest) ar.userObj; |
| 1559 | if (ar.exception != null) { |
| 1560 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1561 | } else { |
| 1562 | request.result = ((int[]) ar.result)[0]; |
| 1563 | } |
| 1564 | notifyRequester(request); |
| 1565 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1566 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1567 | request = (MainThreadRequest) msg.obj; |
| 1568 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1569 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1570 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1571 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1572 | break; |
| 1573 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1574 | ar = (AsyncResult) msg.obj; |
| 1575 | request = (MainThreadRequest) ar.userObj; |
| 1576 | request.result = ar.exception == null; |
| 1577 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1578 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1579 | case CMD_GET_ALL_CELL_INFO: |
| 1580 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1581 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1582 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1583 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1584 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1585 | ar = (AsyncResult) msg.obj; |
| 1586 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1587 | // If a timeout occurs, the response will be null |
| 1588 | request.result = (ar.exception == null && ar.result != null) |
| 1589 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1590 | synchronized (request) { |
| 1591 | request.notifyAll(); |
| 1592 | } |
| 1593 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1594 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1595 | request = (MainThreadRequest) msg.obj; |
| 1596 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1597 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1598 | break; |
| 1599 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1600 | ar = (AsyncResult) msg.obj; |
| 1601 | request = (MainThreadRequest) ar.userObj; |
| 1602 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1603 | try { |
| 1604 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1605 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1606 | cb.onError( |
| 1607 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1608 | ar.exception.getClass().getName(), |
| 1609 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1610 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1611 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1612 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1613 | } else { |
| 1614 | // use the result as returned |
| 1615 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1616 | } |
| 1617 | } catch (RemoteException re) { |
| 1618 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1619 | } |
| 1620 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1621 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1622 | request = (MainThreadRequest) msg.obj; |
| 1623 | WorkSource ws = (WorkSource) request.argument; |
| 1624 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1625 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1626 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1627 | } |
| 1628 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1629 | ar = (AsyncResult) msg.obj; |
| 1630 | request = (MainThreadRequest) ar.userObj; |
| 1631 | if (ar.exception == null) { |
| 1632 | request.result = ar.result; |
| 1633 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1634 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1635 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1636 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1637 | } |
| 1638 | |
| 1639 | synchronized (request) { |
| 1640 | request.notifyAll(); |
| 1641 | } |
| 1642 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1643 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1644 | case CMD_MODEM_REBOOT: |
| 1645 | request = (MainThreadRequest) msg.obj; |
| 1646 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1647 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1648 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1649 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1650 | handleNullReturnEvent(msg, "rebootModem"); |
| 1651 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1652 | case CMD_REQUEST_ENABLE_MODEM: |
| 1653 | request = (MainThreadRequest) msg.obj; |
| 1654 | boolean enable = (boolean) request.argument; |
| 1655 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1656 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1657 | PhoneConfigurationManager.getInstance() |
| 1658 | .enablePhone(request.phone, enable, onCompleted); |
| 1659 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1660 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1661 | ar = (AsyncResult) msg.obj; |
| 1662 | request = (MainThreadRequest) ar.userObj; |
| 1663 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1664 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1665 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1666 | if ((boolean) request.result) { |
| 1667 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1668 | updateModemStateMetrics(); |
| 1669 | } else { |
| 1670 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1671 | + ar.exception); |
| 1672 | } |
| 1673 | notifyRequester(request); |
| 1674 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1675 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1676 | case CMD_GET_MODEM_STATUS: |
| 1677 | request = (MainThreadRequest) msg.obj; |
| 1678 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1679 | PhoneConfigurationManager.getInstance() |
| 1680 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1681 | break; |
| 1682 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1683 | ar = (AsyncResult) msg.obj; |
| 1684 | request = (MainThreadRequest) ar.userObj; |
| 1685 | int id = request.phone.getPhoneId(); |
| 1686 | if (ar.exception == null && ar.result != null) { |
| 1687 | request.result = ar.result; |
| 1688 | //update the cache as modem status has changed |
| 1689 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1690 | (boolean) request.result); |
| 1691 | } else { |
| 1692 | // Return true if modem status cannot be retrieved. For most cases, |
| 1693 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1694 | // and disable modem are not supported. Modem is always on. |
| 1695 | // TODO: this should be fixed in R to support a third |
| 1696 | // status UNKNOWN b/131631629 |
| 1697 | request.result = true; |
| 1698 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1699 | + ar.exception); |
| 1700 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1701 | notifyRequester(request); |
| 1702 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1703 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1704 | request = (MainThreadRequest) msg.obj; |
| 1705 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1706 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1707 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1708 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1709 | break; |
| 1710 | } |
| 1711 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1712 | ar = (AsyncResult) msg.obj; |
| 1713 | request = (MainThreadRequest) ar.userObj; |
| 1714 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1715 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1716 | args.second.accept(ar.exception == null); |
| 1717 | notifyRequester(request); |
| 1718 | break; |
| 1719 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1720 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1721 | request = (MainThreadRequest) msg.obj; |
| 1722 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1723 | Phone phone = getPhoneFromRequest(request); |
| 1724 | if (phone != null) { |
| 1725 | phone.getSystemSelectionChannels(onCompleted); |
| 1726 | } else { |
| 1727 | loge("getSystemSelectionChannels: No phone object"); |
| 1728 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1729 | notifyRequester(request); |
| 1730 | } |
| 1731 | break; |
| 1732 | } |
| 1733 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1734 | ar = (AsyncResult) msg.obj; |
| 1735 | request = (MainThreadRequest) ar.userObj; |
| 1736 | if (ar.exception == null && ar.result != null) { |
| 1737 | request.result = ar.result; |
| 1738 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1739 | request.result = new IllegalStateException( |
| 1740 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1741 | if (ar.result == null) { |
| 1742 | loge("getSystemSelectionChannels: Empty response"); |
| 1743 | } else { |
| 1744 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1745 | } |
| 1746 | } |
| 1747 | notifyRequester(request); |
| 1748 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1749 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1750 | ar = (AsyncResult) msg.obj; |
| 1751 | request = (MainThreadRequest) ar.userObj; |
| 1752 | if (ar.exception == null && ar.result != null) { |
| 1753 | request.result = ar.result; |
| 1754 | } else { |
| 1755 | request.result = -1; |
| 1756 | loge("Failed to set Forbidden Plmns"); |
| 1757 | if (ar.result == null) { |
| 1758 | loge("setForbidenPlmns: Empty response"); |
| 1759 | } else if (ar.exception != null) { |
| 1760 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1761 | request.result = -1; |
| 1762 | } else { |
| 1763 | loge("setForbiddenPlmns: Unknown exception"); |
| 1764 | } |
| 1765 | } |
| 1766 | notifyRequester(request); |
| 1767 | break; |
| 1768 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1769 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1770 | uiccPort = getUiccPortFromRequest(request); |
| 1771 | if (uiccPort == null) { |
| 1772 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1773 | request.result = -1; |
| 1774 | notifyRequester(request); |
| 1775 | break; |
| 1776 | } |
| 1777 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1778 | (Pair<Integer, List<String>>) request.argument; |
| 1779 | appType = setFplmnsArgs.first; |
| 1780 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1781 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1782 | if (uiccApp == null) { |
| 1783 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1784 | request.result = -1; |
| 1785 | loge("Failed to get UICC App"); |
| 1786 | notifyRequester(request); |
| 1787 | } else { |
| 1788 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1789 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1790 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1791 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1792 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1793 | case CMD_ERASE_MODEM_CONFIG: |
| 1794 | request = (MainThreadRequest) msg.obj; |
| 1795 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1796 | defaultPhone.eraseModemConfig(onCompleted); |
| 1797 | break; |
| 1798 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1799 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1800 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1801 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1802 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1803 | request = (MainThreadRequest) msg.obj; |
| 1804 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1805 | notifyRequester(request); |
| 1806 | break; |
| 1807 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1808 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1809 | request = (MainThreadRequest) msg.obj; |
| 1810 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1811 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1812 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1813 | changed.first, changed.second, onCompleted); |
| 1814 | break; |
| 1815 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1816 | ar = (AsyncResult) msg.obj; |
| 1817 | request = (MainThreadRequest) ar.userObj; |
| 1818 | if (ar.exception == null) { |
| 1819 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1820 | // If the operation is successful, update the PIN storage |
| 1821 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1822 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1823 | UiccController.getInstance().getPinStorage() |
| 1824 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1825 | } else { |
| 1826 | request.result = msg.arg1; |
| 1827 | } |
| 1828 | notifyRequester(request); |
| 1829 | break; |
| 1830 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1831 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1832 | request = (MainThreadRequest) msg.obj; |
| 1833 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1834 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1835 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1836 | enabled.first, enabled.second, onCompleted); |
| 1837 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1838 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1839 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1840 | ar = (AsyncResult) msg.obj; |
| 1841 | request = (MainThreadRequest) ar.userObj; |
| 1842 | if (ar.exception == null) { |
| 1843 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1844 | // If the operation is successful, update the PIN storage |
| 1845 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1846 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1847 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1848 | UiccController.getInstance().getPinStorage() |
| 1849 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1850 | } else { |
| 1851 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1852 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1853 | } else { |
| 1854 | request.result = msg.arg1; |
| 1855 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1856 | |
| 1857 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1858 | notifyRequester(request); |
| 1859 | break; |
| 1860 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1861 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1862 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1863 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1864 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1865 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1866 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1867 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1868 | |
| 1869 | case CMD_SET_DATA_THROTTLING: { |
| 1870 | request = (MainThreadRequest) msg.obj; |
| 1871 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1872 | DataThrottlingRequest dataThrottlingRequest = |
| 1873 | (DataThrottlingRequest) request.argument; |
| 1874 | Phone phone = getPhoneFromRequest(request); |
| 1875 | if (phone != null) { |
| 1876 | phone.setDataThrottling(onCompleted, |
| 1877 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1878 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1879 | } else { |
| 1880 | loge("setDataThrottling: No phone object"); |
| 1881 | request.result = |
| 1882 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1883 | notifyRequester(request); |
| 1884 | } |
| 1885 | |
| 1886 | break; |
| 1887 | } |
| 1888 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1889 | ar = (AsyncResult) msg.obj; |
| 1890 | request = (MainThreadRequest) ar.userObj; |
| 1891 | |
| 1892 | if (ar.exception == null) { |
| 1893 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1894 | } else if (ar.exception instanceof CommandException) { |
| 1895 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1896 | CommandException.Error error = |
| 1897 | ((CommandException) (ar.exception)).getCommandError(); |
| 1898 | |
| 1899 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1900 | request.result = TelephonyManager |
| 1901 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1902 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1903 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 1904 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1905 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1906 | } else { |
| 1907 | request.result = |
| 1908 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1909 | } |
| 1910 | } else { |
| 1911 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1912 | } |
| 1913 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1914 | notifyRequester(request); |
| 1915 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1916 | |
| 1917 | case CMD_SET_SIM_POWER: { |
| 1918 | request = (MainThreadRequest) msg.obj; |
| 1919 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1920 | request = (MainThreadRequest) msg.obj; |
| 1921 | int stateToSet = |
| 1922 | ((Pair<Integer, IIntegerConsumer>) |
| 1923 | request.argument).first; |
| 1924 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1925 | break; |
| 1926 | } |
| 1927 | case EVENT_SET_SIM_POWER_DONE: { |
| 1928 | ar = (AsyncResult) msg.obj; |
| 1929 | request = (MainThreadRequest) ar.userObj; |
| 1930 | IIntegerConsumer callback = |
| 1931 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1932 | if (ar.exception != null) { |
| 1933 | loge("setSimPower exception: " + ar.exception); |
| 1934 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1935 | .RESULT_ERROR_UNKNOWN; |
| 1936 | if (ar.exception instanceof CommandException) { |
| 1937 | CommandException.Error error = |
| 1938 | ((CommandException) (ar.exception)).getCommandError(); |
| 1939 | if (error == CommandException.Error.SIM_ERR) { |
| 1940 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1941 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1942 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1943 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1944 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1945 | } else { |
| 1946 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1947 | } |
| 1948 | } |
| 1949 | try { |
| 1950 | callback.accept(errorCode); |
| 1951 | } catch (RemoteException e) { |
| 1952 | // Ignore if the remote process is no longer available to call back. |
| 1953 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1954 | } |
| 1955 | } else { |
| 1956 | try { |
| 1957 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1958 | } catch (RemoteException e) { |
| 1959 | // Ignore if the remote process is no longer available to call back. |
| 1960 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1961 | } |
| 1962 | } |
| 1963 | break; |
| 1964 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1965 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1966 | request = (MainThreadRequest) msg.obj; |
| 1967 | |
| 1968 | final Phone phone = getPhoneFromRequest(request); |
| 1969 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1970 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1971 | notifyRequester(request); |
| 1972 | break; |
| 1973 | } |
| 1974 | |
| 1975 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1976 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1977 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1978 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 1979 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1980 | request.subId, pair.first /*callingUid*/, |
| 1981 | pair.second /*request*/, onCompleted); |
| 1982 | break; |
| 1983 | } |
| 1984 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1985 | ar = (AsyncResult) msg.obj; |
| 1986 | request = (MainThreadRequest) ar.userObj; |
| 1987 | // request.result will be the exception of ar if present, true otherwise. |
| 1988 | // Be cautious not to leave result null which will wait() forever |
| 1989 | request.result = ar.exception != null ? ar.exception : true; |
| 1990 | notifyRequester(request); |
| 1991 | break; |
| 1992 | } |
| 1993 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1994 | request = (MainThreadRequest) msg.obj; |
| 1995 | |
| 1996 | Phone phone = getPhoneFromRequest(request); |
| 1997 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1998 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1999 | notifyRequester(request); |
| 2000 | break; |
| 2001 | } |
| 2002 | |
| 2003 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2004 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2005 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2006 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2007 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2008 | request.subId, pair.first /*callingUid*/, |
| 2009 | pair.second /*request*/, onCompleted); |
| 2010 | break; |
| 2011 | } |
| 2012 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2013 | ar = (AsyncResult) msg.obj; |
| 2014 | request = (MainThreadRequest) ar.userObj; |
| 2015 | request.result = ar.exception != null ? ar.exception : true; |
| 2016 | notifyRequester(request); |
| 2017 | break; |
| 2018 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2019 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2020 | case CMD_GET_SLICING_CONFIG: { |
| 2021 | request = (MainThreadRequest) msg.obj; |
| 2022 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2023 | request.phone.getSlicingConfig(onCompleted); |
| 2024 | break; |
| 2025 | } |
| 2026 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2027 | ar = (AsyncResult) msg.obj; |
| 2028 | request = (MainThreadRequest) ar.userObj; |
| 2029 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2030 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2031 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2032 | Bundle bundle = new Bundle(); |
| 2033 | int resultCode = 0; |
| 2034 | if (ar.exception != null) { |
| 2035 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2036 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2037 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2038 | } else if (ar.result == null) { |
| 2039 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2040 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2041 | } else { |
| 2042 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2043 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2044 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2045 | } |
| 2046 | |
| 2047 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2048 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2049 | } |
| 2050 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2051 | result.send(resultCode, bundle); |
| 2052 | notifyRequester(request); |
| 2053 | break; |
| 2054 | } |
| 2055 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2056 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2057 | request = (MainThreadRequest) msg.obj; |
| 2058 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2059 | UiccController.getInstance().getPinStorage() |
| 2060 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2061 | notifyRequester(request); |
| 2062 | break; |
| 2063 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2064 | default: |
| 2065 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2066 | break; |
| 2067 | } |
| 2068 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2069 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2070 | private void notifyRequester(MainThreadRequest request) { |
| 2071 | synchronized (request) { |
| 2072 | request.notifyAll(); |
| 2073 | } |
| 2074 | } |
| 2075 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2076 | private void handleNullReturnEvent(Message msg, String command) { |
| 2077 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2078 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2079 | if (ar.exception == null) { |
| 2080 | request.result = true; |
| 2081 | } else { |
| 2082 | request.result = false; |
| 2083 | if (ar.exception instanceof CommandException) { |
| 2084 | loge(command + ": CommandException: " + ar.exception); |
| 2085 | } else { |
| 2086 | loge(command + ": Unknown exception"); |
| 2087 | } |
| 2088 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2089 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2090 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2091 | } |
| 2092 | |
| 2093 | /** |
| 2094 | * Posts the specified command to be executed on the main thread, |
| 2095 | * waits for the request to complete, and returns the result. |
| 2096 | * @see #sendRequestAsync |
| 2097 | */ |
| 2098 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2099 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2100 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | /** |
| 2104 | * Posts the specified command to be executed on the main thread, |
| 2105 | * waits for the request to complete, and returns the result. |
| 2106 | * @see #sendRequestAsync |
| 2107 | */ |
| 2108 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2109 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2110 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2111 | } |
| 2112 | |
| 2113 | /** |
| 2114 | * Posts the specified command to be executed on the main thread, |
| 2115 | * waits for the request to complete, and returns the result. |
| 2116 | * @see #sendRequestAsync |
| 2117 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2118 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2119 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2120 | } |
| 2121 | |
| 2122 | /** |
| 2123 | * Posts the specified command to be executed on the main thread, |
| 2124 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2125 | * if not timeout or null otherwise. |
| 2126 | * @see #sendRequestAsync |
| 2127 | */ |
| 2128 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2129 | long timeoutInMs) { |
| 2130 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | /** |
| 2134 | * Posts the specified command to be executed on the main thread, |
| 2135 | * waits for the request to complete, and returns the result. |
| 2136 | * @see #sendRequestAsync |
| 2137 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2138 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2139 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2140 | } |
| 2141 | |
| 2142 | /** |
| 2143 | * Posts the specified command to be executed on the main thread, |
| 2144 | * waits for the request to complete, and returns the result. |
| 2145 | * @see #sendRequestAsync |
| 2146 | */ |
| 2147 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2148 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2149 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2150 | } |
| 2151 | |
| 2152 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2153 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2154 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2155 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2156 | * @see #sendRequestAsync |
| 2157 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2158 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2159 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2160 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2161 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2162 | } |
| 2163 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2164 | MainThreadRequest request = null; |
| 2165 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2166 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2167 | } else if (phone != null) { |
| 2168 | request = new MainThreadRequest(argument, phone, workSource); |
| 2169 | } else { |
| 2170 | request = new MainThreadRequest(argument, subId, workSource); |
| 2171 | } |
| 2172 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2173 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2174 | msg.sendToTarget(); |
| 2175 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2176 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2177 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2178 | if (timeoutInMs >= 0) { |
| 2179 | // Wait for at least timeoutInMs before returning null request result |
| 2180 | long now = SystemClock.elapsedRealtime(); |
| 2181 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2182 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2183 | try { |
| 2184 | request.wait(deadline - now); |
| 2185 | } catch (InterruptedException e) { |
| 2186 | // Do nothing, go back and check if request is completed or timeout |
| 2187 | } finally { |
| 2188 | now = SystemClock.elapsedRealtime(); |
| 2189 | } |
| 2190 | } |
| 2191 | } else { |
| 2192 | // Wait for the request to complete |
| 2193 | while (request.result == null) { |
| 2194 | try { |
| 2195 | request.wait(); |
| 2196 | } catch (InterruptedException e) { |
| 2197 | // Do nothing, go back and wait until the request is complete |
| 2198 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2199 | } |
| 2200 | } |
| 2201 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2202 | if (request.result == null) { |
| 2203 | Log.wtf(LOG_TAG, |
| 2204 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2205 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2206 | return request.result; |
| 2207 | } |
| 2208 | |
| 2209 | /** |
| 2210 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2211 | * Posts the specified command to be executed on the main thread, and |
| 2212 | * returns immediately. |
| 2213 | * @see #sendRequest |
| 2214 | */ |
| 2215 | private void sendRequestAsync(int command) { |
| 2216 | mMainThreadHandler.sendEmptyMessage(command); |
| 2217 | } |
| 2218 | |
| 2219 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2220 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2221 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2222 | */ |
| 2223 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2224 | sendRequestAsync(command, argument, null, null); |
| 2225 | } |
| 2226 | |
| 2227 | /** |
| 2228 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2229 | * @see {@link #sendRequest(int,Object)} |
| 2230 | */ |
| 2231 | private void sendRequestAsync( |
| 2232 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2233 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2234 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2235 | msg.sendToTarget(); |
| 2236 | } |
| 2237 | |
| 2238 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2239 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2240 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2241 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2242 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2243 | synchronized (PhoneInterfaceManager.class) { |
| 2244 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2245 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2246 | } else { |
| 2247 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2248 | } |
| 2249 | return sInstance; |
| 2250 | } |
| 2251 | } |
| 2252 | |
| 2253 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2254 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2255 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2256 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2257 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2258 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2259 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2260 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2261 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2262 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2263 | mTelephonySharedPreferences = |
| 2264 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2265 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2266 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2267 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2268 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2269 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2270 | publish(); |
| 2271 | } |
| 2272 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2273 | private Phone getDefaultPhone() { |
| 2274 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2275 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2276 | } |
| 2277 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2278 | private void publish() { |
| 2279 | if (DBG) log("publish: " + this); |
| 2280 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2281 | TelephonyFrameworkInitializer |
| 2282 | .getTelephonyServiceManager() |
| 2283 | .getTelephonyServiceRegisterer() |
| 2284 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2285 | } |
| 2286 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2287 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2288 | if (request.phone != null) { |
| 2289 | return request.phone; |
| 2290 | } else { |
| 2291 | return getPhoneFromSubId(request.subId); |
| 2292 | } |
| 2293 | } |
| 2294 | |
| 2295 | private Phone getPhoneFromSubId(int subId) { |
| 2296 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2297 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2298 | } |
| 2299 | |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2300 | private UiccPort getUiccPortFromRequest(MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2301 | Phone phone = getPhoneFromRequest(request); |
| 2302 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2303 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2304 | } |
| 2305 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2306 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2307 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2308 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2309 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2310 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2311 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2312 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2313 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2314 | } |
| 2315 | |
| 2316 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2317 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2318 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2319 | } |
| 2320 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2321 | private boolean isImsAvailableOnDevice() { |
| 2322 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2323 | if (pm == null) { |
| 2324 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2325 | // so do not throw error and allow. |
| 2326 | return true; |
| 2327 | } |
| 2328 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2329 | } |
| 2330 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2331 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2332 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2333 | } |
| 2334 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2335 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2336 | if (DBG) log("dial: " + number); |
| 2337 | // No permission check needed here: This is just a wrapper around the |
| 2338 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2339 | // the UI before it does anything. |
| 2340 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2341 | final long identity = Binder.clearCallingIdentity(); |
| 2342 | try { |
| 2343 | String url = createTelUrl(number); |
| 2344 | if (url == null) { |
| 2345 | return; |
| 2346 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2347 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2348 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2349 | PhoneConstants.State state = mCM.getState(subId); |
| 2350 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2351 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2352 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2353 | mApp.startActivity(intent); |
| 2354 | } |
| 2355 | } finally { |
| 2356 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2357 | } |
| 2358 | } |
| 2359 | |
| 2360 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2361 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2362 | } |
| 2363 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2364 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2365 | if (DBG) log("call: " + number); |
| 2366 | |
| 2367 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2368 | // need to do a permission check since we're calling startActivity() |
| 2369 | // from the context of the phone app. |
| 2370 | enforceCallPermission(); |
| 2371 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2372 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2373 | != AppOpsManager.MODE_ALLOWED) { |
| 2374 | return; |
| 2375 | } |
| 2376 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2377 | final long identity = Binder.clearCallingIdentity(); |
| 2378 | try { |
| 2379 | String url = createTelUrl(number); |
| 2380 | if (url == null) { |
| 2381 | return; |
| 2382 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2383 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2384 | boolean isValid = false; |
| 2385 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2386 | if (slist != null) { |
| 2387 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2388 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2389 | isValid = true; |
| 2390 | break; |
| 2391 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2392 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2393 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2394 | if (!isValid) { |
| 2395 | return; |
| 2396 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2397 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2398 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2399 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2400 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2401 | mApp.startActivity(intent); |
| 2402 | } finally { |
| 2403 | Binder.restoreCallingIdentity(identity); |
| 2404 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2405 | } |
| 2406 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2407 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2408 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2409 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2410 | } |
| 2411 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2412 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2413 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2414 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2415 | } |
| 2416 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2417 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2418 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2419 | |
| 2420 | final long identity = Binder.clearCallingIdentity(); |
| 2421 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2422 | Phone phone = getPhone(subId); |
| 2423 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2424 | checkSimPin.start(); |
| 2425 | return checkSimPin.unlockSim(null, pin); |
| 2426 | } finally { |
| 2427 | Binder.restoreCallingIdentity(identity); |
| 2428 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2429 | } |
| 2430 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2431 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2432 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2433 | |
| 2434 | final long identity = Binder.clearCallingIdentity(); |
| 2435 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2436 | Phone phone = getPhone(subId); |
| 2437 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2438 | checkSimPuk.start(); |
| 2439 | return checkSimPuk.unlockSim(puk, pin); |
| 2440 | } finally { |
| 2441 | Binder.restoreCallingIdentity(identity); |
| 2442 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2443 | } |
| 2444 | |
| 2445 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2446 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2447 | * a synchronous one. |
| 2448 | */ |
| 2449 | private static class UnlockSim extends Thread { |
| 2450 | |
| 2451 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2452 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2453 | |
| 2454 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2455 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2456 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2457 | |
| 2458 | // For replies from SimCard interface |
| 2459 | private Handler mHandler; |
| 2460 | |
| 2461 | // For async handler to identify request type |
| 2462 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2463 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2464 | UnlockSim(int phoneId, IccCard simCard) { |
| 2465 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2466 | mSimCard = simCard; |
| 2467 | } |
| 2468 | |
| 2469 | @Override |
| 2470 | public void run() { |
| 2471 | Looper.prepare(); |
| 2472 | synchronized (UnlockSim.this) { |
| 2473 | mHandler = new Handler() { |
| 2474 | @Override |
| 2475 | public void handleMessage(Message msg) { |
| 2476 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2477 | switch (msg.what) { |
| 2478 | case SUPPLY_PIN_COMPLETE: |
| 2479 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2480 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2481 | mRetryCount = msg.arg1; |
| 2482 | if (ar.exception != null) { |
| 2483 | if (ar.exception instanceof CommandException && |
| 2484 | ((CommandException)(ar.exception)).getCommandError() |
| 2485 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2486 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2487 | } //When UiccCardApp dispose,handle message and return exception |
| 2488 | else if (ar.exception instanceof CommandException && |
| 2489 | ((CommandException) (ar.exception)).getCommandError() |
| 2490 | == CommandException.Error.ABORTED) { |
| 2491 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2492 | } else { |
| 2493 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2494 | } |
| 2495 | } else { |
| 2496 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2497 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2498 | mDone = true; |
| 2499 | UnlockSim.this.notifyAll(); |
| 2500 | } |
| 2501 | break; |
| 2502 | } |
| 2503 | } |
| 2504 | }; |
| 2505 | UnlockSim.this.notifyAll(); |
| 2506 | } |
| 2507 | Looper.loop(); |
| 2508 | } |
| 2509 | |
| 2510 | /* |
| 2511 | * Use PIN or PUK to unlock SIM card |
| 2512 | * |
| 2513 | * If PUK is null, unlock SIM card with PIN |
| 2514 | * |
| 2515 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2516 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2517 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2518 | |
| 2519 | while (mHandler == null) { |
| 2520 | try { |
| 2521 | wait(); |
| 2522 | } catch (InterruptedException e) { |
| 2523 | Thread.currentThread().interrupt(); |
| 2524 | } |
| 2525 | } |
| 2526 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2527 | |
| 2528 | if (puk == null) { |
| 2529 | mSimCard.supplyPin(pin, callback); |
| 2530 | } else { |
| 2531 | mSimCard.supplyPuk(puk, pin, callback); |
| 2532 | } |
| 2533 | |
| 2534 | while (!mDone) { |
| 2535 | try { |
| 2536 | Log.d(LOG_TAG, "wait for done"); |
| 2537 | wait(); |
| 2538 | } catch (InterruptedException e) { |
| 2539 | // Restore the interrupted status |
| 2540 | Thread.currentThread().interrupt(); |
| 2541 | } |
| 2542 | } |
| 2543 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2544 | int[] resultArray = new int[2]; |
| 2545 | resultArray[0] = mResult; |
| 2546 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2547 | |
| 2548 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2549 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2550 | } |
| 2551 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2552 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2553 | } |
| 2554 | } |
| 2555 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2556 | /** |
| 2557 | * This method has been removed due to privacy and stability concerns. |
| 2558 | */ |
| 2559 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2560 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2561 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2562 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2563 | } |
| 2564 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2565 | @Override |
| 2566 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2567 | mApp.getSystemService(AppOpsManager.class) |
| 2568 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2569 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2570 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2571 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2572 | // Callers targeting S have no business invoking this method. |
| 2573 | return; |
| 2574 | } |
| 2575 | |
| 2576 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2577 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2578 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2579 | .setCallingPackage(callingPackage) |
| 2580 | .setCallingFeatureId(null) |
| 2581 | .setCallingPid(Binder.getCallingPid()) |
| 2582 | .setCallingUid(Binder.getCallingUid()) |
| 2583 | .setMethod("updateServiceLocation") |
| 2584 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2585 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2586 | .build()); |
| 2587 | // Apps that lack location permission have no business calling this method; |
| 2588 | // however, because no permission was declared in the public API, denials must |
| 2589 | // all be "soft". |
| 2590 | switch (locationResult) { |
| 2591 | case DENIED_HARD: /* fall through */ |
| 2592 | case DENIED_SOFT: |
| 2593 | return; |
| 2594 | } |
| 2595 | |
| 2596 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2597 | final long identity = Binder.clearCallingIdentity(); |
| 2598 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2599 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2600 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2601 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2602 | } |
| 2603 | } finally { |
| 2604 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2605 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2606 | } |
| 2607 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2608 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2609 | @Override |
| 2610 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2611 | return isRadioOnWithFeature(callingPackage, null); |
| 2612 | } |
| 2613 | |
| 2614 | |
| 2615 | @Override |
| 2616 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2617 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2618 | callingFeatureId); |
| 2619 | } |
| 2620 | |
| 2621 | @Deprecated |
| 2622 | @Override |
| 2623 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2624 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2625 | } |
| 2626 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2627 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2628 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2629 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2630 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2631 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2632 | return false; |
| 2633 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2634 | |
| 2635 | final long identity = Binder.clearCallingIdentity(); |
| 2636 | try { |
| 2637 | return isRadioOnForSubscriber(subId); |
| 2638 | } finally { |
| 2639 | Binder.restoreCallingIdentity(identity); |
| 2640 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2641 | } |
| 2642 | |
| 2643 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2644 | final long identity = Binder.clearCallingIdentity(); |
| 2645 | try { |
| 2646 | final Phone phone = getPhone(subId); |
| 2647 | if (phone != null) { |
| 2648 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2649 | } else { |
| 2650 | return false; |
| 2651 | } |
| 2652 | } finally { |
| 2653 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2654 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2655 | } |
| 2656 | |
| 2657 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2658 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2659 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2660 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2661 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2662 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2663 | |
| 2664 | final long identity = Binder.clearCallingIdentity(); |
| 2665 | try { |
| 2666 | final Phone phone = getPhone(subId); |
| 2667 | if (phone != null) { |
| 2668 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2669 | } |
| 2670 | } finally { |
| 2671 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2672 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2673 | } |
| 2674 | |
| 2675 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2676 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2677 | } |
| 2678 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2679 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2680 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2681 | |
| 2682 | final long identity = Binder.clearCallingIdentity(); |
| 2683 | try { |
| 2684 | final Phone phone = getPhone(subId); |
| 2685 | if (phone == null) { |
| 2686 | return false; |
| 2687 | } |
| 2688 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2689 | toggleRadioOnOffForSubscriber(subId); |
| 2690 | } |
| 2691 | return true; |
| 2692 | } finally { |
| 2693 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2694 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2695 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2696 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2697 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2698 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2699 | /* |
| 2700 | * If any of the Radios are available, it will need to be |
| 2701 | * shutdown. So return true if any Radio is available. |
| 2702 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2703 | final long identity = Binder.clearCallingIdentity(); |
| 2704 | try { |
| 2705 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2706 | Phone phone = PhoneFactory.getPhone(i); |
| 2707 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2708 | } |
| 2709 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2710 | return false; |
| 2711 | } finally { |
| 2712 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2713 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2714 | } |
| 2715 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2716 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2717 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2718 | enforceModifyPermission(); |
| 2719 | |
| 2720 | final long identity = Binder.clearCallingIdentity(); |
| 2721 | try { |
| 2722 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2723 | logv("Shutting down Phone " + i); |
| 2724 | shutdownRadioUsingPhoneId(i); |
| 2725 | } |
| 2726 | } finally { |
| 2727 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2728 | } |
| 2729 | } |
| 2730 | |
| 2731 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2732 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2733 | if (phone != null && phone.isRadioAvailable()) { |
| 2734 | phone.shutdownRadio(); |
| 2735 | } |
| 2736 | } |
| 2737 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2738 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2739 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2740 | |
| 2741 | final long identity = Binder.clearCallingIdentity(); |
| 2742 | try { |
| 2743 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2744 | if (defaultPhone != null) { |
| 2745 | defaultPhone.setRadioPower(turnOn); |
| 2746 | return true; |
| 2747 | } else { |
| 2748 | loge("There's no default phone."); |
| 2749 | return false; |
| 2750 | } |
| 2751 | } finally { |
| 2752 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2753 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2754 | } |
| 2755 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2756 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2757 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2758 | |
| 2759 | final long identity = Binder.clearCallingIdentity(); |
| 2760 | try { |
| 2761 | final Phone phone = getPhone(subId); |
| 2762 | if (phone != null) { |
| 2763 | phone.setRadioPower(turnOn); |
| 2764 | return true; |
| 2765 | } else { |
| 2766 | return false; |
| 2767 | } |
| 2768 | } finally { |
| 2769 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2770 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2771 | } |
| 2772 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2773 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2774 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2775 | public boolean enableDataConnectivity() { |
| 2776 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2777 | |
| 2778 | final long identity = Binder.clearCallingIdentity(); |
| 2779 | try { |
| 2780 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2781 | final Phone phone = getPhone(subId); |
| 2782 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2783 | phone.getDataEnabledSettings().setDataEnabled( |
| 2784 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2785 | return true; |
| 2786 | } else { |
| 2787 | return false; |
| 2788 | } |
| 2789 | } finally { |
| 2790 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2791 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2792 | } |
| 2793 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2794 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2795 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2796 | public boolean disableDataConnectivity() { |
| 2797 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2798 | |
| 2799 | final long identity = Binder.clearCallingIdentity(); |
| 2800 | try { |
| 2801 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2802 | final Phone phone = getPhone(subId); |
| 2803 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2804 | phone.getDataEnabledSettings().setDataEnabled( |
| 2805 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2806 | return true; |
| 2807 | } else { |
| 2808 | return false; |
| 2809 | } |
| 2810 | } finally { |
| 2811 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2812 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2813 | } |
| 2814 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2815 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2816 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2817 | final long identity = Binder.clearCallingIdentity(); |
| 2818 | try { |
| 2819 | final Phone phone = getPhone(subId); |
| 2820 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2821 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2822 | } else { |
| 2823 | return false; |
| 2824 | } |
| 2825 | } finally { |
| 2826 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2827 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2828 | } |
| 2829 | |
| 2830 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2831 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2832 | } |
| 2833 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2834 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2835 | enforceCallPermission(); |
| 2836 | |
| 2837 | final long identity = Binder.clearCallingIdentity(); |
| 2838 | try { |
| 2839 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2840 | return; |
| 2841 | } |
| 2842 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2843 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2844 | } finally { |
| 2845 | Binder.restoreCallingIdentity(identity); |
| 2846 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2847 | }; |
| 2848 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2849 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2850 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2851 | |
| 2852 | final long identity = Binder.clearCallingIdentity(); |
| 2853 | try { |
| 2854 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2855 | return false; |
| 2856 | } |
| 2857 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2858 | } finally { |
| 2859 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2860 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2861 | } |
| 2862 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2863 | /** |
| 2864 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 2865 | * tag on getCallState Binder call. |
| 2866 | */ |
| 2867 | @Deprecated |
| 2868 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2869 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2870 | if (CompatChanges.isChangeEnabled( |
| 2871 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2872 | Binder.getCallingUid())) { |
| 2873 | // Do not allow this API to be called on API version 31+, it should only be |
| 2874 | // called on old apps using this Binder call directly. |
| 2875 | throw new SecurityException("This method can only be used for applications " |
| 2876 | + "targeting API version 30 or less."); |
| 2877 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2878 | final long identity = Binder.clearCallingIdentity(); |
| 2879 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2880 | Phone phone = getPhone(getDefaultSubscription()); |
| 2881 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2882 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2883 | } finally { |
| 2884 | Binder.restoreCallingIdentity(identity); |
| 2885 | } |
| 2886 | } |
| 2887 | |
| 2888 | @Override |
| 2889 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 2890 | if (CompatChanges.isChangeEnabled( |
| 2891 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2892 | Binder.getCallingUid())) { |
| 2893 | // Check READ_PHONE_STATE for API version 31+ |
| 2894 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2895 | featureId, "getCallStateForSubscription")) { |
| 2896 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 2897 | + "targeting API level 31+."); |
| 2898 | } |
| 2899 | } |
| 2900 | final long identity = Binder.clearCallingIdentity(); |
| 2901 | try { |
| 2902 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2903 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2904 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2905 | } finally { |
| 2906 | Binder.restoreCallingIdentity(identity); |
| 2907 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2908 | } |
| 2909 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2910 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2911 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2912 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2913 | } |
| 2914 | |
| 2915 | @Override |
| 2916 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2917 | final long identity = Binder.clearCallingIdentity(); |
| 2918 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2919 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2920 | if (phone != null) { |
| 2921 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2922 | } else { |
| 2923 | return PhoneConstantConversions.convertDataState( |
| 2924 | PhoneConstants.DataState.DISCONNECTED); |
| 2925 | } |
| 2926 | } finally { |
| 2927 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2928 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2929 | } |
| 2930 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2931 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2932 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2933 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2934 | } |
| 2935 | |
| 2936 | @Override |
| 2937 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2938 | final long identity = Binder.clearCallingIdentity(); |
| 2939 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2940 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2941 | if (phone != null) { |
| 2942 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2943 | } else { |
| 2944 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2945 | } |
| 2946 | } finally { |
| 2947 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2948 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2949 | } |
| 2950 | |
| 2951 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2952 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2953 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2954 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2955 | |
| 2956 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2957 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2958 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2959 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2960 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2961 | .setCallingPid(Binder.getCallingPid()) |
| 2962 | .setCallingUid(Binder.getCallingUid()) |
| 2963 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2964 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2965 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2966 | .build()); |
| 2967 | switch (locationResult) { |
| 2968 | case DENIED_HARD: |
| 2969 | throw new SecurityException("Not allowed to access cell location"); |
| 2970 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2971 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2972 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2973 | } |
| 2974 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2975 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2976 | final long identity = Binder.clearCallingIdentity(); |
| 2977 | try { |
| 2978 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2979 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2980 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2981 | } finally { |
| 2982 | Binder.restoreCallingIdentity(identity); |
| 2983 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2984 | } |
| 2985 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2986 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2987 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2988 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2989 | // registered cell info, so return a NULL country instead. |
| 2990 | final long identity = Binder.clearCallingIdentity(); |
| 2991 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2992 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2993 | // Get default phone in this case. |
| 2994 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2995 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2996 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2997 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2998 | if (phone == null) return ""; |
| 2999 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3000 | if (sst == null) return ""; |
| 3001 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3002 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3003 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3004 | } finally { |
| 3005 | Binder.restoreCallingIdentity(identity); |
| 3006 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3007 | } |
| 3008 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3009 | /** |
| 3010 | * This method was removed due to potential issues caused by performing partial |
| 3011 | * updates of service state, and lack of a credible use case. |
| 3012 | * |
| 3013 | * This has the ability to break the telephony implementation by disabling notification of |
| 3014 | * changes in device connectivity. DO NOT USE THIS! |
| 3015 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3016 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3017 | public void enableLocationUpdates() { |
| 3018 | mApp.enforceCallingOrSelfPermission( |
| 3019 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3020 | } |
| 3021 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3022 | /** |
| 3023 | * This method was removed due to potential issues caused by performing partial |
| 3024 | * updates of service state, and lack of a credible use case. |
| 3025 | * |
| 3026 | * This has the ability to break the telephony implementation by disabling notification of |
| 3027 | * changes in device connectivity. DO NOT USE THIS! |
| 3028 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3029 | @Override |
| 3030 | public void disableLocationUpdates() { |
| 3031 | mApp.enforceCallingOrSelfPermission( |
| 3032 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3033 | } |
| 3034 | |
| 3035 | @Override |
| 3036 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3037 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3038 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3039 | try { |
| 3040 | mApp.getSystemService(AppOpsManager.class) |
| 3041 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3042 | } catch (SecurityException e) { |
| 3043 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3044 | throw e; |
| 3045 | } |
| 3046 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3047 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3048 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3049 | throw new SecurityException( |
| 3050 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3051 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3052 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3053 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3054 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3055 | return null; |
| 3056 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3057 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3058 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3059 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3060 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3061 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3062 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3063 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3064 | for (CellInfo ci : info) { |
| 3065 | if (ci instanceof CellInfoGsm) { |
| 3066 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3067 | } else if (ci instanceof CellInfoWcdma) { |
| 3068 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3069 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3070 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3071 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3072 | } |
| 3073 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3074 | private List<CellInfo> getCachedCellInfo() { |
| 3075 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3076 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3077 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3078 | if (info != null) cellInfos.addAll(info); |
| 3079 | } |
| 3080 | return cellInfos; |
| 3081 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3082 | |
| 3083 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3084 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3085 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3086 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3087 | |
| 3088 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3089 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3090 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3091 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3092 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3093 | .setCallingPid(Binder.getCallingPid()) |
| 3094 | .setCallingUid(Binder.getCallingUid()) |
| 3095 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3096 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3097 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3098 | .build()); |
| 3099 | switch (locationResult) { |
| 3100 | case DENIED_HARD: |
| 3101 | throw new SecurityException("Not allowed to access cell info"); |
| 3102 | case DENIED_SOFT: |
| 3103 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3104 | } |
| 3105 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3106 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3107 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3108 | return getCachedCellInfo(); |
| 3109 | } |
| 3110 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3111 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3112 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3113 | final long identity = Binder.clearCallingIdentity(); |
| 3114 | try { |
| 3115 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3116 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3117 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3118 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3119 | if (info != null) cellInfos.addAll(info); |
| 3120 | } |
| 3121 | return cellInfos; |
| 3122 | } finally { |
| 3123 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3124 | } |
| 3125 | } |
| 3126 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3127 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3128 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3129 | String callingFeatureId) { |
| 3130 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3131 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3132 | } |
| 3133 | |
| 3134 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3135 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3136 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3137 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3138 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3139 | } |
| 3140 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3141 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3142 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3143 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3144 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3145 | |
| 3146 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3147 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3148 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3149 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3150 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3151 | .setCallingPid(Binder.getCallingPid()) |
| 3152 | .setCallingUid(Binder.getCallingUid()) |
| 3153 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3154 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3155 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3156 | .build()); |
| 3157 | switch (locationResult) { |
| 3158 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3159 | if (TelephonyPermissions |
| 3160 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3161 | // Safetynet logging for b/154934934 |
| 3162 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3163 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3164 | throw new SecurityException("Not allowed to access cell info"); |
| 3165 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3166 | if (TelephonyPermissions |
| 3167 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3168 | // Safetynet logging for b/154934934 |
| 3169 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3170 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3171 | try { |
| 3172 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3173 | } catch (RemoteException re) { |
| 3174 | // Drop without consequences |
| 3175 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3176 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3177 | } |
| 3178 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3179 | |
| 3180 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3181 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3182 | |
| 3183 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3184 | } |
| 3185 | |
| 3186 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3187 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3188 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3189 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3190 | |
| 3191 | final long identity = Binder.clearCallingIdentity(); |
| 3192 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3193 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3194 | } finally { |
| 3195 | Binder.restoreCallingIdentity(identity); |
| 3196 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3197 | } |
| 3198 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3199 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3200 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3201 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3202 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3203 | return null; |
| 3204 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3205 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3206 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3207 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3208 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3209 | return null; |
| 3210 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3211 | |
| 3212 | final long identity = Binder.clearCallingIdentity(); |
| 3213 | try { |
| 3214 | return phone.getImei(); |
| 3215 | } finally { |
| 3216 | Binder.restoreCallingIdentity(identity); |
| 3217 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3218 | } |
| 3219 | |
| 3220 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3221 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3222 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3223 | String tac = null; |
| 3224 | if (phone != null) { |
| 3225 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3226 | try { |
| 3227 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3228 | } catch (IndexOutOfBoundsException e) { |
| 3229 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3230 | return null; |
| 3231 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3232 | } |
| 3233 | return tac; |
| 3234 | } |
| 3235 | |
| 3236 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3237 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3238 | try { |
| 3239 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3240 | } catch (SecurityException se) { |
| 3241 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3242 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3243 | + Binder.getCallingUid()); |
| 3244 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3245 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3246 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3247 | return null; |
| 3248 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3249 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3250 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3251 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3252 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3253 | return null; |
| 3254 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3255 | |
| 3256 | final long identity = Binder.clearCallingIdentity(); |
| 3257 | try { |
| 3258 | return phone.getMeid(); |
| 3259 | } finally { |
| 3260 | Binder.restoreCallingIdentity(identity); |
| 3261 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3262 | } |
| 3263 | |
| 3264 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3265 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3266 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3267 | String manufacturerCode = null; |
| 3268 | if (phone != null) { |
| 3269 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3270 | try { |
| 3271 | manufacturerCode = |
| 3272 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3273 | } catch (IndexOutOfBoundsException e) { |
| 3274 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3275 | return null; |
| 3276 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3277 | } |
| 3278 | return manufacturerCode; |
| 3279 | } |
| 3280 | |
| 3281 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3282 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3283 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3284 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3285 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3286 | return null; |
| 3287 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3288 | int subId = phone.getSubId(); |
| 3289 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3290 | mApp, subId, callingPackage, callingFeatureId, |
| 3291 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3292 | return null; |
| 3293 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3294 | |
| 3295 | final long identity = Binder.clearCallingIdentity(); |
| 3296 | try { |
| 3297 | return phone.getDeviceSvn(); |
| 3298 | } finally { |
| 3299 | Binder.restoreCallingIdentity(identity); |
| 3300 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3301 | } |
| 3302 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3303 | @Override |
| 3304 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3305 | final long identity = Binder.clearCallingIdentity(); |
| 3306 | try { |
| 3307 | final Phone phone = getPhone(subId); |
| 3308 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3309 | } finally { |
| 3310 | Binder.restoreCallingIdentity(identity); |
| 3311 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3312 | } |
| 3313 | |
| 3314 | @Override |
| 3315 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3316 | final long identity = Binder.clearCallingIdentity(); |
| 3317 | try { |
| 3318 | final Phone phone = getPhone(subId); |
| 3319 | return phone == null ? null : phone.getCarrierName(); |
| 3320 | } finally { |
| 3321 | Binder.restoreCallingIdentity(identity); |
| 3322 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3323 | } |
| 3324 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3325 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3326 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3327 | final long identity = Binder.clearCallingIdentity(); |
| 3328 | try { |
| 3329 | final Phone phone = getPhone(subId); |
| 3330 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3331 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3332 | } finally { |
| 3333 | Binder.restoreCallingIdentity(identity); |
| 3334 | } |
| 3335 | } |
| 3336 | |
| 3337 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3338 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3339 | final long identity = Binder.clearCallingIdentity(); |
| 3340 | try { |
| 3341 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3342 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3343 | } finally { |
| 3344 | Binder.restoreCallingIdentity(identity); |
| 3345 | } |
| 3346 | } |
| 3347 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3348 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3349 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3350 | if (!isSubscriptionMccMnc) { |
| 3351 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3352 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3353 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3354 | if (phone == null) { |
| 3355 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3356 | } |
| 3357 | final long identity = Binder.clearCallingIdentity(); |
| 3358 | try { |
| 3359 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3360 | } finally { |
| 3361 | Binder.restoreCallingIdentity(identity); |
| 3362 | } |
| 3363 | } |
| 3364 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3365 | // |
| 3366 | // Internal helper methods. |
| 3367 | // |
| 3368 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3369 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3370 | * Make sure the caller is the calling package itself |
| 3371 | * |
| 3372 | * @throws SecurityException if the caller is not the calling package |
| 3373 | */ |
| 3374 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3375 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3376 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3377 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3378 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3379 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3380 | } catch (PackageManager.NameNotFoundException e) { |
| 3381 | // packageUid is -1 |
| 3382 | } |
| 3383 | if (packageUid != callingUid) { |
| 3384 | throw new SecurityException(message + ": Package " + callingPackage |
| 3385 | + " does not belong to " + callingUid); |
| 3386 | } |
| 3387 | } |
| 3388 | |
| 3389 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3390 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3391 | * |
| 3392 | * @throws SecurityException if the caller does not have the required permission |
| 3393 | */ |
| 3394 | private void enforceModifyPermission() { |
| 3395 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3396 | } |
| 3397 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3398 | /** |
| 3399 | * Make sure the caller is system. |
| 3400 | * |
| 3401 | * @throws SecurityException if the caller is not system. |
| 3402 | */ |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 3403 | private static void enforceSystemCaller() { |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3404 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3405 | throw new SecurityException("Caller must be system"); |
| 3406 | } |
| 3407 | } |
| 3408 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3409 | private void enforceActiveEmergencySessionPermission() { |
| 3410 | mApp.enforceCallingOrSelfPermission( |
| 3411 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3412 | } |
| 3413 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3414 | /** |
| 3415 | * Make sure the caller has the CALL_PHONE permission. |
| 3416 | * |
| 3417 | * @throws SecurityException if the caller does not have the required permission |
| 3418 | */ |
| 3419 | private void enforceCallPermission() { |
| 3420 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3421 | } |
| 3422 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3423 | private void enforceSettingsPermission() { |
| 3424 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3425 | } |
| 3426 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3427 | private void enforceRebootPermission() { |
| 3428 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3429 | } |
| 3430 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3431 | private String createTelUrl(String number) { |
| 3432 | if (TextUtils.isEmpty(number)) { |
| 3433 | return null; |
| 3434 | } |
| 3435 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3436 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3437 | } |
| 3438 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3439 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3440 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3441 | } |
| 3442 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3443 | private static void logv(String msg) { |
| 3444 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3445 | } |
| 3446 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3447 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3448 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3449 | } |
| 3450 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3451 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3452 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3453 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3454 | } |
| 3455 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3456 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3457 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3458 | final long identity = Binder.clearCallingIdentity(); |
| 3459 | try { |
| 3460 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3461 | if (phone == null) { |
| 3462 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3463 | } else { |
| 3464 | return phone.getPhoneType(); |
| 3465 | } |
| 3466 | } finally { |
| 3467 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3468 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3469 | } |
| 3470 | |
| 3471 | /** |
| 3472 | * Returns the CDMA ERI icon index to display |
| 3473 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3474 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3475 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3476 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3477 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3478 | } |
| 3479 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3480 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3481 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3482 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3483 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3484 | mApp, subId, callingPackage, callingFeatureId, |
| 3485 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3486 | return -1; |
| 3487 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3488 | |
| 3489 | final long identity = Binder.clearCallingIdentity(); |
| 3490 | try { |
| 3491 | final Phone phone = getPhone(subId); |
| 3492 | if (phone != null) { |
| 3493 | return phone.getCdmaEriIconIndex(); |
| 3494 | } else { |
| 3495 | return -1; |
| 3496 | } |
| 3497 | } finally { |
| 3498 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3499 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3500 | } |
| 3501 | |
| 3502 | /** |
| 3503 | * Returns the CDMA ERI icon mode, |
| 3504 | * 0 - ON |
| 3505 | * 1 - FLASHING |
| 3506 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3507 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3508 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3509 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3510 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3511 | } |
| 3512 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3513 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3514 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3515 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3516 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3517 | mApp, subId, callingPackage, callingFeatureId, |
| 3518 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3519 | return -1; |
| 3520 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3521 | |
| 3522 | final long identity = Binder.clearCallingIdentity(); |
| 3523 | try { |
| 3524 | final Phone phone = getPhone(subId); |
| 3525 | if (phone != null) { |
| 3526 | return phone.getCdmaEriIconMode(); |
| 3527 | } else { |
| 3528 | return -1; |
| 3529 | } |
| 3530 | } finally { |
| 3531 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3532 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3533 | } |
| 3534 | |
| 3535 | /** |
| 3536 | * Returns the CDMA ERI text, |
| 3537 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3538 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3539 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3540 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3541 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3542 | } |
| 3543 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3544 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3545 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3546 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3547 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3548 | mApp, subId, callingPackage, callingFeatureId, |
| 3549 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3550 | return null; |
| 3551 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3552 | |
| 3553 | final long identity = Binder.clearCallingIdentity(); |
| 3554 | try { |
| 3555 | final Phone phone = getPhone(subId); |
| 3556 | if (phone != null) { |
| 3557 | return phone.getCdmaEriText(); |
| 3558 | } else { |
| 3559 | return null; |
| 3560 | } |
| 3561 | } finally { |
| 3562 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3563 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3564 | } |
| 3565 | |
| 3566 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3567 | * Returns the CDMA MDN. |
| 3568 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3569 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3570 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3571 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3572 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3573 | |
| 3574 | final long identity = Binder.clearCallingIdentity(); |
| 3575 | try { |
| 3576 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3577 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3578 | return phone.getLine1Number(); |
| 3579 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3580 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3581 | return null; |
| 3582 | } |
| 3583 | } finally { |
| 3584 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3585 | } |
| 3586 | } |
| 3587 | |
| 3588 | /** |
| 3589 | * Returns the CDMA MIN. |
| 3590 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3591 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3592 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3593 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3594 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3595 | |
| 3596 | final long identity = Binder.clearCallingIdentity(); |
| 3597 | try { |
| 3598 | final Phone phone = getPhone(subId); |
| 3599 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3600 | return phone.getCdmaMin(); |
| 3601 | } else { |
| 3602 | return null; |
| 3603 | } |
| 3604 | } finally { |
| 3605 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3606 | } |
| 3607 | } |
| 3608 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3609 | @Override |
| 3610 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3611 | INumberVerificationCallback callback, String callingPackage) { |
| 3612 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3613 | != PERMISSION_GRANTED) { |
| 3614 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3615 | } |
| 3616 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3617 | |
| 3618 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3619 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3620 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3621 | + "calling package: " + callingPackage |
| 3622 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3623 | } |
| 3624 | |
| 3625 | if (range == null) { |
| 3626 | throw new NullPointerException("Range must be non-null"); |
| 3627 | } |
| 3628 | |
| 3629 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3630 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3631 | |
| 3632 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3633 | } |
| 3634 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3635 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3636 | * Returns true if CDMA provisioning needs to run. |
| 3637 | */ |
| 3638 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3639 | final long identity = Binder.clearCallingIdentity(); |
| 3640 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3641 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3642 | } finally { |
| 3643 | Binder.restoreCallingIdentity(identity); |
| 3644 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3645 | } |
| 3646 | |
| 3647 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3648 | * Sets the voice mail number of a given subId. |
| 3649 | */ |
| 3650 | @Override |
| 3651 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3652 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3653 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3654 | |
| 3655 | final long identity = Binder.clearCallingIdentity(); |
| 3656 | try { |
| 3657 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3658 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3659 | return success; |
| 3660 | } finally { |
| 3661 | Binder.restoreCallingIdentity(identity); |
| 3662 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3663 | } |
| 3664 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3665 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3666 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3667 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3668 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3669 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3670 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3671 | throw new SecurityException("caller must be system dialer"); |
| 3672 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3673 | |
| 3674 | final long identity = Binder.clearCallingIdentity(); |
| 3675 | try { |
| 3676 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3677 | if (phoneAccountHandle == null) { |
| 3678 | return null; |
| 3679 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3680 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3681 | } finally { |
| 3682 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3683 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3684 | } |
| 3685 | |
| 3686 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3687 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3688 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3689 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3690 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3691 | mApp, subId, callingPackage, callingFeatureId, |
| 3692 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3693 | return null; |
| 3694 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3695 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3696 | final long identity = Binder.clearCallingIdentity(); |
| 3697 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3698 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3699 | } finally { |
| 3700 | Binder.restoreCallingIdentity(identity); |
| 3701 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3702 | } |
| 3703 | |
| 3704 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3705 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3706 | VisualVoicemailSmsFilterSettings settings) { |
| 3707 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3708 | |
| 3709 | final long identity = Binder.clearCallingIdentity(); |
| 3710 | try { |
| 3711 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3712 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3713 | } finally { |
| 3714 | Binder.restoreCallingIdentity(identity); |
| 3715 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3716 | } |
| 3717 | |
| 3718 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3719 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3720 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3721 | |
| 3722 | final long identity = Binder.clearCallingIdentity(); |
| 3723 | try { |
| 3724 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3725 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3726 | } finally { |
| 3727 | Binder.restoreCallingIdentity(identity); |
| 3728 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3729 | } |
| 3730 | |
| 3731 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3732 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3733 | String callingPackage, int subId) { |
| 3734 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3735 | |
| 3736 | final long identity = Binder.clearCallingIdentity(); |
| 3737 | try { |
| 3738 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3739 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3740 | } finally { |
| 3741 | Binder.restoreCallingIdentity(identity); |
| 3742 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3743 | } |
| 3744 | |
| 3745 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3746 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3747 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3748 | |
| 3749 | final long identity = Binder.clearCallingIdentity(); |
| 3750 | try { |
| 3751 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3752 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3753 | } finally { |
| 3754 | Binder.restoreCallingIdentity(identity); |
| 3755 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3756 | } |
| 3757 | |
| 3758 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3759 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3760 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3761 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3762 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3763 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3764 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3765 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3766 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3767 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3768 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3769 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3770 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3771 | * Sets the voice activation state of a given subId. |
| 3772 | */ |
| 3773 | @Override |
| 3774 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3775 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3776 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3777 | |
| 3778 | final long identity = Binder.clearCallingIdentity(); |
| 3779 | try { |
| 3780 | final Phone phone = getPhone(subId); |
| 3781 | if (phone != null) { |
| 3782 | phone.setVoiceActivationState(activationState); |
| 3783 | } else { |
| 3784 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3785 | } |
| 3786 | } finally { |
| 3787 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3788 | } |
| 3789 | } |
| 3790 | |
| 3791 | /** |
| 3792 | * Sets the data activation state of a given subId. |
| 3793 | */ |
| 3794 | @Override |
| 3795 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3796 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3797 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3798 | |
| 3799 | final long identity = Binder.clearCallingIdentity(); |
| 3800 | try { |
| 3801 | final Phone phone = getPhone(subId); |
| 3802 | if (phone != null) { |
| 3803 | phone.setDataActivationState(activationState); |
| 3804 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3805 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3806 | } |
| 3807 | } finally { |
| 3808 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3809 | } |
| 3810 | } |
| 3811 | |
| 3812 | /** |
| 3813 | * Returns the voice activation state of a given subId. |
| 3814 | */ |
| 3815 | @Override |
| 3816 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3817 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3818 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3819 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3820 | final long identity = Binder.clearCallingIdentity(); |
| 3821 | try { |
| 3822 | if (phone != null) { |
| 3823 | return phone.getVoiceActivationState(); |
| 3824 | } else { |
| 3825 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3826 | } |
| 3827 | } finally { |
| 3828 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3829 | } |
| 3830 | } |
| 3831 | |
| 3832 | /** |
| 3833 | * Returns the data activation state of a given subId. |
| 3834 | */ |
| 3835 | @Override |
| 3836 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3837 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3838 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3839 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3840 | final long identity = Binder.clearCallingIdentity(); |
| 3841 | try { |
| 3842 | if (phone != null) { |
| 3843 | return phone.getDataActivationState(); |
| 3844 | } else { |
| 3845 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3846 | } |
| 3847 | } finally { |
| 3848 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3849 | } |
| 3850 | } |
| 3851 | |
| 3852 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3853 | * Returns the unread count of voicemails for a subId |
| 3854 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3855 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3856 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3857 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3858 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3859 | mApp, subId, callingPackage, callingFeatureId, |
| 3860 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3861 | return 0; |
| 3862 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3863 | final long identity = Binder.clearCallingIdentity(); |
| 3864 | try { |
| 3865 | final Phone phone = getPhone(subId); |
| 3866 | if (phone != null) { |
| 3867 | return phone.getVoiceMessageCount(); |
| 3868 | } else { |
| 3869 | return 0; |
| 3870 | } |
| 3871 | } finally { |
| 3872 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3873 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3874 | } |
| 3875 | |
| 3876 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3877 | * returns true, if the device is in a state where both voice and data |
| 3878 | * are supported simultaneously. This can change based on location or network condition. |
| 3879 | */ |
| 3880 | @Override |
| 3881 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3882 | final long identity = Binder.clearCallingIdentity(); |
| 3883 | try { |
| 3884 | final Phone phone = getPhone(subId); |
| 3885 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3886 | } finally { |
| 3887 | Binder.restoreCallingIdentity(identity); |
| 3888 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3889 | } |
| 3890 | |
| 3891 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3892 | * Send the dialer code if called from the current default dialer or the caller has |
| 3893 | * carrier privilege. |
| 3894 | * @param inputCode The dialer code to send |
| 3895 | */ |
| 3896 | @Override |
| 3897 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3898 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3899 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3900 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3901 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3902 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3903 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3904 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3905 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3906 | |
| 3907 | final long identity = Binder.clearCallingIdentity(); |
| 3908 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3909 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3910 | } finally { |
| 3911 | Binder.restoreCallingIdentity(identity); |
| 3912 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3913 | } |
| 3914 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3915 | @Override |
| 3916 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3917 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3918 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3919 | mApp, subId, "getNetworkSelectionMode"); |
| 3920 | final long identity = Binder.clearCallingIdentity(); |
| 3921 | try { |
| 3922 | if (!isActiveSubscription(subId)) { |
| 3923 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3924 | } |
| 3925 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3926 | } finally { |
| 3927 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3928 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3929 | } |
| 3930 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3931 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3932 | public boolean isInEmergencySmsMode() { |
| 3933 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3934 | final long identity = Binder.clearCallingIdentity(); |
| 3935 | try { |
| 3936 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3937 | if (phone.isInEmergencySmsMode()) { |
| 3938 | return true; |
| 3939 | } |
| 3940 | } |
| 3941 | } finally { |
| 3942 | Binder.restoreCallingIdentity(identity); |
| 3943 | } |
| 3944 | return false; |
| 3945 | } |
| 3946 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3947 | /** |
| 3948 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3949 | * @param subId The subscription to use to check the configuration. |
| 3950 | * @param c The callback that will be used to send the result. |
| 3951 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3952 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3953 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3954 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3955 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3956 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3957 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3958 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3959 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3960 | "IMS not available on device."); |
| 3961 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3962 | final long token = Binder.clearCallingIdentity(); |
| 3963 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 3964 | int slotId = getSlotIndexOrException(subId); |
| 3965 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 3966 | ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3967 | } catch (ImsException e) { |
| 3968 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3969 | } finally { |
| 3970 | Binder.restoreCallingIdentity(token); |
| 3971 | } |
| 3972 | } |
| 3973 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3974 | /** |
| 3975 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3976 | * @param subId The subscription to use to check the configuration. |
| 3977 | * @param c The callback that will be used to send the result. |
| 3978 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3979 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3980 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3981 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3982 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3983 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3984 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3985 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3986 | final long token = Binder.clearCallingIdentity(); |
| 3987 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3988 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3989 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3990 | } catch (ImsException e) { |
| 3991 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3992 | + "is inactive, ignoring unregister."); |
| 3993 | // If the subscription is no longer active, just return, since the callback |
| 3994 | // will already have been removed internally. |
| 3995 | } finally { |
| 3996 | Binder.restoreCallingIdentity(token); |
| 3997 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3998 | } |
| 3999 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4000 | /** |
| 4001 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4002 | */ |
| 4003 | @Override |
| 4004 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4005 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4006 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4007 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4008 | "IMS not available on device."); |
| 4009 | } |
| 4010 | final long token = Binder.clearCallingIdentity(); |
| 4011 | try { |
| 4012 | Phone phone = getPhone(subId); |
| 4013 | if (phone == null) { |
| 4014 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4015 | + subId + "'"); |
| 4016 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4017 | } |
| 4018 | phone.getImsRegistrationState(regState -> { |
| 4019 | try { |
| 4020 | consumer.accept((regState == null) |
| 4021 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4022 | } catch (RemoteException e) { |
| 4023 | // Ignore if the remote process is no longer available to call back. |
| 4024 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4025 | } |
| 4026 | }); |
| 4027 | } finally { |
| 4028 | Binder.restoreCallingIdentity(token); |
| 4029 | } |
| 4030 | } |
| 4031 | |
| 4032 | /** |
| 4033 | * Get the transport type for the IMS service registration state. |
| 4034 | */ |
| 4035 | @Override |
| 4036 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4037 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4038 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4039 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4040 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4041 | "IMS not available on device."); |
| 4042 | } |
| 4043 | final long token = Binder.clearCallingIdentity(); |
| 4044 | try { |
| 4045 | Phone phone = getPhone(subId); |
| 4046 | if (phone == null) { |
| 4047 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4048 | + subId + "'"); |
| 4049 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4050 | } |
| 4051 | phone.getImsRegistrationTech(regTech -> { |
| 4052 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4053 | int regTechConverted = (regTech == null) |
| 4054 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4055 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4056 | regTechConverted); |
| 4057 | try { |
| 4058 | consumer.accept(regTechConverted); |
| 4059 | } catch (RemoteException e) { |
| 4060 | // Ignore if the remote process is no longer available to call back. |
| 4061 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4062 | } |
| 4063 | }); |
| 4064 | } finally { |
| 4065 | Binder.restoreCallingIdentity(token); |
| 4066 | } |
| 4067 | } |
| 4068 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4069 | /** |
| 4070 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4071 | * @param subId The subscription to use to check the configuration. |
| 4072 | * @param c The callback that will be used to send the result. |
| 4073 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4074 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4075 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4076 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4077 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4078 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4079 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4080 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4081 | "IMS not available on device."); |
| 4082 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4083 | final long token = Binder.clearCallingIdentity(); |
| 4084 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4085 | int slotId = getSlotIndexOrException(subId); |
| 4086 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4087 | ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4088 | } catch (ImsException e) { |
| 4089 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4090 | } finally { |
| 4091 | Binder.restoreCallingIdentity(token); |
| 4092 | } |
| 4093 | } |
| 4094 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4095 | /** |
| 4096 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4097 | * @param subId The subscription to use to check the configuration. |
| 4098 | * @param c The callback that will be used to send the result. |
| 4099 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4100 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4101 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4102 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4103 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4104 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4105 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4106 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4107 | |
| 4108 | final long token = Binder.clearCallingIdentity(); |
| 4109 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4110 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4111 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4112 | } catch (ImsException e) { |
| 4113 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4114 | + "is inactive, ignoring unregister."); |
| 4115 | // If the subscription is no longer active, just return, since the callback |
| 4116 | // will already have been removed internally. |
| 4117 | } finally { |
| 4118 | Binder.restoreCallingIdentity(token); |
| 4119 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4120 | } |
| 4121 | |
| 4122 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4123 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4124 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4125 | final long token = Binder.clearCallingIdentity(); |
| 4126 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4127 | int slotId = getSlotIndexOrException(subId); |
| 4128 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4129 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4130 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4131 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4132 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4133 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4134 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4135 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4136 | } finally { |
| 4137 | Binder.restoreCallingIdentity(token); |
| 4138 | } |
| 4139 | } |
| 4140 | |
| 4141 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4142 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4143 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4144 | final long token = Binder.clearCallingIdentity(); |
| 4145 | try { |
| 4146 | Phone phone = getPhone(subId); |
| 4147 | if (phone == null) return false; |
| 4148 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4149 | } catch (com.android.ims.ImsException e) { |
| 4150 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4151 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4152 | } finally { |
| 4153 | Binder.restoreCallingIdentity(token); |
| 4154 | } |
| 4155 | } |
| 4156 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4157 | /** |
| 4158 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4159 | * subscription. |
| 4160 | * @param subId The subscription to use to check the configuration. |
| 4161 | * @param callback The callback that will be used to send the result. |
| 4162 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4163 | * @param transportType The transport type of the MmTelFeature capability. |
| 4164 | */ |
| 4165 | @Override |
| 4166 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4167 | int transportType) { |
| 4168 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 4169 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4170 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4171 | "IMS not available on device."); |
| 4172 | } |
| 4173 | final long token = Binder.clearCallingIdentity(); |
| 4174 | try { |
| 4175 | int slotId = getSlotIndex(subId); |
| 4176 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4177 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4178 | + subId + "'"); |
| 4179 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4180 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4181 | verifyImsMmTelConfiguredOrThrow(slotId); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4182 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4183 | transportType, aBoolean -> { |
| 4184 | try { |
| 4185 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4186 | } catch (RemoteException e) { |
| 4187 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4188 | + "running. Ignore"); |
| 4189 | } |
| 4190 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4191 | } catch (ImsException e) { |
| 4192 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4193 | } finally { |
| 4194 | Binder.restoreCallingIdentity(token); |
| 4195 | } |
| 4196 | } |
| 4197 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4198 | /** |
| 4199 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4200 | * @param subId The subscription to use to check the configuration. |
| 4201 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4202 | @Override |
| 4203 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4204 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4205 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4206 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4207 | final long token = Binder.clearCallingIdentity(); |
| 4208 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4209 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4210 | // 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] | 4211 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4212 | } catch (ImsException e) { |
| 4213 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4214 | } finally { |
| 4215 | Binder.restoreCallingIdentity(token); |
| 4216 | } |
| 4217 | } |
| 4218 | |
| 4219 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4220 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4221 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4222 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4223 | final long identity = Binder.clearCallingIdentity(); |
| 4224 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4225 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4226 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4227 | // 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] | 4228 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4229 | } catch (ImsException e) { |
| 4230 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4231 | } finally { |
| 4232 | Binder.restoreCallingIdentity(identity); |
| 4233 | } |
| 4234 | } |
| 4235 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4236 | /** |
| 4237 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4238 | * @param subId The subscription to use to check the configuration. |
| 4239 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4240 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4241 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4242 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4243 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4244 | final long identity = Binder.clearCallingIdentity(); |
| 4245 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4246 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4247 | // 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] | 4248 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4249 | } catch (ImsException e) { |
| 4250 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4251 | } finally { |
| 4252 | Binder.restoreCallingIdentity(identity); |
| 4253 | } |
| 4254 | } |
| 4255 | |
| 4256 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4257 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4258 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4259 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4260 | final long identity = Binder.clearCallingIdentity(); |
| 4261 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4262 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4263 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4264 | // 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] | 4265 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4266 | } catch (ImsException e) { |
| 4267 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4268 | } finally { |
| 4269 | Binder.restoreCallingIdentity(identity); |
| 4270 | } |
| 4271 | } |
| 4272 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4273 | /** |
| 4274 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4275 | * @param subId The subscription to use to check the configuration. |
| 4276 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4277 | @Override |
| 4278 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4279 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4280 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4281 | final long identity = Binder.clearCallingIdentity(); |
| 4282 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4283 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4284 | // 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] | 4285 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4286 | } catch (ImsException e) { |
| 4287 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4288 | } finally { |
| 4289 | Binder.restoreCallingIdentity(identity); |
| 4290 | } |
| 4291 | } |
| 4292 | |
| 4293 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4294 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4295 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4296 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4297 | final long identity = Binder.clearCallingIdentity(); |
| 4298 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4299 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4300 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4301 | // 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] | 4302 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4303 | } catch (ImsException e) { |
| 4304 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4305 | } finally { |
| 4306 | Binder.restoreCallingIdentity(identity); |
| 4307 | } |
| 4308 | } |
| 4309 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4310 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4311 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4312 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4313 | * @param subId The subscription to use to check the configuration. |
| 4314 | */ |
| 4315 | @Override |
| 4316 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4317 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4318 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4319 | final long identity = Binder.clearCallingIdentity(); |
| 4320 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4321 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4322 | // 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] | 4323 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4324 | } catch (ImsException e) { |
| 4325 | throw new ServiceSpecificException(e.getCode()); |
| 4326 | } finally { |
| 4327 | Binder.restoreCallingIdentity(identity); |
| 4328 | } |
| 4329 | } |
| 4330 | |
| 4331 | /** |
| 4332 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4333 | * Requires MODIFY_PHONE_STATE permission. |
| 4334 | * @param subId The subscription to use to check the configuration. |
| 4335 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4336 | * false otherwise |
| 4337 | */ |
| 4338 | @Override |
| 4339 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4340 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4341 | "setCrossSimCallingEnabled"); |
| 4342 | final long identity = Binder.clearCallingIdentity(); |
| 4343 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4344 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4345 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4346 | // 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] | 4347 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4348 | } catch (ImsException e) { |
| 4349 | throw new ServiceSpecificException(e.getCode()); |
| 4350 | } finally { |
| 4351 | Binder.restoreCallingIdentity(identity); |
| 4352 | } |
| 4353 | } |
| 4354 | |
| 4355 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4356 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4357 | * @param subId The subscription to use to check the configuration. |
| 4358 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4359 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4360 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4361 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4362 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4363 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4364 | final long identity = Binder.clearCallingIdentity(); |
| 4365 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4366 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4367 | // 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] | 4368 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4369 | } catch (ImsException e) { |
| 4370 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4371 | } finally { |
| 4372 | Binder.restoreCallingIdentity(identity); |
| 4373 | } |
| 4374 | } |
| 4375 | |
| 4376 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4377 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4378 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4379 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4380 | final long identity = Binder.clearCallingIdentity(); |
| 4381 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4382 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4383 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4384 | // 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] | 4385 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4386 | } catch (ImsException e) { |
| 4387 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4388 | } finally { |
| 4389 | Binder.restoreCallingIdentity(identity); |
| 4390 | } |
| 4391 | } |
| 4392 | |
| 4393 | @Override |
| 4394 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4395 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4396 | "setVoWiFiNonPersistent"); |
| 4397 | final long identity = Binder.clearCallingIdentity(); |
| 4398 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4399 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4400 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4401 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4402 | } catch (ImsException e) { |
| 4403 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4404 | } finally { |
| 4405 | Binder.restoreCallingIdentity(identity); |
| 4406 | } |
| 4407 | } |
| 4408 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4409 | /** |
| 4410 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4411 | * @param subId The subscription to use to check the configuration. |
| 4412 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4413 | @Override |
| 4414 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4415 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4416 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4417 | final long identity = Binder.clearCallingIdentity(); |
| 4418 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4419 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4420 | // 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] | 4421 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4422 | } catch (ImsException e) { |
| 4423 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4424 | } finally { |
| 4425 | Binder.restoreCallingIdentity(identity); |
| 4426 | } |
| 4427 | } |
| 4428 | |
| 4429 | @Override |
| 4430 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4431 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4432 | "setVoWiFiModeSetting"); |
| 4433 | final long identity = Binder.clearCallingIdentity(); |
| 4434 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4435 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4436 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4437 | // 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] | 4438 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4439 | } catch (ImsException e) { |
| 4440 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4441 | } finally { |
| 4442 | Binder.restoreCallingIdentity(identity); |
| 4443 | } |
| 4444 | } |
| 4445 | |
| 4446 | @Override |
| 4447 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4448 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4449 | final long identity = Binder.clearCallingIdentity(); |
| 4450 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4451 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4452 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4453 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4454 | } catch (ImsException e) { |
| 4455 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4456 | } finally { |
| 4457 | Binder.restoreCallingIdentity(identity); |
| 4458 | } |
| 4459 | } |
| 4460 | |
| 4461 | @Override |
| 4462 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4463 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4464 | "setVoWiFiRoamingModeSetting"); |
| 4465 | final long identity = Binder.clearCallingIdentity(); |
| 4466 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4467 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4468 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4469 | // 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] | 4470 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4471 | } catch (ImsException e) { |
| 4472 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4473 | } finally { |
| 4474 | Binder.restoreCallingIdentity(identity); |
| 4475 | } |
| 4476 | } |
| 4477 | |
| 4478 | @Override |
| 4479 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4480 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4481 | "setRttCapabilityEnabled"); |
| 4482 | final long identity = Binder.clearCallingIdentity(); |
| 4483 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4484 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4485 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4486 | // 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] | 4487 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4488 | } catch (ImsException e) { |
| 4489 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4490 | } finally { |
| 4491 | Binder.restoreCallingIdentity(identity); |
| 4492 | } |
| 4493 | } |
| 4494 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4495 | /** |
| 4496 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4497 | * @param subId The subscription to use to check the configuration. |
| 4498 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4499 | @Override |
| 4500 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4501 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4502 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4503 | final long identity = Binder.clearCallingIdentity(); |
| 4504 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4505 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4506 | // 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] | 4507 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4508 | } catch (ImsException e) { |
| 4509 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4510 | } finally { |
| 4511 | Binder.restoreCallingIdentity(identity); |
| 4512 | } |
| 4513 | } |
| 4514 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4515 | @Override |
| 4516 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4517 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4518 | final long identity = Binder.clearCallingIdentity(); |
| 4519 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4520 | if (!isImsAvailableOnDevice()) { |
| 4521 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4522 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4523 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4524 | int slotId = getSlotIndexOrException(subId); |
| 4525 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4526 | ImsManager.getInstance(mApp, slotId) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4527 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4528 | } catch (ImsException e) { |
| 4529 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4530 | } finally { |
| 4531 | Binder.restoreCallingIdentity(identity); |
| 4532 | } |
| 4533 | } |
| 4534 | |
| 4535 | @Override |
| 4536 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4537 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4538 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4539 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4540 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4541 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4542 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4543 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4544 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4545 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4546 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4547 | + "is inactive, ignoring unregister."); |
| 4548 | // If the subscription is no longer active, just return, since the callback will already |
| 4549 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4550 | } finally { |
| 4551 | Binder.restoreCallingIdentity(identity); |
| 4552 | } |
| 4553 | } |
| 4554 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4555 | |
| 4556 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4557 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4558 | message); |
| 4559 | } |
| 4560 | |
| 4561 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4562 | boolean isMmtelCapability) { |
| 4563 | Phone phone = getPhone(subId); |
| 4564 | if (phone == null) { |
| 4565 | loge("phone instance null for subid " + subId); |
| 4566 | return false; |
| 4567 | } |
| 4568 | if (isMmtelCapability) { |
| 4569 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4570 | return false; |
| 4571 | } |
| 4572 | } else { |
| 4573 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4574 | return false; |
| 4575 | } |
| 4576 | } |
| 4577 | return true; |
| 4578 | } |
| 4579 | |
| 4580 | @Override |
| 4581 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4582 | boolean isProvisioned) { |
| 4583 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4584 | |
| 4585 | final long identity = Binder.clearCallingIdentity(); |
| 4586 | try { |
| 4587 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4588 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4589 | return; |
| 4590 | } |
| 4591 | |
| 4592 | // this capability requires provisioning, route to the correct API. |
| 4593 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4594 | switch (capability) { |
| 4595 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4596 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4597 | ims.setEabProvisioned(isProvisioned); |
| 4598 | break; |
| 4599 | default: { |
| 4600 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4601 | + "rcs capability '" + capability + "', which does not require " |
| 4602 | + "provisioning."); |
| 4603 | } |
| 4604 | } |
| 4605 | } finally { |
| 4606 | Binder.restoreCallingIdentity(identity); |
| 4607 | } |
| 4608 | |
| 4609 | } |
| 4610 | |
| 4611 | |
| 4612 | @Override |
| 4613 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4614 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4615 | final long identity = Binder.clearCallingIdentity(); |
| 4616 | try { |
| 4617 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4618 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4619 | return true; |
| 4620 | } |
| 4621 | |
| 4622 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4623 | switch (capability) { |
| 4624 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4625 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4626 | return ims.isEabProvisionedOnDevice(); |
| 4627 | |
| 4628 | default: { |
| 4629 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4630 | + "capability '" + capability + "', which does not require " |
| 4631 | + "provisioning."); |
| 4632 | } |
| 4633 | } |
| 4634 | |
| 4635 | } finally { |
| 4636 | Binder.restoreCallingIdentity(identity); |
| 4637 | } |
| 4638 | } |
| 4639 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4640 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4641 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4642 | boolean isProvisioned) { |
| 4643 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4644 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE |
| 4645 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4646 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4647 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4648 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4649 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4650 | final long identity = Binder.clearCallingIdentity(); |
| 4651 | try { |
| 4652 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4653 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4654 | return; |
| 4655 | } |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4656 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4657 | || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
| 4658 | loge("setImsProvisioningStatusForCapability: called for technology that does " |
| 4659 | + "not support provisioning - " + tech); |
| 4660 | return; |
| 4661 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4662 | |
| 4663 | // this capability requires provisioning, route to the correct API. |
| 4664 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4665 | switch (capability) { |
| 4666 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4667 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4668 | ims.setVolteProvisioned(isProvisioned); |
| 4669 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4670 | ims.setWfcProvisioned(isProvisioned); |
| 4671 | } |
| 4672 | break; |
| 4673 | } |
| 4674 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4675 | // There is currently no difference in VT provisioning type. |
| 4676 | ims.setVtProvisioned(isProvisioned); |
| 4677 | break; |
| 4678 | } |
| 4679 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4680 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4681 | // change the capability of the feature instead if needed. |
| 4682 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4683 | == isProvisioned) { |
| 4684 | // No change in provisioning. |
| 4685 | return; |
| 4686 | } |
| 4687 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4688 | try { |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4689 | ims.changeMmTelCapability(isProvisioned, capability, tech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4690 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4691 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4692 | + ", Exception" + e.getMessage()); |
| 4693 | } |
| 4694 | break; |
| 4695 | } |
| 4696 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4697 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4698 | + "MmTel capability '" + capability + "', which does not require " |
| 4699 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4700 | } |
| 4701 | } |
| 4702 | |
| 4703 | } finally { |
| 4704 | Binder.restoreCallingIdentity(identity); |
| 4705 | } |
| 4706 | } |
| 4707 | |
| 4708 | @Override |
| 4709 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4710 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4711 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE |
| 4712 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4713 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4714 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4715 | } |
| 4716 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4717 | final long identity = Binder.clearCallingIdentity(); |
| 4718 | try { |
| 4719 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4720 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4721 | return true; |
| 4722 | } |
| 4723 | |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4724 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4725 | || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
| 4726 | loge("getImsProvisioningStatusForCapability: called for technology that does " |
| 4727 | + "not support provisioning - " + tech); |
| 4728 | return true; |
| 4729 | } |
| 4730 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4731 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4732 | switch (capability) { |
| 4733 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4734 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4735 | return ims.isVolteProvisionedOnDevice(); |
| 4736 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4737 | return ims.isWfcProvisionedOnDevice(); |
| 4738 | } |
| 4739 | // This should never happen, since we are checking tech above to make sure it |
| 4740 | // is either LTE or IWLAN. |
| 4741 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4742 | + "capability."); |
| 4743 | } |
| 4744 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4745 | // There is currently no difference in VT provisioning type. |
| 4746 | return ims.isVtProvisionedOnDevice(); |
| 4747 | } |
| 4748 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4749 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4750 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4751 | } |
| 4752 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4753 | throw new IllegalArgumentException( |
| 4754 | "Tried to get provisioning for MmTel capability '" + capability |
| 4755 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4756 | } |
| 4757 | } |
| 4758 | |
| 4759 | } finally { |
| 4760 | Binder.restoreCallingIdentity(identity); |
| 4761 | } |
| 4762 | } |
| 4763 | |
| 4764 | @Override |
| 4765 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4766 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4767 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4768 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4769 | } |
| 4770 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4771 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4772 | return (provisionedBits & capability) > 0; |
| 4773 | } |
| 4774 | |
| 4775 | @Override |
| 4776 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4777 | boolean isProvisioned) { |
| 4778 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4779 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4780 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4781 | } |
| 4782 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4783 | "setProvisioningStatusForCapability"); |
| 4784 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4785 | // If the current provisioning status for capability already matches isProvisioned, |
| 4786 | // do nothing. |
| 4787 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4788 | return; |
| 4789 | } |
| 4790 | if (isProvisioned) { |
| 4791 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4792 | } else { |
| 4793 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4794 | } |
| 4795 | } |
| 4796 | |
| 4797 | /** |
| 4798 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4799 | * technology. The bitfield should mirror the bitfield defined by |
| 4800 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4801 | */ |
| 4802 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4803 | String key = getMmTelProvisioningKey(subId, tech); |
| 4804 | // Default is no capabilities are provisioned. |
| 4805 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4806 | } |
| 4807 | |
| 4808 | /** |
| 4809 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4810 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4811 | * technology specified. |
| 4812 | * |
| 4813 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4814 | */ |
| 4815 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4816 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4817 | String key = getMmTelProvisioningKey(subId, tech); |
| 4818 | editor.putInt(key, newField); |
| 4819 | editor.commit(); |
| 4820 | } |
| 4821 | |
| 4822 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4823 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4824 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4825 | } |
| 4826 | |
| 4827 | /** |
| 4828 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4829 | * carrier associated with the subscription id. |
| 4830 | */ |
| 4831 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4832 | int capability) { |
| 4833 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4834 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4835 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4836 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4837 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4838 | false); |
| 4839 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4840 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4841 | |
| 4842 | // First check to make sure that the capability requires provisioning. |
| 4843 | switch (capability) { |
| 4844 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4845 | // intentional fallthrough |
| 4846 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4847 | if (requireVoiceVtProvisioning) { |
| 4848 | // Voice and Video requires provisioning |
| 4849 | return true; |
| 4850 | } |
| 4851 | break; |
| 4852 | } |
| 4853 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4854 | if (requireUtProvisioning) { |
| 4855 | // UT requires provisioning |
| 4856 | return true; |
| 4857 | } |
| 4858 | break; |
| 4859 | } |
| 4860 | } |
| 4861 | return false; |
| 4862 | } |
| 4863 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4864 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4865 | int capability) { |
| 4866 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4867 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4868 | |
| 4869 | boolean requireRcsProvisioning = c.getBoolean( |
| 4870 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4871 | |
| 4872 | // First check to make sure that the capability requires provisioning. |
| 4873 | switch (capability) { |
| 4874 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4875 | // intentional fallthrough |
| 4876 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4877 | if (requireRcsProvisioning) { |
| 4878 | // OPTION or PRESENCE requires provisioning |
| 4879 | return true; |
| 4880 | } |
| 4881 | break; |
| 4882 | } |
| 4883 | } |
| 4884 | return false; |
| 4885 | } |
| 4886 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4887 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4888 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4889 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4890 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4891 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4892 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4893 | final long identity = Binder.clearCallingIdentity(); |
| 4894 | try { |
| 4895 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4896 | int slotId = getSlotIndex(subId); |
| 4897 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4898 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4899 | + subId + "' for key:" + key); |
| 4900 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4901 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4902 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4903 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4904 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4905 | + subId + "' for key:" + key); |
| 4906 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4907 | } finally { |
| 4908 | Binder.restoreCallingIdentity(identity); |
| 4909 | } |
| 4910 | } |
| 4911 | |
| 4912 | @Override |
| 4913 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4914 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4915 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4916 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4917 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4918 | final long identity = Binder.clearCallingIdentity(); |
| 4919 | try { |
| 4920 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4921 | int slotId = getSlotIndex(subId); |
| 4922 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4923 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4924 | + subId + "' for key:" + key); |
| 4925 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4926 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4927 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4928 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4929 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4930 | + subId + "' for key:" + key); |
| 4931 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4932 | } finally { |
| 4933 | Binder.restoreCallingIdentity(identity); |
| 4934 | } |
| 4935 | } |
| 4936 | |
| 4937 | @Override |
| 4938 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4939 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4940 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4941 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4942 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4943 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4944 | final long identity = Binder.clearCallingIdentity(); |
| 4945 | try { |
| 4946 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4947 | int slotId = getSlotIndex(subId); |
| 4948 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4949 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4950 | + subId + "' for key:" + key); |
| 4951 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4952 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4953 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4954 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4955 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4956 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4957 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4958 | } finally { |
| 4959 | Binder.restoreCallingIdentity(identity); |
| 4960 | } |
| 4961 | } |
| 4962 | |
| 4963 | @Override |
| 4964 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4965 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4966 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4967 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4968 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4969 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4970 | final long identity = Binder.clearCallingIdentity(); |
| 4971 | try { |
| 4972 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4973 | int slotId = getSlotIndex(subId); |
| 4974 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4975 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4976 | + subId + "' for key:" + key); |
| 4977 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4978 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4979 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4980 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4981 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4982 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4983 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4984 | } finally { |
| 4985 | Binder.restoreCallingIdentity(identity); |
| 4986 | } |
| 4987 | } |
| 4988 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4989 | /** |
| 4990 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 4991 | * for the given slot ID or no ImsResolver instance has been created. |
| 4992 | * @param slotId The slot ID that the IMS service is created for. |
| 4993 | * @throws ImsException If there is no ImsService configured for this slot. |
| 4994 | */ |
| 4995 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 4996 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 4997 | ImsFeature.FEATURE_MMTEL)) { |
| 4998 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 4999 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5000 | } |
| 5001 | } |
| 5002 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5003 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5004 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5005 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5006 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5007 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5008 | } |
| 5009 | return slotId; |
| 5010 | } |
| 5011 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5012 | private int getSlotIndex(int subId) { |
| 5013 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5014 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5015 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5016 | } |
| 5017 | return slotId; |
| 5018 | } |
| 5019 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5020 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5021 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5022 | */ |
| 5023 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5024 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5025 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5026 | try { |
| 5027 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5028 | } catch (SecurityException se) { |
| 5029 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5030 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5031 | + Binder.getCallingUid()); |
| 5032 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5033 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5034 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5035 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5036 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5037 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5038 | mApp, subId, callingPackage, callingFeatureId, |
| 5039 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5040 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5041 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5042 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5043 | final long identity = Binder.clearCallingIdentity(); |
| 5044 | try { |
| 5045 | final Phone phone = getPhone(subId); |
| 5046 | if (phone != null) { |
| 5047 | return phone.getServiceState().getDataNetworkType(); |
| 5048 | } else { |
| 5049 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5050 | } |
| 5051 | } finally { |
| 5052 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5053 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5054 | } |
| 5055 | |
| 5056 | /** |
| 5057 | * Returns the data network type |
| 5058 | */ |
| 5059 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5060 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5061 | return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(), |
| 5062 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5063 | } |
| 5064 | |
| 5065 | /** |
| 5066 | * Returns the data network type for a subId |
| 5067 | */ |
| 5068 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5069 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5070 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5071 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5072 | mApp, subId, callingPackage, callingFeatureId, |
| 5073 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5074 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5075 | } |
| 5076 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5077 | final long identity = Binder.clearCallingIdentity(); |
| 5078 | try { |
| 5079 | final Phone phone = getPhone(subId); |
| 5080 | if (phone != null) { |
| 5081 | return phone.getServiceState().getDataNetworkType(); |
| 5082 | } else { |
| 5083 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5084 | } |
| 5085 | } finally { |
| 5086 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5087 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5088 | } |
| 5089 | |
| 5090 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5091 | * Returns the Voice network type for a subId |
| 5092 | */ |
| 5093 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5094 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5095 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5096 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5097 | mApp, subId, callingPackage, callingFeatureId, |
| 5098 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5099 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 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) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5527 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5528 | mApp, subId, "setForbiddenPlmns"); |
| 5529 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5530 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5531 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5532 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5533 | } |
| 5534 | if (fplmns == null) { |
| 5535 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5536 | } |
| 5537 | for (String fplmn : fplmns) { |
| 5538 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5539 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5540 | } |
| 5541 | } |
| 5542 | final long identity = Binder.clearCallingIdentity(); |
| 5543 | try { |
| 5544 | Object response = sendRequest( |
| 5545 | CMD_SET_FORBIDDEN_PLMNS, |
| 5546 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5547 | subId); |
| 5548 | return (int) response; |
| 5549 | } finally { |
| 5550 | Binder.restoreCallingIdentity(identity); |
| 5551 | } |
| 5552 | } |
| 5553 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5554 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5555 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5556 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5557 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5558 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5559 | final long identity = Binder.clearCallingIdentity(); |
| 5560 | try { |
| 5561 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5562 | if (response.payload == null) { |
| 5563 | return ""; |
| 5564 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5565 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5566 | // Append the returned status code to the end of the response payload. |
| 5567 | String s = Integer.toHexString( |
| 5568 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5569 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5570 | return s; |
| 5571 | } finally { |
| 5572 | Binder.restoreCallingIdentity(identity); |
| 5573 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5574 | } |
| 5575 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5576 | /** |
| 5577 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5578 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5579 | * |
| 5580 | * @param itemID the ID of the item to read |
| 5581 | * @return the NV item as a String, or null on error. |
| 5582 | */ |
| 5583 | @Override |
| 5584 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5585 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5586 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5587 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5588 | |
| 5589 | final long identity = Binder.clearCallingIdentity(); |
| 5590 | try { |
| 5591 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5592 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5593 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5594 | return value; |
| 5595 | } finally { |
| 5596 | Binder.restoreCallingIdentity(identity); |
| 5597 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5598 | } |
| 5599 | |
| 5600 | /** |
| 5601 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5602 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5603 | * |
| 5604 | * @param itemID the ID of the item to read |
| 5605 | * @param itemValue the value to write, as a String |
| 5606 | * @return true on success; false on any failure |
| 5607 | */ |
| 5608 | @Override |
| 5609 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5610 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5611 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5612 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5613 | |
| 5614 | final long identity = Binder.clearCallingIdentity(); |
| 5615 | try { |
| 5616 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5617 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5618 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5619 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5620 | return success; |
| 5621 | } finally { |
| 5622 | Binder.restoreCallingIdentity(identity); |
| 5623 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5624 | } |
| 5625 | |
| 5626 | /** |
| 5627 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5628 | * Used for device configuration by some CDMA operators. |
| 5629 | * |
| 5630 | * @param preferredRoamingList byte array containing the new PRL |
| 5631 | * @return true on success; false on any failure |
| 5632 | */ |
| 5633 | @Override |
| 5634 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5635 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5636 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5637 | |
| 5638 | final long identity = Binder.clearCallingIdentity(); |
| 5639 | try { |
| 5640 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5641 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5642 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5643 | return success; |
| 5644 | } finally { |
| 5645 | Binder.restoreCallingIdentity(identity); |
| 5646 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5647 | } |
| 5648 | |
| 5649 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5650 | * 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] | 5651 | * Used for device configuration by some CDMA operators. |
| 5652 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5653 | * @param slotIndex - device slot. |
| 5654 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5655 | * @return true on success; false on any failure |
| 5656 | */ |
| 5657 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5658 | public boolean resetModemConfig(int slotIndex) { |
| 5659 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5660 | if (phone != null) { |
| 5661 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5662 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5663 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5664 | final long identity = Binder.clearCallingIdentity(); |
| 5665 | try { |
| 5666 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5667 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5668 | return success; |
| 5669 | } finally { |
| 5670 | Binder.restoreCallingIdentity(identity); |
| 5671 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5672 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5673 | return false; |
| 5674 | } |
| 5675 | |
| 5676 | /** |
| 5677 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5678 | * |
| 5679 | * @param slotIndex - device slot. |
| 5680 | * |
| 5681 | * @return true on success; false on any failure |
| 5682 | */ |
| 5683 | @Override |
| 5684 | public boolean rebootModem(int slotIndex) { |
| 5685 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5686 | if (phone != null) { |
| 5687 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5688 | mApp, phone.getSubId(), "rebootModem"); |
| 5689 | |
| 5690 | final long identity = Binder.clearCallingIdentity(); |
| 5691 | try { |
| 5692 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5693 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5694 | return success; |
| 5695 | } finally { |
| 5696 | Binder.restoreCallingIdentity(identity); |
| 5697 | } |
| 5698 | } |
| 5699 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5700 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5701 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5702 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5703 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5704 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5705 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5706 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5707 | return new String[0]; |
| 5708 | } |
| 5709 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5710 | final long identity = Binder.clearCallingIdentity(); |
| 5711 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5712 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5713 | } finally { |
| 5714 | Binder.restoreCallingIdentity(identity); |
| 5715 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5716 | } |
| 5717 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5718 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5719 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5720 | * {@link #disableIms(int)}. |
| 5721 | * @param slotIndex device slot. |
| 5722 | */ |
| 5723 | public void resetIms(int slotIndex) { |
| 5724 | enforceModifyPermission(); |
| 5725 | |
| 5726 | final long identity = Binder.clearCallingIdentity(); |
| 5727 | try { |
| 5728 | if (mImsResolver == null) { |
| 5729 | // may happen if the does not support IMS. |
| 5730 | return; |
| 5731 | } |
| 5732 | mImsResolver.disableIms(slotIndex); |
| 5733 | mImsResolver.enableIms(slotIndex); |
| 5734 | } finally { |
| 5735 | Binder.restoreCallingIdentity(identity); |
| 5736 | } |
| 5737 | } |
| 5738 | |
| 5739 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5740 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5741 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5742 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5743 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5744 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5745 | |
| 5746 | final long identity = Binder.clearCallingIdentity(); |
| 5747 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5748 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5749 | // may happen if the device does not support IMS. |
| 5750 | return; |
| 5751 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5752 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5753 | } finally { |
| 5754 | Binder.restoreCallingIdentity(identity); |
| 5755 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5756 | } |
| 5757 | |
| 5758 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5759 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5760 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5761 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5762 | public void disableIms(int slotId) { |
| 5763 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5764 | |
| 5765 | final long identity = Binder.clearCallingIdentity(); |
| 5766 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5767 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5768 | // may happen if the device does not support IMS. |
| 5769 | return; |
| 5770 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5771 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5772 | } finally { |
| 5773 | Binder.restoreCallingIdentity(identity); |
| 5774 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5775 | } |
| 5776 | |
| 5777 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5778 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5779 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5780 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5781 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5782 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5783 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5784 | |
| 5785 | final long identity = Binder.clearCallingIdentity(); |
| 5786 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5787 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5788 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5789 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5790 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5791 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5792 | } finally { |
| 5793 | Binder.restoreCallingIdentity(identity); |
| 5794 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5795 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5796 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5797 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5798 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5799 | @Override |
| 5800 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5801 | enforceModifyPermission(); |
| 5802 | |
| 5803 | final long identity = Binder.clearCallingIdentity(); |
| 5804 | try { |
| 5805 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5806 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5807 | } finally { |
| 5808 | Binder.restoreCallingIdentity(identity); |
| 5809 | } |
| 5810 | } |
| 5811 | |
| 5812 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5813 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5814 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5815 | */ |
| 5816 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5817 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5818 | |
| 5819 | final long identity = Binder.clearCallingIdentity(); |
| 5820 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5821 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5822 | // may happen if the device does not support IMS. |
| 5823 | return null; |
| 5824 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5825 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5826 | } finally { |
| 5827 | Binder.restoreCallingIdentity(identity); |
| 5828 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5829 | } |
| 5830 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5831 | /** |
| 5832 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5833 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5834 | */ |
| 5835 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5836 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5837 | |
| 5838 | final long identity = Binder.clearCallingIdentity(); |
| 5839 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5840 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5841 | // may happen if the device does not support IMS. |
| 5842 | return null; |
| 5843 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5844 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5845 | } finally { |
| 5846 | Binder.restoreCallingIdentity(identity); |
| 5847 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5848 | } |
| 5849 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5850 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5851 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5852 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5853 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5854 | * @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] | 5855 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5856 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5857 | * @param packageName The name of the package that the current configuration will be replaced |
| 5858 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5859 | * @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] | 5860 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5861 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5862 | int[] featureTypes, String packageName) { |
| 5863 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5864 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5865 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5866 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5867 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5868 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5869 | final long identity = Binder.clearCallingIdentity(); |
| 5870 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5871 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5872 | // may happen if the device does not support IMS. |
| 5873 | return false; |
| 5874 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5875 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5876 | for (int featureType : featureTypes) { |
| 5877 | featureConfig.put(featureType, packageName); |
| 5878 | } |
| 5879 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5880 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5881 | } finally { |
| 5882 | Binder.restoreCallingIdentity(identity); |
| 5883 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5884 | } |
| 5885 | |
| 5886 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5887 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5888 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5889 | * |
| 5890 | * This should only be used for testing. |
| 5891 | * |
| 5892 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5893 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5894 | */ |
| 5895 | @Override |
| 5896 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5897 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5898 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5899 | "clearCarrierImsServiceOverride"); |
| 5900 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5901 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5902 | "clearCarrierImsServiceOverride"); |
| 5903 | |
| 5904 | final long identity = Binder.clearCallingIdentity(); |
| 5905 | try { |
| 5906 | if (mImsResolver == null) { |
| 5907 | // may happen if the device does not support IMS. |
| 5908 | return false; |
| 5909 | } |
| 5910 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5911 | } finally { |
| 5912 | Binder.restoreCallingIdentity(identity); |
| 5913 | } |
| 5914 | } |
| 5915 | |
| 5916 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5917 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5918 | * |
| 5919 | * @param slotId The slot that the ImsService is associated with. |
| 5920 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5921 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5922 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5923 | * @return the package name of the ImsService configuration. |
| 5924 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5925 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5926 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5927 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5928 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5929 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5930 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5931 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5932 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5933 | final long identity = Binder.clearCallingIdentity(); |
| 5934 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5935 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5936 | // may happen if the device does not support IMS. |
| 5937 | return ""; |
| 5938 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5939 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5940 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5941 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5942 | } finally { |
| 5943 | Binder.restoreCallingIdentity(identity); |
| 5944 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5945 | } |
| 5946 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5947 | /** |
| 5948 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5949 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5950 | * @param callback A callback with an integer containing the |
| 5951 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5952 | */ |
| 5953 | @Override |
| 5954 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5955 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5956 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5957 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5958 | "IMS not available on device."); |
| 5959 | } |
| 5960 | final long token = Binder.clearCallingIdentity(); |
| 5961 | try { |
| 5962 | int slotId = getSlotIndex(subId); |
| 5963 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5964 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5965 | + subId + "'"); |
| 5966 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5967 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5968 | verifyImsMmTelConfiguredOrThrow(slotId); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5969 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5970 | try { |
| 5971 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5972 | } catch (RemoteException e) { |
| 5973 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5974 | + "Ignore"); |
| 5975 | } |
| 5976 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5977 | } catch (ImsException e) { |
| 5978 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5979 | } finally { |
| 5980 | Binder.restoreCallingIdentity(token); |
| 5981 | } |
| 5982 | } |
| 5983 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5984 | /** |
| 5985 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5986 | */ |
| 5987 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5988 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5989 | |
| 5990 | final long identity = Binder.clearCallingIdentity(); |
| 5991 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5992 | // NOTE: Before S, this method only set the default phone. |
| 5993 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5994 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5995 | phone.setImsRegistrationState(registered); |
| 5996 | } |
| 5997 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5998 | } finally { |
| 5999 | Binder.restoreCallingIdentity(identity); |
| 6000 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6001 | } |
| 6002 | |
| 6003 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6004 | * Set the network selection mode to automatic. |
| 6005 | * |
| 6006 | */ |
| 6007 | @Override |
| 6008 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6009 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6010 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6011 | |
| 6012 | final long identity = Binder.clearCallingIdentity(); |
| 6013 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6014 | if (!isActiveSubscription(subId)) { |
| 6015 | return; |
| 6016 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6017 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6018 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6019 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6020 | } finally { |
| 6021 | Binder.restoreCallingIdentity(identity); |
| 6022 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6023 | } |
| 6024 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6025 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6026 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6027 | * |
| 6028 | * @param subId the id of the subscription. |
| 6029 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6030 | * the operator to attach to. |
| 6031 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6032 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6033 | * normal network selection next time. |
| 6034 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6035 | */ |
| 6036 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6037 | public boolean setNetworkSelectionModeManual( |
| 6038 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6039 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6040 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6041 | |
| 6042 | if (!isActiveSubscription(subId)) { |
| 6043 | return false; |
| 6044 | } |
| 6045 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6046 | final long identity = Binder.clearCallingIdentity(); |
| 6047 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6048 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6049 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6050 | if (DBG) { |
| 6051 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6052 | + " operator: " + operatorInfo); |
| 6053 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6054 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6055 | } finally { |
| 6056 | Binder.restoreCallingIdentity(identity); |
| 6057 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6058 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6059 | /** |
| 6060 | * Get the manual network selection |
| 6061 | * |
| 6062 | * @param subId the id of the subscription. |
| 6063 | * |
| 6064 | * @return the previously saved user selected PLMN |
| 6065 | */ |
| 6066 | @Override |
| 6067 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6068 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6069 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6070 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 6071 | |
| 6072 | final long identity = Binder.clearCallingIdentity(); |
| 6073 | try { |
| 6074 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6075 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6076 | } |
| 6077 | |
| 6078 | final Phone phone = getPhone(subId); |
| 6079 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6080 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6081 | } |
| 6082 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6083 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6084 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6085 | } finally { |
| 6086 | Binder.restoreCallingIdentity(identity); |
| 6087 | } |
| 6088 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6089 | |
| 6090 | /** |
| 6091 | * Scans for available networks. |
| 6092 | */ |
| 6093 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6094 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6095 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6096 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6097 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6098 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6099 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6100 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6101 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6102 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6103 | .setCallingPid(Binder.getCallingPid()) |
| 6104 | .setCallingUid(Binder.getCallingUid()) |
| 6105 | .setMethod("getCellNetworkScanResults") |
| 6106 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6107 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6108 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6109 | .build()); |
| 6110 | switch (locationResult) { |
| 6111 | case DENIED_HARD: |
| 6112 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6113 | case DENIED_SOFT: |
| 6114 | return null; |
| 6115 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6116 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6117 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6118 | try { |
| 6119 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6120 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6121 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6122 | } finally { |
| 6123 | Binder.restoreCallingIdentity(identity); |
| 6124 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6125 | } |
| 6126 | |
| 6127 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6128 | * Get the call forwarding info, given the call forwarding reason. |
| 6129 | */ |
| 6130 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6131 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6132 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6133 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6134 | long identity = Binder.clearCallingIdentity(); |
| 6135 | try { |
| 6136 | if (DBG) { |
| 6137 | log("getCallForwarding: subId " + subId |
| 6138 | + " callForwardingReason" + callForwardingReason); |
| 6139 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6140 | |
| 6141 | Phone phone = getPhone(subId); |
| 6142 | if (phone == null) { |
| 6143 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6144 | callback.onError( |
| 6145 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6146 | } catch (RemoteException e) { |
| 6147 | // ignore |
| 6148 | } |
| 6149 | return; |
| 6150 | } |
| 6151 | |
| 6152 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6153 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6154 | @Override |
| 6155 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6156 | try { |
| 6157 | callback.onCallForwardingInfoAvailable(info); |
| 6158 | } catch (RemoteException e) { |
| 6159 | // ignore |
| 6160 | } |
| 6161 | } |
| 6162 | |
| 6163 | @Override |
| 6164 | public void onError(int error) { |
| 6165 | try { |
| 6166 | callback.onError(error); |
| 6167 | } catch (RemoteException e) { |
| 6168 | // ignore |
| 6169 | } |
| 6170 | } |
| 6171 | }); |
| 6172 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6173 | } finally { |
| 6174 | Binder.restoreCallingIdentity(identity); |
| 6175 | } |
| 6176 | } |
| 6177 | |
| 6178 | /** |
| 6179 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6180 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6181 | */ |
| 6182 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6183 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6184 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6185 | enforceModifyPermission(); |
| 6186 | long identity = Binder.clearCallingIdentity(); |
| 6187 | try { |
| 6188 | if (DBG) { |
| 6189 | log("setCallForwarding: subId " + subId |
| 6190 | + " callForwardingInfo" + callForwardingInfo); |
| 6191 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6192 | |
| 6193 | Phone phone = getPhone(subId); |
| 6194 | if (phone == null) { |
| 6195 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6196 | callback.accept( |
| 6197 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6198 | } catch (RemoteException e) { |
| 6199 | // ignore |
| 6200 | } |
| 6201 | return; |
| 6202 | } |
| 6203 | |
| 6204 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6205 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6206 | |
| 6207 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6208 | } finally { |
| 6209 | Binder.restoreCallingIdentity(identity); |
| 6210 | } |
| 6211 | } |
| 6212 | |
| 6213 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6214 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6215 | */ |
| 6216 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6217 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6218 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6219 | long identity = Binder.clearCallingIdentity(); |
| 6220 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6221 | Phone phone = getPhone(subId); |
| 6222 | if (phone == null) { |
| 6223 | try { |
| 6224 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6225 | } catch (RemoteException e) { |
| 6226 | // ignore |
| 6227 | } |
| 6228 | return; |
| 6229 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6230 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6231 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6232 | boolean requireUssd = c.getBoolean( |
| 6233 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6234 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6235 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6236 | if (requireUssd) { |
| 6237 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6238 | getSubscriptionCarrierId(subId)); |
| 6239 | String newUssdCommand = ""; |
| 6240 | try { |
| 6241 | newUssdCommand = carrierXmlParser.getFeature( |
| 6242 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6243 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6244 | } catch (NullPointerException e) { |
| 6245 | loge("Failed to generate USSD number" + e); |
| 6246 | } |
| 6247 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6248 | mMainThreadHandler, callback, carrierXmlParser, |
| 6249 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6250 | final String ussdCommand = newUssdCommand; |
| 6251 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6252 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6253 | }); |
| 6254 | } else { |
| 6255 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6256 | callback::accept); |
| 6257 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6258 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6259 | } finally { |
| 6260 | Binder.restoreCallingIdentity(identity); |
| 6261 | } |
| 6262 | } |
| 6263 | |
| 6264 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6265 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6266 | */ |
| 6267 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6268 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6269 | enforceModifyPermission(); |
| 6270 | long identity = Binder.clearCallingIdentity(); |
| 6271 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6272 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6273 | |
| 6274 | Phone phone = getPhone(subId); |
| 6275 | if (phone == null) { |
| 6276 | try { |
| 6277 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6278 | } catch (RemoteException e) { |
| 6279 | // ignore |
| 6280 | } |
| 6281 | return; |
| 6282 | } |
| 6283 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6284 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6285 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6286 | boolean requireUssd = c.getBoolean( |
| 6287 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6288 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6289 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6290 | if (requireUssd) { |
| 6291 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6292 | getSubscriptionCarrierId(subId)); |
| 6293 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6294 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6295 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6296 | String newUssdCommand = ""; |
| 6297 | try { |
| 6298 | newUssdCommand = carrierXmlParser.getFeature( |
| 6299 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6300 | .makeCommand(ssAction, null); |
| 6301 | } catch (NullPointerException e) { |
| 6302 | loge("Failed to generate USSD number" + e); |
| 6303 | } |
| 6304 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6305 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6306 | final String ussdCommand = newUssdCommand; |
| 6307 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6308 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6309 | }); |
| 6310 | } else { |
| 6311 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6312 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6313 | |
| 6314 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6315 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6316 | } finally { |
| 6317 | Binder.restoreCallingIdentity(identity); |
| 6318 | } |
| 6319 | } |
| 6320 | |
| 6321 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6322 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6323 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6324 | * @param subId id of the subscription |
| 6325 | * @param request contains the radio access networks with bands/channels to scan |
| 6326 | * @param messenger callback messenger for scan results or errors |
| 6327 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6328 | * @return the id of the requested scan which can be used to stop the scan. |
| 6329 | */ |
| 6330 | @Override |
| 6331 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6332 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6333 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6334 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6335 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6336 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6337 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6338 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6339 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6340 | .setCallingPid(Binder.getCallingPid()) |
| 6341 | .setCallingUid(Binder.getCallingUid()) |
| 6342 | .setMethod("requestNetworkScan") |
| 6343 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
James.cf Lin | 1d4d739 | 2020-07-03 18:22:53 +0800 | [diff] [blame] | 6344 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6345 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6346 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6347 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6348 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6349 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6350 | if (e != null) { |
| 6351 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6352 | throw e; |
| 6353 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6354 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6355 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6356 | } |
| 6357 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6358 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6359 | int callingUid = Binder.getCallingUid(); |
| 6360 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6361 | final long identity = Binder.clearCallingIdentity(); |
| 6362 | try { |
| 6363 | return mNetworkScanRequestTracker.startNetworkScan( |
| 6364 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6365 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6366 | } finally { |
| 6367 | Binder.restoreCallingIdentity(identity); |
| 6368 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6369 | } |
| 6370 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6371 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6372 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6373 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6374 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6375 | boolean hasNetworkScanPermission = |
| 6376 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6377 | == PERMISSION_GRANTED; |
| 6378 | |
| 6379 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6380 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6381 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6382 | } |
| 6383 | |
| 6384 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6385 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6386 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6387 | return new SecurityException("Specific channels must not be" |
| 6388 | + " scanned without location access."); |
| 6389 | } |
| 6390 | } |
| 6391 | } |
| 6392 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6393 | return null; |
| 6394 | } |
| 6395 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6396 | /** |
| 6397 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6398 | * |
| 6399 | * @param subId id of the subscription |
| 6400 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6401 | */ |
| 6402 | @Override |
| 6403 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6404 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6405 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6406 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6407 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6408 | final long identity = Binder.clearCallingIdentity(); |
| 6409 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6410 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6411 | } finally { |
| 6412 | Binder.restoreCallingIdentity(identity); |
| 6413 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6414 | } |
| 6415 | |
| 6416 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6417 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6418 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6419 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6420 | */ |
| 6421 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6422 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6423 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6424 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6425 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6426 | |
| 6427 | final long identity = Binder.clearCallingIdentity(); |
| 6428 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6429 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6430 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6431 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6432 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6433 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6434 | } finally { |
| 6435 | Binder.restoreCallingIdentity(identity); |
| 6436 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6437 | } |
| 6438 | |
| 6439 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6440 | * Get the allowed network types for certain reason. |
| 6441 | * |
| 6442 | * @param subId the id of the subscription. |
| 6443 | * @param reason the reason the allowed network type change is taking place |
| 6444 | * @return the allowed network types. |
| 6445 | */ |
| 6446 | @Override |
| 6447 | public long getAllowedNetworkTypesForReason(int subId, |
| 6448 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6449 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6450 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6451 | final long identity = Binder.clearCallingIdentity(); |
| 6452 | try { |
| 6453 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6454 | } finally { |
| 6455 | Binder.restoreCallingIdentity(identity); |
| 6456 | } |
| 6457 | } |
| 6458 | |
| 6459 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6460 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6461 | * @param subId subscription id of the sim card |
| 6462 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6463 | * This can be passed following states |
| 6464 | * <ol> |
| 6465 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6466 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6467 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6468 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6469 | * </ol> |
| 6470 | * @return operation result. |
| 6471 | */ |
| 6472 | @Override |
| 6473 | public int setNrDualConnectivityState(int subId, |
| 6474 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6475 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6476 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6477 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6478 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6479 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6480 | } |
| 6481 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6482 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6483 | final long identity = Binder.clearCallingIdentity(); |
| 6484 | try { |
| 6485 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6486 | nrDualConnectivityState, subId, |
| 6487 | workSource); |
| 6488 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6489 | return result; |
| 6490 | } finally { |
| 6491 | Binder.restoreCallingIdentity(identity); |
| 6492 | } |
| 6493 | } |
| 6494 | |
| 6495 | /** |
| 6496 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6497 | * @return true if dual connectivity is enabled else false |
| 6498 | */ |
| 6499 | @Override |
| 6500 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6501 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6502 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6503 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6504 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6505 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6506 | return false; |
| 6507 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6508 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6509 | final long identity = Binder.clearCallingIdentity(); |
| 6510 | try { |
| 6511 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6512 | null, subId, workSource); |
| 6513 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6514 | return isEnabled; |
| 6515 | } finally { |
| 6516 | Binder.restoreCallingIdentity(identity); |
| 6517 | } |
| 6518 | } |
| 6519 | |
| 6520 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6521 | * Set the allowed network types of the device and |
| 6522 | * provide the reason triggering the allowed network change. |
| 6523 | * |
| 6524 | * @param subId the id of the subscription. |
| 6525 | * @param reason the reason the allowed network type change is taking place |
| 6526 | * @param allowedNetworkTypes the allowed network types. |
| 6527 | * @return true on success; false on any failure. |
| 6528 | */ |
| 6529 | @Override |
| 6530 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6531 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6532 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6533 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6534 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6535 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6536 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6537 | return false; |
| 6538 | } |
| 6539 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6540 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6541 | return false; |
| 6542 | } |
| 6543 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6544 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6545 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6546 | |
| 6547 | |
| 6548 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6549 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6550 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6551 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6552 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6553 | final long identity = Binder.clearCallingIdentity(); |
| 6554 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6555 | Boolean success = (Boolean) sendRequest( |
| 6556 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6557 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6558 | |
| 6559 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6560 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6561 | } finally { |
| 6562 | Binder.restoreCallingIdentity(identity); |
| 6563 | } |
| 6564 | } |
| 6565 | |
| 6566 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6567 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6568 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6569 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6570 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6571 | * @hide |
| 6572 | */ |
| 6573 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6574 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6575 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6576 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6577 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6578 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6579 | if (phone != null) { |
| 6580 | return phone.hasMatchedTetherApnSetting(); |
| 6581 | } else { |
| 6582 | return false; |
| 6583 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6584 | } finally { |
| 6585 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6586 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6587 | } |
| 6588 | |
| 6589 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6590 | * Enable or disable always reporting signal strength changes from radio. |
| 6591 | * |
| 6592 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6593 | */ |
| 6594 | @Override |
| 6595 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6596 | enforceModifyPermission(); |
| 6597 | enforceSystemCaller(); |
| 6598 | |
| 6599 | final long identity = Binder.clearCallingIdentity(); |
| 6600 | final Phone phone = getPhone(subId); |
| 6601 | try { |
| 6602 | if (phone != null) { |
| 6603 | if (DBG) { |
| 6604 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6605 | + " isEnable=" + isEnable); |
| 6606 | } |
| 6607 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6608 | } else { |
| 6609 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6610 | + subId); |
| 6611 | } |
| 6612 | } finally { |
| 6613 | Binder.restoreCallingIdentity(identity); |
| 6614 | } |
| 6615 | } |
| 6616 | |
| 6617 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6618 | * Get the user enabled state of Mobile Data. |
| 6619 | * |
| 6620 | * TODO: remove and use isUserDataEnabled. |
| 6621 | * This can't be removed now because some vendor codes |
| 6622 | * calls through ITelephony directly while they should |
| 6623 | * use TelephonyManager. |
| 6624 | * |
| 6625 | * @return true on enabled |
| 6626 | */ |
| 6627 | @Override |
| 6628 | public boolean getDataEnabled(int subId) { |
| 6629 | return isUserDataEnabled(subId); |
| 6630 | } |
| 6631 | |
| 6632 | /** |
| 6633 | * Get whether mobile data is enabled per user setting. |
| 6634 | * |
| 6635 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6636 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6637 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6638 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6639 | * |
| 6640 | * @return {@code true} if data is enabled else {@code false} |
| 6641 | */ |
| 6642 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6643 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6644 | try { |
| 6645 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6646 | null); |
| 6647 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6648 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6649 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6650 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6651 | |
| 6652 | final long identity = Binder.clearCallingIdentity(); |
| 6653 | try { |
| 6654 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6655 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6656 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6657 | if (phone != null) { |
| 6658 | boolean retVal = phone.isUserDataEnabled(); |
| 6659 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6660 | return retVal; |
| 6661 | } else { |
| 6662 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6663 | return false; |
| 6664 | } |
| 6665 | } finally { |
| 6666 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6667 | } |
| 6668 | } |
| 6669 | |
| 6670 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6671 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6672 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6673 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6674 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6675 | * @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] | 6676 | */ |
| 6677 | @Override |
| 6678 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6679 | try { |
| 6680 | try { |
| 6681 | mApp.enforceCallingOrSelfPermission( |
| 6682 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6683 | null); |
| 6684 | } catch (Exception e) { |
| 6685 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6686 | "isDataEnabled"); |
| 6687 | } |
| 6688 | } catch (Exception e) { |
| 6689 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6690 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6691 | |
| 6692 | final long identity = Binder.clearCallingIdentity(); |
| 6693 | try { |
| 6694 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6695 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6696 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6697 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6698 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6699 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6700 | return retVal; |
| 6701 | } else { |
| 6702 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6703 | return false; |
| 6704 | } |
| 6705 | } finally { |
| 6706 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6707 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6708 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6709 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6710 | /** |
| 6711 | * Check if data is enabled for a specific reason |
| 6712 | * @param subId Subscription index |
| 6713 | * @param reason the reason the data enable change is taking place |
| 6714 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6715 | */ |
| 6716 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6717 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6718 | @TelephonyManager.DataEnabledReason int reason) { |
| 6719 | try { |
| 6720 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6721 | null); |
| 6722 | } catch (Exception e) { |
| 6723 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6724 | "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6725 | } |
| 6726 | |
| 6727 | |
| 6728 | final long identity = Binder.clearCallingIdentity(); |
| 6729 | try { |
| 6730 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6731 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6732 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6733 | + " reason=" + reason); |
| 6734 | } |
| 6735 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6736 | if (phone != null) { |
| 6737 | boolean retVal; |
| 6738 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6739 | retVal = phone.isUserDataEnabled(); |
| 6740 | } else { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6741 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6742 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6743 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6744 | return retVal; |
| 6745 | } else { |
| 6746 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6747 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6748 | + subId + " retVal=false"); |
| 6749 | } |
| 6750 | return false; |
| 6751 | } |
| 6752 | } finally { |
| 6753 | Binder.restoreCallingIdentity(identity); |
| 6754 | } |
| 6755 | } |
| 6756 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6757 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6758 | Phone phone) { |
Sarah Chin | 3394efe | 2021-04-09 10:37:15 -0700 | [diff] [blame] | 6759 | if (uid == Process.PHONE_UID) { |
| 6760 | // Skip the check if it's the phone UID (system UID removed in b/184713596) |
| 6761 | // 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] | 6762 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6763 | } |
| 6764 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6765 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6766 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6767 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6768 | || subController == null) return privilegeFromSim; |
| 6769 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6770 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6771 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6772 | |
| 6773 | final long identity = Binder.clearCallingIdentity(); |
| 6774 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6775 | int subId = phone.getSubId(); |
| 6776 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6777 | // A test override is in place for the privileges for this subId, so don't try to |
| 6778 | // read the subscription privileges. |
| 6779 | return privilegeFromSim; |
| 6780 | } |
| 6781 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6782 | SubscriptionManager subManager = (SubscriptionManager) |
| 6783 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6784 | for (String pkg : packages) { |
| 6785 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6786 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6787 | } |
| 6788 | } |
| 6789 | return privilegeFromSim; |
| 6790 | } finally { |
| 6791 | Binder.restoreCallingIdentity(identity); |
| 6792 | } |
| 6793 | } |
| 6794 | |
| 6795 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6796 | String pkgName) { |
| 6797 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6798 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6799 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6800 | || subController == null) return privilegeFromSim; |
| 6801 | |
| 6802 | final long identity = Binder.clearCallingIdentity(); |
| 6803 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6804 | int subId = phone.getSubId(); |
| 6805 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6806 | // A test override is in place for the privileges for this subId, so don't try to |
| 6807 | // read the subscription privileges. |
| 6808 | return privilegeFromSim; |
| 6809 | } |
| 6810 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6811 | SubscriptionManager subManager = (SubscriptionManager) |
| 6812 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6813 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6814 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6815 | } finally { |
| 6816 | Binder.restoreCallingIdentity(identity); |
| 6817 | } |
| 6818 | } |
| 6819 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6820 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6821 | public int getCarrierPrivilegeStatus(int subId) { |
| 6822 | final Phone phone = getPhone(subId); |
| 6823 | if (phone == null) { |
| 6824 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6825 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6826 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6827 | UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
| 6828 | if (port == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6829 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6830 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6831 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6832 | |
| 6833 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6834 | port.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6835 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6836 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6837 | |
| 6838 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6839 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6840 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6841 | final Phone phone = getPhone(subId); |
| 6842 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6843 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6844 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6845 | } |
| 6846 | UiccProfile profile = |
| 6847 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6848 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6849 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6850 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6851 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6852 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6853 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6854 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6855 | } |
| 6856 | |
| 6857 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6858 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6859 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6860 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6861 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6862 | } |
| 6863 | |
| 6864 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6865 | UiccPort port = UiccController.getInstance().getUiccPort(phoneId); |
| 6866 | if (port == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6867 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6868 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6869 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6870 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6871 | port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6872 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6873 | } |
| 6874 | |
| 6875 | @Override |
| 6876 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Sarah Chin | fc3169b | 2021-04-28 20:21:03 -0700 | [diff] [blame] | 6877 | // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6878 | if (TextUtils.isEmpty(pkgName)) |
| 6879 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6880 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6881 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6882 | UiccPort port = UiccController.getInstance().getUiccPort(i); |
| 6883 | if (port == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6884 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6885 | continue; |
| 6886 | } |
| 6887 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6888 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6889 | port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6890 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6891 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6892 | break; |
| 6893 | } |
| 6894 | } |
| 6895 | |
| 6896 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6897 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6898 | |
| 6899 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6900 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6901 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6902 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6903 | loge("phoneId " + phoneId + " is not valid."); |
| 6904 | return null; |
| 6905 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6906 | UiccPort port = UiccController.getInstance().getUiccPort(phoneId); |
| 6907 | if (port == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6908 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6909 | return null ; |
| 6910 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6911 | return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6912 | } |
| 6913 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6914 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6915 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6916 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6917 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6918 | List<String> privilegedPackages = new ArrayList<>(); |
| 6919 | List<PackageInfo> packages = null; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6920 | UiccPort port = UiccController.getInstance().getUiccPort(phoneId); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6921 | // has UICC in that slot. |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6922 | if (port != null) { |
| 6923 | if (port.hasCarrierPrivilegeRules()) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6924 | if (packages == null) { |
| 6925 | // Only check packages in user 0 for now |
| 6926 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6927 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6928 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6929 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6930 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6931 | } |
| 6932 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6933 | PackageInfo pkgInfo = packages.get(p); |
| 6934 | if (pkgInfo != null && pkgInfo.packageName != null |
Sooraj Sasindran | 97bce6f | 2021-09-28 21:37:29 +0000 | [diff] [blame] | 6935 | && getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6936 | port.getCarrierPrivilegeStatus(pkgInfo), |
| 6937 | getPhone(phoneId), pkgInfo.packageName) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6938 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6939 | privilegedPackages.add(pkgInfo.packageName); |
| 6940 | } |
| 6941 | } |
| 6942 | } |
| 6943 | } |
| 6944 | return privilegedPackages; |
| 6945 | } |
| 6946 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6947 | @Override |
| 6948 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6949 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6950 | |
| 6951 | final long identity = Binder.clearCallingIdentity(); |
| 6952 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6953 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6954 | try { |
| 6955 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6956 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6957 | } |
| 6958 | } finally { |
| 6959 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6960 | } |
| 6961 | return privilegedPackages; |
| 6962 | } |
| 6963 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6964 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6965 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6966 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 6967 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6968 | return null; |
| 6969 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6970 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6971 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6972 | return null; |
| 6973 | } |
| 6974 | return iccId; |
| 6975 | } |
| 6976 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6977 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6978 | public void setCallComposerStatus(int subId, int status) { |
| 6979 | enforceModifyPermission(); |
| 6980 | |
| 6981 | final long identity = Binder.clearCallingIdentity(); |
| 6982 | try { |
| 6983 | Phone phone = getPhone(subId); |
| 6984 | if (phone != null) { |
| 6985 | Phone defaultPhone = phone.getImsPhone(); |
| 6986 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6987 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6988 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6989 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6990 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6991 | } |
| 6992 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6993 | } catch (ImsException e) { |
| 6994 | throw new ServiceSpecificException(e.getCode()); |
| 6995 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6996 | Binder.restoreCallingIdentity(identity); |
| 6997 | } |
| 6998 | } |
| 6999 | |
| 7000 | @Override |
| 7001 | public int getCallComposerStatus(int subId) { |
| 7002 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7003 | |
| 7004 | final long identity = Binder.clearCallingIdentity(); |
| 7005 | try { |
| 7006 | Phone phone = getPhone(subId); |
| 7007 | if (phone != null) { |
| 7008 | Phone defaultPhone = phone.getImsPhone(); |
| 7009 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7010 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7011 | return imsPhone.getCallComposerStatus(); |
| 7012 | } |
| 7013 | } |
| 7014 | } finally { |
| 7015 | Binder.restoreCallingIdentity(identity); |
| 7016 | } |
| 7017 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7018 | } |
| 7019 | |
| 7020 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7021 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7022 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7023 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7024 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7025 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7026 | final long identity = Binder.clearCallingIdentity(); |
| 7027 | try { |
| 7028 | final String iccId = getIccId(subId); |
| 7029 | final Phone phone = getPhone(subId); |
| 7030 | if (phone == null) { |
| 7031 | return false; |
| 7032 | } |
| 7033 | final String subscriberId = phone.getSubscriberId(); |
| 7034 | |
| 7035 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7036 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7037 | + subscriberId + " to " + number); |
| 7038 | } |
| 7039 | |
| 7040 | if (TextUtils.isEmpty(iccId)) { |
| 7041 | return false; |
| 7042 | } |
| 7043 | |
| 7044 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7045 | |
| 7046 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7047 | if (alphaTag == null) { |
| 7048 | editor.remove(alphaTagPrefKey); |
| 7049 | } else { |
| 7050 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7051 | } |
| 7052 | |
| 7053 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7054 | // track all merged IMSIs based on line number |
| 7055 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7056 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7057 | if (number == null) { |
| 7058 | editor.remove(numberPrefKey); |
| 7059 | editor.remove(subscriberPrefKey); |
| 7060 | } else { |
| 7061 | editor.putString(numberPrefKey, number); |
| 7062 | editor.putString(subscriberPrefKey, subscriberId); |
| 7063 | } |
| 7064 | |
| 7065 | editor.commit(); |
| 7066 | return true; |
| 7067 | } finally { |
| 7068 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7069 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7070 | } |
| 7071 | |
| 7072 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7073 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7074 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7075 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7076 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7077 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7078 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7079 | return null; |
| 7080 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7081 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7082 | final long identity = Binder.clearCallingIdentity(); |
| 7083 | try { |
| 7084 | String iccId = getIccId(subId); |
| 7085 | if (iccId != null) { |
| 7086 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7087 | if (DBG_MERGE) { |
| 7088 | log("getLine1NumberForDisplay returning " |
| 7089 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7090 | } |
| 7091 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7092 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7093 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7094 | return null; |
| 7095 | } finally { |
| 7096 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7097 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7098 | } |
| 7099 | |
| 7100 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7101 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7102 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7103 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7104 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7105 | return null; |
| 7106 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7107 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7108 | final long identity = Binder.clearCallingIdentity(); |
| 7109 | try { |
| 7110 | String iccId = getIccId(subId); |
| 7111 | if (iccId != null) { |
| 7112 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7113 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7114 | } |
| 7115 | return null; |
| 7116 | } finally { |
| 7117 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7118 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7119 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7120 | |
| 7121 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7122 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7123 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7124 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7125 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7126 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7127 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7128 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7129 | return null; |
| 7130 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7131 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7132 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7133 | // the process, where TelephonyManager was instantiated. |
| 7134 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7135 | final long identity = Binder.clearCallingIdentity(); |
| 7136 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7137 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7138 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7139 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7140 | |
| 7141 | // Figure out what subscribers are currently active |
| 7142 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7143 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7144 | // Only consider subs which match the current subId |
| 7145 | // This logic can be simplified. See b/131189269 for progress. |
| 7146 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7147 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7148 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7149 | |
| 7150 | // First pass, find a number override for an active subscriber |
| 7151 | String mergeNumber = null; |
| 7152 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7153 | for (String key : prefs.keySet()) { |
| 7154 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7155 | final String subscriberId = (String) prefs.get(key); |
| 7156 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7157 | final String iccId = key.substring( |
| 7158 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7159 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7160 | mergeNumber = (String) prefs.get(numberKey); |
| 7161 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7162 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7163 | + " for active subscriber " + subscriberId); |
| 7164 | } |
| 7165 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7166 | break; |
| 7167 | } |
| 7168 | } |
| 7169 | } |
| 7170 | } |
| 7171 | |
| 7172 | // Shortcut when no active merged subscribers |
| 7173 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7174 | return null; |
| 7175 | } |
| 7176 | |
| 7177 | // Second pass, find all subscribers under that line override |
| 7178 | final ArraySet<String> result = new ArraySet<>(); |
| 7179 | for (String key : prefs.keySet()) { |
| 7180 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7181 | final String number = (String) prefs.get(key); |
| 7182 | if (mergeNumber.equals(number)) { |
| 7183 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7184 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7185 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7186 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7187 | result.add(subscriberId); |
| 7188 | } |
| 7189 | } |
| 7190 | } |
| 7191 | } |
| 7192 | |
| 7193 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7194 | Arrays.sort(resultArray); |
| 7195 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7196 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7197 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7198 | } |
| 7199 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7200 | } finally { |
| 7201 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7202 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7203 | } |
| 7204 | |
| 7205 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7206 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7207 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7208 | |
| 7209 | final long identity = Binder.clearCallingIdentity(); |
| 7210 | try { |
| 7211 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7212 | TelephonyManager.class); |
| 7213 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7214 | if (subscriberId == null) { |
| 7215 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7216 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7217 | + subId); |
| 7218 | } |
| 7219 | return null; |
| 7220 | } |
| 7221 | |
| 7222 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 7223 | .getSubscriptionInfo(subId); |
| 7224 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 7225 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7226 | if (groupUuid == null) { |
| 7227 | return new String[]{subscriberId}; |
| 7228 | } |
| 7229 | |
| 7230 | // Get all subscriberIds from the group. |
| 7231 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 7232 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7233 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7234 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7235 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7236 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7237 | if (subscriberId != null) { |
| 7238 | mergedSubscriberIds.add(subscriberId); |
| 7239 | } |
| 7240 | } |
| 7241 | |
| 7242 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7243 | } finally { |
| 7244 | Binder.restoreCallingIdentity(identity); |
| 7245 | |
| 7246 | } |
| 7247 | } |
| 7248 | |
| 7249 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7250 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7251 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7252 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7253 | |
| 7254 | final long identity = Binder.clearCallingIdentity(); |
| 7255 | try { |
| 7256 | final Phone phone = getPhone(subId); |
| 7257 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7258 | } finally { |
| 7259 | Binder.restoreCallingIdentity(identity); |
| 7260 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7261 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7262 | |
| 7263 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7264 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7265 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7266 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7267 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7268 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7269 | |
| 7270 | final long identity = Binder.clearCallingIdentity(); |
| 7271 | try { |
| 7272 | final Phone phone = getPhone(subId); |
| 7273 | if (phone == null) { |
| 7274 | return false; |
| 7275 | } |
| 7276 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7277 | cdmaNonRoamingList); |
| 7278 | } finally { |
| 7279 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7280 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7281 | } |
| 7282 | |
| 7283 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7284 | @Deprecated |
| 7285 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7286 | enforceModifyPermission(); |
| 7287 | |
| 7288 | int returnValue = 0; |
| 7289 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7290 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7291 | if(result.exception == null) { |
| 7292 | if (result.result != null) { |
| 7293 | byte[] responseData = (byte[])(result.result); |
| 7294 | if(responseData.length > oemResp.length) { |
| 7295 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7296 | responseData.length + "bytes. Buffer Size is " + |
| 7297 | oemResp.length + "bytes."); |
| 7298 | } |
| 7299 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7300 | returnValue = responseData.length; |
| 7301 | } |
| 7302 | } else { |
| 7303 | CommandException ex = (CommandException) result.exception; |
| 7304 | returnValue = ex.getCommandError().ordinal(); |
| 7305 | if(returnValue > 0) returnValue *= -1; |
| 7306 | } |
| 7307 | } catch (RuntimeException e) { |
| 7308 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7309 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7310 | if(returnValue > 0) returnValue *= -1; |
| 7311 | } |
| 7312 | |
| 7313 | return returnValue; |
| 7314 | } |
| 7315 | |
| 7316 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7317 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7318 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7319 | try { |
| 7320 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7321 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7322 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7323 | } catch (SecurityException e) { |
| 7324 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7325 | throw e; |
| 7326 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7327 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7328 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7329 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7330 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7331 | final long identity = Binder.clearCallingIdentity(); |
| 7332 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7333 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7334 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7335 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7336 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7337 | } finally { |
| 7338 | Binder.restoreCallingIdentity(identity); |
| 7339 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7340 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7341 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7342 | |
| 7343 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7344 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7345 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7346 | try { |
| 7347 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7348 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7349 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7350 | } |
| 7351 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7352 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7353 | } |
| 7354 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7355 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7356 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7357 | throw new SecurityException("App must be the dialer role holder to" |
| 7358 | + " upload a call composer pic"); |
| 7359 | } |
| 7360 | |
| 7361 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7362 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7363 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7364 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7365 | boolean readUntilEnd = false; |
| 7366 | int totalBytesRead = 0; |
| 7367 | byte[] buffer = new byte[16 * 1024]; |
| 7368 | while (true) { |
| 7369 | int numRead; |
| 7370 | try { |
| 7371 | numRead = input.read(buffer); |
| 7372 | } catch (IOException e) { |
| 7373 | try { |
| 7374 | fd.checkError(); |
| 7375 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7376 | null); |
| 7377 | } catch (IOException e1) { |
| 7378 | // This means that the other side closed explicitly with an error. If this |
| 7379 | // happens, log and ignore. |
| 7380 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7381 | } |
| 7382 | break; |
| 7383 | } |
| 7384 | if (numRead == -1) { |
| 7385 | readUntilEnd = true; |
| 7386 | break; |
| 7387 | } |
| 7388 | totalBytesRead += numRead; |
| 7389 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7390 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7391 | try { |
| 7392 | input.close(); |
| 7393 | } catch (IOException e) { |
| 7394 | // ignore |
| 7395 | } |
| 7396 | break; |
| 7397 | } |
| 7398 | output.write(buffer, 0, numRead); |
| 7399 | } |
| 7400 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7401 | // close is above, where the picture size is too big. |
| 7402 | |
| 7403 | try { |
| 7404 | fd.checkError(); |
| 7405 | } catch (IOException e) { |
| 7406 | loge("Remote end for call composer closed with an error: " + e); |
| 7407 | return; |
| 7408 | } |
| 7409 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7410 | if (!readUntilEnd) { |
| 7411 | loge("Did not finish reading entire image; aborting"); |
| 7412 | return; |
| 7413 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7414 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7415 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7416 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7417 | new CallComposerPictureTransfer.Factory() {}, |
| 7418 | imageData, |
| 7419 | (result) -> { |
| 7420 | if (result.first != null) { |
| 7421 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7422 | Bundle outputResult = new Bundle(); |
| 7423 | outputResult.putParcelable( |
| 7424 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7425 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7426 | outputResult); |
| 7427 | } else { |
| 7428 | callback.send(result.second, null); |
| 7429 | } |
| 7430 | } |
| 7431 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7432 | }); |
| 7433 | } |
| 7434 | |
| 7435 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7436 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7437 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7438 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7439 | |
| 7440 | final long identity = Binder.clearCallingIdentity(); |
| 7441 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7442 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7443 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7444 | } finally { |
| 7445 | Binder.restoreCallingIdentity(identity); |
| 7446 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7447 | } |
| 7448 | |
| 7449 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7450 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7451 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7452 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7453 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7454 | return false; |
| 7455 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7456 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7457 | final long identity = Binder.clearCallingIdentity(); |
| 7458 | try { |
| 7459 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7460 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7461 | // In the long run, we may instead need to check if there exists a connection service |
| 7462 | // which can support video calling. |
| 7463 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7464 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7465 | return imsManager.isVtEnabledByPlatform() |
| 7466 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7467 | && imsManager.isVtEnabledByUser(); |
| 7468 | } finally { |
| 7469 | Binder.restoreCallingIdentity(identity); |
| 7470 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7471 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7472 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7473 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7474 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7475 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7476 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7477 | mApp, subId, callingPackage, callingFeatureId, |
| 7478 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7479 | return false; |
| 7480 | } |
| 7481 | |
| 7482 | final long identity = Binder.clearCallingIdentity(); |
| 7483 | try { |
| 7484 | CarrierConfigManager configManager = |
| 7485 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7486 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7487 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7488 | } finally { |
| 7489 | Binder.restoreCallingIdentity(identity); |
| 7490 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7491 | } |
| 7492 | |
| 7493 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7494 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7495 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7496 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7497 | return false; |
| 7498 | } |
| 7499 | |
| 7500 | final long identity = Binder.clearCallingIdentity(); |
| 7501 | try { |
| 7502 | CarrierConfigManager configManager = |
| 7503 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7504 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7505 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7506 | } finally { |
| 7507 | Binder.restoreCallingIdentity(identity); |
| 7508 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7509 | } |
| 7510 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7511 | @Override |
| 7512 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7513 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7514 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7515 | } |
| 7516 | |
| 7517 | @Override |
| 7518 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7519 | final long identity = Binder.clearCallingIdentity(); |
| 7520 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7521 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7522 | } finally { |
| 7523 | Binder.restoreCallingIdentity(identity); |
| 7524 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7525 | } |
| 7526 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7527 | /** |
| 7528 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7529 | * support for the feature and device firmware support. |
| 7530 | * |
| 7531 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7532 | */ |
| 7533 | @Override |
| 7534 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7535 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7536 | final Phone phone = getPhone(subscriptionId); |
| 7537 | if (phone == null) { |
| 7538 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7539 | return false; |
| 7540 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7541 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7542 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7543 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7544 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7545 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7546 | return isCarrierSupported && isDeviceSupported; |
| 7547 | } finally { |
| 7548 | Binder.restoreCallingIdentity(identity); |
| 7549 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7550 | } |
| 7551 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7552 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7553 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7554 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7555 | * 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] | 7556 | */ |
| 7557 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7558 | final long identity = Binder.clearCallingIdentity(); |
| 7559 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7560 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7561 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7562 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7563 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7564 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7565 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7566 | } finally { |
| 7567 | Binder.restoreCallingIdentity(identity); |
| 7568 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7569 | } |
| 7570 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7571 | @Deprecated |
| 7572 | @Override |
| 7573 | public String getDeviceId(String callingPackage) { |
| 7574 | return getDeviceIdWithFeature(callingPackage, null); |
| 7575 | } |
| 7576 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7577 | /** |
| 7578 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7579 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7580 | * |
| 7581 | * <p>Requires Permission: |
| 7582 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7583 | */ |
| 7584 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7585 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7586 | try { |
| 7587 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7588 | } catch (SecurityException se) { |
| 7589 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7590 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7591 | + Binder.getCallingUid()); |
| 7592 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7593 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7594 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7595 | return null; |
| 7596 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7597 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7598 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7599 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7600 | return null; |
| 7601 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7602 | |
| 7603 | final long identity = Binder.clearCallingIdentity(); |
| 7604 | try { |
| 7605 | return phone.getDeviceId(); |
| 7606 | } finally { |
| 7607 | Binder.restoreCallingIdentity(identity); |
| 7608 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7609 | } |
| 7610 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7611 | /** |
| 7612 | * {@hide} |
| 7613 | * Returns the IMS Registration Status on a particular subid |
| 7614 | * |
| 7615 | * @param subId |
| 7616 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7617 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7618 | Phone phone = getPhone(subId); |
| 7619 | if (phone != null) { |
| 7620 | return phone.isImsRegistered(); |
| 7621 | } else { |
| 7622 | return false; |
| 7623 | } |
| 7624 | } |
| 7625 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7626 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7627 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7628 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7629 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7630 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7631 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7632 | } |
| 7633 | final long identity = Binder.clearCallingIdentity(); |
| 7634 | try { |
| 7635 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7636 | } finally { |
| 7637 | Binder.restoreCallingIdentity(identity); |
| 7638 | } |
| 7639 | } |
| 7640 | |
| 7641 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7642 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7643 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7644 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7645 | mApp, |
| 7646 | subscriptionId, |
| 7647 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7648 | final long identity = Binder.clearCallingIdentity(); |
| 7649 | try { |
| 7650 | Phone phone = getPhone(subscriptionId); |
| 7651 | if (phone == null) { |
| 7652 | return null; |
| 7653 | } |
| 7654 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7655 | } finally { |
| 7656 | Binder.restoreCallingIdentity(identity); |
| 7657 | } |
| 7658 | } |
| 7659 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7660 | /** |
| 7661 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7662 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7663 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7664 | final long identity = Binder.clearCallingIdentity(); |
| 7665 | try { |
| 7666 | Phone phone = getPhone(subId); |
| 7667 | if (phone != null) { |
| 7668 | return phone.isWifiCallingEnabled(); |
| 7669 | } else { |
| 7670 | return false; |
| 7671 | } |
| 7672 | } finally { |
| 7673 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7674 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7675 | } |
| 7676 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7677 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7678 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7679 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7680 | public boolean isVideoTelephonyAvailable(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.isVideoEnabled(); |
| 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 | } |
| 7692 | } |
| 7693 | |
| 7694 | /** |
| 7695 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7696 | * defined in {@link ImsRegistrationImplBase}. |
| 7697 | */ |
| 7698 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7699 | final long identity = Binder.clearCallingIdentity(); |
| 7700 | try { |
| 7701 | Phone phone = getPhone(subId); |
| 7702 | if (phone != null) { |
| 7703 | return phone.getImsRegistrationTech(); |
| 7704 | } else { |
| 7705 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7706 | } |
| 7707 | } finally { |
| 7708 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7709 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7710 | } |
| 7711 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7712 | @Override |
| 7713 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7714 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7715 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7716 | return; |
| 7717 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7718 | Phone defaultPhone = getDefaultPhone(); |
| 7719 | if (defaultPhone != null) { |
| 7720 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7721 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7722 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7723 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7724 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7725 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7726 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7727 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7728 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7729 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7730 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7731 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7732 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7733 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7734 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7735 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7736 | // There has been issues when Sms raw table somehow stores orphan |
| 7737 | // fragments. They lead to garbled message when new fragments come |
| 7738 | // in and combined with those stale ones. In case this happens again, |
| 7739 | // user can reset all network settings which will clean up this table. |
| 7740 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7741 | // Clean up IMS settings as well here. |
| 7742 | int slotId = getSlotIndex(subId); |
| 7743 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7744 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7745 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7746 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7747 | if (defaultPhone == null) { |
| 7748 | return; |
| 7749 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7750 | // Erase modem config if erase modem on network setting is enabled. |
| 7751 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7752 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7753 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7754 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7755 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7756 | |
| 7757 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7758 | } finally { |
| 7759 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7760 | } |
| 7761 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7762 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7763 | @VisibleForTesting |
| 7764 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7765 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7766 | return; |
| 7767 | } |
| 7768 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7769 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7770 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7771 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7772 | "user=" + defaultNetworkType); |
| 7773 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7774 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7775 | defaultNetworkType, null); |
| 7776 | } |
| 7777 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7778 | private void cleanUpSmsRawTable(Context context) { |
| 7779 | ContentResolver resolver = context.getContentResolver(); |
| 7780 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7781 | resolver.delete(uri, null, null); |
| 7782 | } |
| 7783 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7784 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7785 | public String getSimLocaleForSubscriber(int subId) { |
| 7786 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7787 | final Phone phone = getPhone(subId); |
| 7788 | if (phone == null) { |
| 7789 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7790 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7791 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7792 | final long identity = Binder.clearCallingIdentity(); |
| 7793 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7794 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7795 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7796 | if (info == null) { |
| 7797 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7798 | return null; |
| 7799 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7800 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7801 | // preferences (EF-PL and EF-LI)... |
| 7802 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7803 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7804 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7805 | if (localeFromDefaultSim != null) { |
| 7806 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7807 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7808 | + localeFromDefaultSim); |
| 7809 | return localeFromDefaultSim.toLanguageTag(); |
| 7810 | } else { |
| 7811 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7812 | } |
| 7813 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7814 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7815 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7816 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7817 | // the SIM and carrier preferences does not include a country we add the country |
| 7818 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7819 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7820 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7821 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7822 | return mccLocale.toLanguageTag(); |
| 7823 | } |
| 7824 | |
| 7825 | if (DBG) log("No locale found - returning null"); |
| 7826 | return null; |
| 7827 | } finally { |
| 7828 | Binder.restoreCallingIdentity(identity); |
| 7829 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7830 | } |
| 7831 | |
| 7832 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7833 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7834 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7835 | } |
| 7836 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7837 | /** |
| 7838 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7839 | */ |
| 7840 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7841 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7842 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7843 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7844 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7845 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7846 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7847 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7848 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7849 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7850 | * representing the state of the modem. |
| 7851 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7852 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7853 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7854 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7855 | */ |
| 7856 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7857 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7858 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7859 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7860 | |
| 7861 | final long identity = Binder.clearCallingIdentity(); |
| 7862 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7863 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7864 | } finally { |
| 7865 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7866 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7867 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7868 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7869 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7870 | // less than total activity duration. |
| 7871 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7872 | if (info == null) { |
| 7873 | return false; |
| 7874 | } |
| 7875 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7876 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7877 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7878 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7879 | return (info.isValid() |
| 7880 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7881 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7882 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7883 | && (totalTxTimeMs <= activityDurationMs)); |
| 7884 | } |
| 7885 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7886 | /** |
| 7887 | * {@hide} |
| 7888 | * Returns the service state information on specified subscription. |
| 7889 | */ |
| 7890 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7891 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7892 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7893 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7894 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7895 | return null; |
| 7896 | } |
| 7897 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7898 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7899 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7900 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7901 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7902 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7903 | .setCallingPid(Binder.getCallingPid()) |
| 7904 | .setCallingUid(Binder.getCallingUid()) |
| 7905 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7906 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7907 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7908 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7909 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7910 | .build()); |
| 7911 | |
| 7912 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7913 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7914 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7915 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7916 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7917 | .setCallingPid(Binder.getCallingPid()) |
| 7918 | .setCallingUid(Binder.getCallingUid()) |
| 7919 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7920 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7921 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7922 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7923 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7924 | .build()); |
| 7925 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7926 | boolean hasFinePermission = |
| 7927 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7928 | boolean hasCoarsePermission = |
| 7929 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7930 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7931 | final Phone phone = getPhone(subId); |
| 7932 | if (phone == null) { |
| 7933 | return null; |
| 7934 | } |
| 7935 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7936 | final long identity = Binder.clearCallingIdentity(); |
| 7937 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7938 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7939 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7940 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7941 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7942 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7943 | Rlog.d(LOG_TAG, |
| 7944 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7945 | return null; |
| 7946 | } |
| 7947 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7948 | ServiceState ss = phone.getServiceState(); |
| 7949 | |
| 7950 | // Scrub out the location info in ServiceState depending on what level of access |
| 7951 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7952 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7953 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7954 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7955 | } finally { |
| 7956 | Binder.restoreCallingIdentity(identity); |
| 7957 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7958 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7959 | |
| 7960 | /** |
| 7961 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7962 | * |
| 7963 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7964 | * voicemail ringtone. |
| 7965 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7966 | * PhoneAccount. |
| 7967 | */ |
| 7968 | @Override |
| 7969 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7970 | final long identity = Binder.clearCallingIdentity(); |
| 7971 | try { |
| 7972 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7973 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7974 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7975 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7976 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7977 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7978 | } finally { |
| 7979 | Binder.restoreCallingIdentity(identity); |
| 7980 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7981 | } |
| 7982 | |
| 7983 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7984 | * Sets the per-account voicemail ringtone. |
| 7985 | * |
| 7986 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7987 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7988 | * |
| 7989 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7990 | * voicemail ringtone. |
| 7991 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7992 | * PhoneAccount. |
| 7993 | */ |
| 7994 | @Override |
| 7995 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7996 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7997 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7998 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7999 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8000 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8001 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8002 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8003 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8004 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8005 | |
| 8006 | final long identity = Binder.clearCallingIdentity(); |
| 8007 | try { |
| 8008 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8009 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8010 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8011 | } |
| 8012 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8013 | } finally { |
| 8014 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8015 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8016 | } |
| 8017 | |
| 8018 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8019 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8020 | * |
| 8021 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8022 | * voicemail vibration setting. |
| 8023 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8024 | */ |
| 8025 | @Override |
| 8026 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8027 | final long identity = Binder.clearCallingIdentity(); |
| 8028 | try { |
| 8029 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8030 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8031 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8032 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8033 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8034 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8035 | } finally { |
| 8036 | Binder.restoreCallingIdentity(identity); |
| 8037 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8038 | } |
| 8039 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8040 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8041 | * Sets the per-account voicemail vibration. |
| 8042 | * |
| 8043 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8044 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8045 | * |
| 8046 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8047 | * voicemail vibration setting. |
| 8048 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8049 | * specific PhoneAccount. |
| 8050 | */ |
| 8051 | @Override |
| 8052 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8053 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8054 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8055 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8056 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8057 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8058 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8059 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8060 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8061 | } |
| 8062 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8063 | final long identity = Binder.clearCallingIdentity(); |
| 8064 | try { |
| 8065 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8066 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8067 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8068 | } |
| 8069 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8070 | } finally { |
| 8071 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8072 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8073 | } |
| 8074 | |
| 8075 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8076 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8077 | * |
| 8078 | * @throws SecurityException if the caller does not have the required permission |
| 8079 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8080 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8081 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8082 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8083 | } |
| 8084 | |
| 8085 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8086 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8087 | * permission. |
| 8088 | * |
| 8089 | * @throws SecurityException if the caller does not have the required permission |
| 8090 | */ |
| 8091 | private void enforceSendSmsPermission() { |
| 8092 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8093 | } |
| 8094 | |
| 8095 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8096 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8097 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8098 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8099 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8100 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8101 | final long identity = Binder.clearCallingIdentity(); |
| 8102 | try { |
| 8103 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8104 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8105 | if (componentName == null) { |
| 8106 | throw new SecurityException( |
| 8107 | "Caller not current active visual voicemail package[null]"); |
| 8108 | } |
| 8109 | String vvmPackage = componentName.getPackageName(); |
| 8110 | if (!callingPackage.equals(vvmPackage)) { |
| 8111 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 8112 | + vvmPackage + "]"); |
| 8113 | } |
| 8114 | } finally { |
| 8115 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8116 | } |
| 8117 | } |
| 8118 | |
| 8119 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8120 | * Return the application ID for the app type. |
| 8121 | * |
| 8122 | * @param subId the subscription ID that this request applies to. |
| 8123 | * @param appType the uicc app type. |
| 8124 | * @return Application ID for specificied app type, or null if no uicc. |
| 8125 | */ |
| 8126 | @Override |
| 8127 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8128 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8129 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8130 | |
| 8131 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8132 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8133 | if (phone == null) { |
| 8134 | return null; |
| 8135 | } |
| 8136 | String aid = null; |
| 8137 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8138 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8139 | .getApplicationByType(appType).getAid(); |
| 8140 | } catch (Exception e) { |
| 8141 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8142 | } |
| 8143 | return aid; |
| 8144 | } finally { |
| 8145 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8146 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8147 | } |
| 8148 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8149 | /** |
| 8150 | * Return the Electronic Serial Number. |
| 8151 | * |
| 8152 | * @param subId the subscription ID that this request applies to. |
| 8153 | * @return ESN or null if error. |
| 8154 | */ |
| 8155 | @Override |
| 8156 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8157 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8158 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8159 | |
| 8160 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8161 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8162 | if (phone == null) { |
| 8163 | return null; |
| 8164 | } |
| 8165 | String esn = null; |
| 8166 | try { |
| 8167 | esn = phone.getEsn(); |
| 8168 | } catch (Exception e) { |
| 8169 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8170 | } |
| 8171 | return esn; |
| 8172 | } finally { |
| 8173 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8174 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8175 | } |
| 8176 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8177 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8178 | * Return the Preferred Roaming List Version. |
| 8179 | * |
| 8180 | * @param subId the subscription ID that this request applies to. |
| 8181 | * @return PRLVersion or null if error. |
| 8182 | */ |
| 8183 | @Override |
| 8184 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8185 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8186 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8187 | |
| 8188 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8189 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8190 | if (phone == null) { |
| 8191 | return null; |
| 8192 | } |
| 8193 | String cdmaPrlVersion = null; |
| 8194 | try { |
| 8195 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8196 | } catch (Exception e) { |
| 8197 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8198 | } |
| 8199 | return cdmaPrlVersion; |
| 8200 | } finally { |
| 8201 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8202 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8203 | } |
| 8204 | |
| 8205 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8206 | * Get snapshot of Telephony histograms |
| 8207 | * @return List of Telephony histograms |
| 8208 | * @hide |
| 8209 | */ |
| 8210 | @Override |
| 8211 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8212 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8213 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8214 | |
| 8215 | final long identity = Binder.clearCallingIdentity(); |
| 8216 | try { |
| 8217 | return RIL.getTelephonyRILTimingHistograms(); |
| 8218 | } finally { |
| 8219 | Binder.restoreCallingIdentity(identity); |
| 8220 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8221 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8222 | |
| 8223 | /** |
| 8224 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8225 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8226 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8227 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8228 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8229 | * @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] | 8230 | */ |
| 8231 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8232 | @TelephonyManager.SetCarrierRestrictionResult |
| 8233 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8234 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8235 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8236 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8237 | if (carrierRestrictionRules == null) { |
| 8238 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8239 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8240 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8241 | final long identity = Binder.clearCallingIdentity(); |
| 8242 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8243 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8244 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8245 | } finally { |
| 8246 | Binder.restoreCallingIdentity(identity); |
| 8247 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8248 | } |
| 8249 | |
| 8250 | /** |
| 8251 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8252 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8253 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8254 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8255 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8256 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8257 | */ |
| 8258 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8259 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8260 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8261 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8262 | |
| 8263 | final long identity = Binder.clearCallingIdentity(); |
| 8264 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8265 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8266 | if (response instanceof CarrierRestrictionRules) { |
| 8267 | return (CarrierRestrictionRules) response; |
| 8268 | } |
| 8269 | // Response is an Exception of some kind, |
| 8270 | // which is signalled to the user as a NULL retval |
| 8271 | return null; |
| 8272 | } catch (Exception e) { |
| 8273 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8274 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8275 | } finally { |
| 8276 | Binder.restoreCallingIdentity(identity); |
| 8277 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8278 | } |
| 8279 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8280 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8281 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8282 | * @param subId the subscription ID that this action applies to. |
| 8283 | * @param enabled control enable or disable radio. |
| 8284 | * {@hide} |
| 8285 | */ |
| 8286 | @Override |
| 8287 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8288 | enforceModifyPermission(); |
| 8289 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8290 | |
| 8291 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8292 | if (phone == null) { |
| 8293 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8294 | return; |
| 8295 | } |
| 8296 | try { |
| 8297 | phone.carrierActionSetRadioEnabled(enabled); |
| 8298 | } catch (Exception e) { |
| 8299 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8300 | } finally { |
| 8301 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8302 | } |
| 8303 | } |
| 8304 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8305 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8306 | * Enable or disable Voice over NR (VoNR) |
| 8307 | * @param subId the subscription ID that this action applies to. |
| 8308 | * @param enabled enable or disable VoNR. |
| 8309 | * @return operation result. |
| 8310 | */ |
| 8311 | @Override |
| 8312 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8313 | enforceModifyPermission(); |
| 8314 | final Phone phone = getPhone(subId); |
| 8315 | |
| 8316 | final long identity = Binder.clearCallingIdentity(); |
| 8317 | if (phone == null) { |
| 8318 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8319 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8320 | } |
| 8321 | |
| 8322 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8323 | try { |
| 8324 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8325 | workSource); |
| 8326 | if (DBG) log("setVoNrEnabled result: " + result); |
| 8327 | return result; |
| 8328 | } finally { |
| 8329 | Binder.restoreCallingIdentity(identity); |
| 8330 | } |
| 8331 | } |
| 8332 | |
| 8333 | /** |
| 8334 | * Is voice over NR enabled |
| 8335 | * @return true if VoNR is enabled else false |
| 8336 | */ |
| 8337 | @Override |
| 8338 | public boolean isVoNrEnabled(int subId) { |
| 8339 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8340 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8341 | final long identity = Binder.clearCallingIdentity(); |
| 8342 | try { |
| 8343 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8344 | null, subId, workSource); |
| 8345 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8346 | return isEnabled; |
| 8347 | } finally { |
| 8348 | Binder.restoreCallingIdentity(identity); |
| 8349 | } |
| 8350 | } |
| 8351 | |
| 8352 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8353 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8354 | * network status based on which carrier apps could apply actions accordingly, |
| 8355 | * enable/disable default url handler for example. |
| 8356 | * |
| 8357 | * @param subId the subscription ID that this action applies to. |
| 8358 | * @param report control start/stop reporting the default network status. |
| 8359 | * {@hide} |
| 8360 | */ |
| 8361 | @Override |
| 8362 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8363 | enforceModifyPermission(); |
| 8364 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8365 | |
| 8366 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8367 | if (phone == null) { |
| 8368 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8369 | return; |
| 8370 | } |
| 8371 | try { |
| 8372 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8373 | } catch (Exception e) { |
| 8374 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8375 | } finally { |
| 8376 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8377 | } |
| 8378 | } |
| 8379 | |
| 8380 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8381 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8382 | * @param subId the subscription ID that this action applies to. |
| 8383 | * {@hide} |
| 8384 | */ |
| 8385 | @Override |
| 8386 | public void carrierActionResetAll(int subId) { |
| 8387 | enforceModifyPermission(); |
| 8388 | final Phone phone = getPhone(subId); |
| 8389 | if (phone == null) { |
| 8390 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8391 | return; |
| 8392 | } |
| 8393 | try { |
| 8394 | phone.carrierActionResetAll(); |
| 8395 | } catch (Exception e) { |
| 8396 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8397 | } |
| 8398 | } |
| 8399 | |
| 8400 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8401 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8402 | * bug report is being generated. |
| 8403 | */ |
| 8404 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8405 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8406 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8407 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8408 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8409 | + Binder.getCallingPid() |
| 8410 | + ", uid=" + Binder.getCallingUid() |
| 8411 | + "without permission " |
| 8412 | + android.Manifest.permission.DUMP); |
| 8413 | return; |
| 8414 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8415 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8416 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8417 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8418 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8419 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8420 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8421 | @NonNull String[] args) { |
| 8422 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8423 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8424 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8425 | } |
| 8426 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8427 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8428 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8429 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8430 | * @param reason the reason the data enable change is taking place |
| 8431 | * @param enabled True if enabling the data, otherwise disabling. |
| 8432 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8433 | */ |
| 8434 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8435 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8436 | boolean enabled) { |
| 8437 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8438 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8439 | try { |
| 8440 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8441 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8442 | } catch (SecurityException se) { |
| 8443 | enforceModifyPermission(); |
| 8444 | } |
| 8445 | } else { |
| 8446 | enforceModifyPermission(); |
| 8447 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8448 | |
| 8449 | final long identity = Binder.clearCallingIdentity(); |
| 8450 | try { |
| 8451 | Phone phone = getPhone(subId); |
| 8452 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8453 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8454 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8455 | } else { |
| 8456 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 8457 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8458 | } |
| 8459 | } finally { |
| 8460 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8461 | } |
| 8462 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8463 | |
| 8464 | /** |
| 8465 | * Get Client request stats |
| 8466 | * @return List of Client Request Stats |
| 8467 | * @hide |
| 8468 | */ |
| 8469 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8470 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8471 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8472 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8473 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8474 | return null; |
| 8475 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8476 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8477 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8478 | final long identity = Binder.clearCallingIdentity(); |
| 8479 | try { |
| 8480 | if (phone != null) { |
| 8481 | return phone.getClientRequestStats(); |
| 8482 | } |
| 8483 | |
| 8484 | return null; |
| 8485 | } finally { |
| 8486 | Binder.restoreCallingIdentity(identity); |
| 8487 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8488 | } |
| 8489 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8490 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8491 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8492 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8493 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8494 | |
| 8495 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8496 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8497 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8498 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8499 | * @param state State of SIM (power down, power up, pass through) |
| 8500 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8501 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8502 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8503 | * |
| 8504 | **/ |
| 8505 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8506 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8507 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8508 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8509 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8510 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8511 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8512 | final long identity = Binder.clearCallingIdentity(); |
| 8513 | try { |
| 8514 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8515 | phone.setSimPowerState(state, null, workSource); |
| 8516 | } |
| 8517 | } finally { |
| 8518 | Binder.restoreCallingIdentity(identity); |
| 8519 | } |
| 8520 | } |
| 8521 | |
| 8522 | /** |
| 8523 | * Set SIM card power state. |
| 8524 | * |
| 8525 | * @param slotIndex SIM slot id. |
| 8526 | * @param state State of SIM (power down, power up, pass through) |
| 8527 | * @param callback callback to trigger after success or failure |
| 8528 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8529 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8530 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8531 | * |
| 8532 | **/ |
| 8533 | @Override |
| 8534 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8535 | IIntegerConsumer callback) { |
| 8536 | enforceModifyPermission(); |
| 8537 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8538 | |
| 8539 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8540 | |
| 8541 | final long identity = Binder.clearCallingIdentity(); |
| 8542 | try { |
| 8543 | if (phone != null) { |
| 8544 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8545 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8546 | } |
| 8547 | } finally { |
| 8548 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8549 | } |
| 8550 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8551 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8552 | private boolean isUssdApiAllowed(int subId) { |
| 8553 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8554 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8555 | if (configManager == null) { |
| 8556 | return false; |
| 8557 | } |
| 8558 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8559 | if (pb == null) { |
| 8560 | return false; |
| 8561 | } |
| 8562 | return pb.getBoolean( |
| 8563 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8564 | } |
| 8565 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8566 | /** |
| 8567 | * Check if phone is in emergency callback mode |
| 8568 | * @return true if phone is in emergency callback mode |
| 8569 | * @param subId sub id |
| 8570 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8571 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8572 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8573 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8574 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8575 | |
| 8576 | final long identity = Binder.clearCallingIdentity(); |
| 8577 | try { |
| 8578 | if (phone != null) { |
| 8579 | return phone.isInEcm(); |
| 8580 | } else { |
| 8581 | return false; |
| 8582 | } |
| 8583 | } finally { |
| 8584 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8585 | } |
| 8586 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8587 | |
| 8588 | /** |
| 8589 | * Get the current signal strength information for the given subscription. |
| 8590 | * Because this information is not updated when the device is in a low power state |
| 8591 | * it should not be relied-upon to be current. |
| 8592 | * @param subId Subscription index |
| 8593 | * @return the most recent cached signal strength info from the modem |
| 8594 | */ |
| 8595 | @Override |
| 8596 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8597 | final long identity = Binder.clearCallingIdentity(); |
| 8598 | try { |
| 8599 | Phone p = getPhone(subId); |
| 8600 | if (p == null) { |
| 8601 | return null; |
| 8602 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8603 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8604 | return p.getSignalStrength(); |
| 8605 | } finally { |
| 8606 | Binder.restoreCallingIdentity(identity); |
| 8607 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8608 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8609 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8610 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8611 | * Get the current modem radio state for the given slot. |
| 8612 | * @param slotIndex slot index. |
| 8613 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8614 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8615 | * @return the current radio power state from the modem |
| 8616 | */ |
| 8617 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8618 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8619 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8620 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8621 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8622 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8623 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8624 | } |
| 8625 | |
| 8626 | final long identity = Binder.clearCallingIdentity(); |
| 8627 | try { |
| 8628 | return phone.getRadioPowerState(); |
| 8629 | } finally { |
| 8630 | Binder.restoreCallingIdentity(identity); |
| 8631 | } |
| 8632 | } |
| 8633 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8634 | } |
| 8635 | |
| 8636 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8637 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8638 | * |
| 8639 | * <p>Requires one of the following permissions: |
| 8640 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8641 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8642 | * privileges. |
| 8643 | * |
| 8644 | * @param subId subscription id |
| 8645 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8646 | * {@code false}. |
| 8647 | */ |
| 8648 | @Override |
| 8649 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8650 | try { |
| 8651 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8652 | null); |
| 8653 | } catch (Exception e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8654 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8655 | mApp, subId, "isDataRoamingEnabled"); |
| 8656 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8657 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8658 | boolean isEnabled = false; |
| 8659 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8660 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8661 | Phone phone = getPhone(subId); |
| 8662 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8663 | } finally { |
| 8664 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8665 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8666 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8667 | } |
| 8668 | |
| 8669 | |
| 8670 | /** |
| 8671 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8672 | * |
| 8673 | * <p> Requires permission: |
| 8674 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8675 | * privileges. |
| 8676 | * |
| 8677 | * @param subId subscription id |
| 8678 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8679 | */ |
| 8680 | @Override |
| 8681 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8682 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8683 | mApp, subId, "setDataRoamingEnabled"); |
| 8684 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8685 | final long identity = Binder.clearCallingIdentity(); |
| 8686 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8687 | Phone phone = getPhone(subId); |
| 8688 | if (phone != null) { |
| 8689 | phone.setDataRoamingEnabled(isEnabled); |
| 8690 | } |
| 8691 | } finally { |
| 8692 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8693 | } |
| 8694 | } |
| 8695 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8696 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8697 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8698 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8699 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8700 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8701 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8702 | boolean isAllowed = true; |
| 8703 | final long identity = Binder.clearCallingIdentity(); |
| 8704 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8705 | Phone phone = getPhone(subId); |
| 8706 | if (phone != null) { |
| 8707 | isAllowed = phone.isCspPlmnEnabled(); |
| 8708 | } |
| 8709 | } finally { |
| 8710 | Binder.restoreCallingIdentity(identity); |
| 8711 | } |
| 8712 | return isAllowed; |
| 8713 | } |
| 8714 | |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8715 | private boolean haveCarrierPrivilegeAccess(UiccCard card, String callingPackage) { |
| 8716 | // TODO once MEP API refactoring CL is merged, loop port list from UiccCardInfo, |
| 8717 | // and if find the matching UiccPort by UiccController.getUiccPortForSlot(slot, portIdx) |
| 8718 | // Update each UiccPort object based on privilege access |
| 8719 | UiccPort[] uiccPorts = card.getUiccPortList(); |
| 8720 | for (UiccPort port : uiccPorts) { |
| 8721 | UiccProfile profile = port.getUiccProfile(); |
| 8722 | if (profile == null || |
| 8723 | profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8724 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8725 | return false; |
| 8726 | } |
| 8727 | } |
| 8728 | return true; |
| 8729 | } |
| 8730 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8731 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8732 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8733 | // Verify that tha callingPackage belongs to the calling UID |
| 8734 | mApp.getSystemService(AppOpsManager.class) |
| 8735 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8736 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8737 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8738 | try { |
| 8739 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8740 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8741 | } catch (SecurityException e) { |
| 8742 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8743 | // has carrier privileges on an active UICC |
| 8744 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8745 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8746 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8747 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8748 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8749 | |
| 8750 | final long identity = Binder.clearCallingIdentity(); |
| 8751 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8752 | UiccController uiccController = UiccController.getInstance(); |
| 8753 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8754 | if (hasReadPermission) { |
| 8755 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8756 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8757 | |
| 8758 | // Remove private info if the caller doesn't have access |
| 8759 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8760 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8761 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8762 | // is available |
| 8763 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8764 | // TODO remove card.getUiccPortList().length once MEP API refactoring CL is merged |
| 8765 | // Get UiccPortInfo from CardInfo and process further based on each UiccPort |
| 8766 | if (card == null || card.getUiccPortList().length == 0) { |
| 8767 | // assume no access if the card or ports are unavailable |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8768 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8769 | continue; |
| 8770 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8771 | |
| 8772 | if (haveCarrierPrivilegeAccess(card, callingPackage)) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8773 | filteredInfos.add(cardInfo); |
| 8774 | } else { |
| 8775 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8776 | } |
| 8777 | } |
| 8778 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8779 | } finally { |
| 8780 | Binder.restoreCallingIdentity(identity); |
| 8781 | } |
| 8782 | } |
| 8783 | |
| 8784 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8785 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8786 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8787 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8788 | final long identity = Binder.clearCallingIdentity(); |
| 8789 | try { |
| 8790 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8791 | if (slots == null) { |
| 8792 | Rlog.i(LOG_TAG, "slots is null."); |
| 8793 | return null; |
| 8794 | } |
| 8795 | |
| 8796 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8797 | for (int i = 0; i < slots.length; i++) { |
| 8798 | UiccSlot slot = slots[i]; |
| 8799 | if (slot == null) { |
| 8800 | continue; |
| 8801 | } |
| 8802 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8803 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8804 | UiccCard card = slot.getUiccCard(); |
| 8805 | if (card != null) { |
| 8806 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8807 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8808 | cardId = slot.getEid(); |
| 8809 | if (TextUtils.isEmpty(cardId)) { |
| 8810 | cardId = slot.getIccId(); |
| 8811 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8812 | } |
| 8813 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8814 | if (cardId != null) { |
| 8815 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8816 | // if cardId is an EID, it's all digits so this is fine |
| 8817 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8818 | } |
| 8819 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8820 | int cardState = 0; |
| 8821 | switch (slot.getCardState()) { |
| 8822 | case CARDSTATE_ABSENT: |
| 8823 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8824 | break; |
| 8825 | case CARDSTATE_PRESENT: |
| 8826 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8827 | break; |
| 8828 | case CARDSTATE_ERROR: |
| 8829 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8830 | break; |
| 8831 | case CARDSTATE_RESTRICTED: |
| 8832 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8833 | break; |
| 8834 | default: |
| 8835 | break; |
| 8836 | |
| 8837 | } |
| 8838 | |
| 8839 | infos[i] = new UiccSlotInfo( |
| 8840 | slot.isActive(), |
| 8841 | slot.isEuicc(), |
| 8842 | cardId, |
| 8843 | cardState, |
| 8844 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8845 | slot.isExtendedApduSupported(), |
| 8846 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8847 | } |
| 8848 | return infos; |
| 8849 | } finally { |
| 8850 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8851 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8852 | } |
| 8853 | |
| 8854 | @Override |
| 8855 | public boolean switchSlots(int[] physicalSlots) { |
| 8856 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8857 | |
| 8858 | final long identity = Binder.clearCallingIdentity(); |
| 8859 | try { |
| 8860 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8861 | } finally { |
| 8862 | Binder.restoreCallingIdentity(identity); |
| 8863 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8864 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8865 | |
| 8866 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8867 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8868 | final long identity = Binder.clearCallingIdentity(); |
| 8869 | try { |
| 8870 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8871 | } finally { |
| 8872 | Binder.restoreCallingIdentity(identity); |
| 8873 | } |
| 8874 | } |
| 8875 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8876 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8877 | * A test API to reload the UICC profile. |
| 8878 | * |
| 8879 | * <p>Requires that the calling app has permission |
| 8880 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8881 | * @hide |
| 8882 | */ |
| 8883 | @Override |
| 8884 | public void refreshUiccProfile(int subId) { |
| 8885 | enforceModifyPermission(); |
| 8886 | |
| 8887 | final long identity = Binder.clearCallingIdentity(); |
| 8888 | try { |
| 8889 | Phone phone = getPhone(subId); |
| 8890 | if (phone == null) { |
| 8891 | return; |
| 8892 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8893 | UiccPort uiccPort = phone.getUiccPort(); |
| 8894 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8895 | return; |
| 8896 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8897 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8898 | if (uiccProfile == null) { |
| 8899 | return; |
| 8900 | } |
| 8901 | uiccProfile.refresh(); |
| 8902 | } finally { |
| 8903 | Binder.restoreCallingIdentity(identity); |
| 8904 | } |
| 8905 | } |
| 8906 | |
| 8907 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8908 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8909 | */ |
| 8910 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8911 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8912 | } |
| 8913 | |
| 8914 | /** |
| 8915 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8916 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8917 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8918 | */ |
| 8919 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8920 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8921 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8922 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8923 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8924 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8925 | return isDataRoamingEnabled; |
| 8926 | } |
| 8927 | |
| 8928 | /** |
| 8929 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8930 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8931 | */ |
| 8932 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8933 | List<Integer> list = TelephonyProperties.default_network(); |
| 8934 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8935 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8936 | return list.get(phoneId); |
| 8937 | } |
| 8938 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8939 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8940 | |
| 8941 | @Override |
| 8942 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8943 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8944 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8945 | |
| 8946 | final long identity = Binder.clearCallingIdentity(); |
| 8947 | try { |
| 8948 | final Phone phone = getPhone(subId); |
| 8949 | if (phone == null) { |
| 8950 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8951 | return; |
| 8952 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8953 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8954 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8955 | if (carrierPrivilegeRules == null) { |
| 8956 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8957 | } else { |
| 8958 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8959 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8960 | } finally { |
| 8961 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8962 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8963 | } |
| 8964 | |
| 8965 | @Override |
| 8966 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8967 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8968 | |
| 8969 | final long identity = Binder.clearCallingIdentity(); |
| 8970 | try { |
| 8971 | final Phone phone = getPhone(subId); |
| 8972 | if (phone == null) { |
| 8973 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8974 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8975 | } |
| 8976 | return phone.getCarrierIdListVersion(); |
| 8977 | } finally { |
| 8978 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8979 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8980 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8981 | |
| 8982 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8983 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8984 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8985 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8986 | mApp, subId, callingPackage, callingFeatureId, |
| 8987 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8988 | return -1; |
| 8989 | } |
| 8990 | |
| 8991 | final long identity = Binder.clearCallingIdentity(); |
| 8992 | try { |
| 8993 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8994 | } finally { |
| 8995 | Binder.restoreCallingIdentity(identity); |
| 8996 | } |
| 8997 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8998 | |
| 8999 | @Override |
| 9000 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9001 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9002 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9003 | mApp, subId, "getCdmaRoamingMode"); |
| 9004 | |
| 9005 | final long identity = Binder.clearCallingIdentity(); |
| 9006 | try { |
| 9007 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9008 | } finally { |
| 9009 | Binder.restoreCallingIdentity(identity); |
| 9010 | } |
| 9011 | } |
| 9012 | |
| 9013 | @Override |
| 9014 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9015 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9016 | mApp, subId, "setCdmaRoamingMode"); |
| 9017 | |
| 9018 | final long identity = Binder.clearCallingIdentity(); |
| 9019 | try { |
| 9020 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9021 | } finally { |
| 9022 | Binder.restoreCallingIdentity(identity); |
| 9023 | } |
| 9024 | } |
| 9025 | |
| 9026 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9027 | public int getCdmaSubscriptionMode(int subId) { |
| 9028 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9029 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9030 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9031 | |
| 9032 | final long identity = Binder.clearCallingIdentity(); |
| 9033 | try { |
| 9034 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9035 | } finally { |
| 9036 | Binder.restoreCallingIdentity(identity); |
| 9037 | } |
| 9038 | } |
| 9039 | |
| 9040 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9041 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9042 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9043 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9044 | |
| 9045 | final long identity = Binder.clearCallingIdentity(); |
| 9046 | try { |
| 9047 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9048 | } finally { |
| 9049 | Binder.restoreCallingIdentity(identity); |
| 9050 | } |
| 9051 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9052 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9053 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9054 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9055 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9056 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9057 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9058 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9059 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9060 | } |
| 9061 | final long identity = Binder.clearCallingIdentity(); |
| 9062 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9063 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9064 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9065 | if (phone.getEmergencyNumberTracker() != null |
| 9066 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9067 | emergencyNumberListInternal.put( |
| 9068 | phone.getSubId(), |
| 9069 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9070 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9071 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9072 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9073 | } finally { |
| 9074 | Binder.restoreCallingIdentity(identity); |
| 9075 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9076 | } |
| 9077 | |
| 9078 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9079 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9080 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9081 | if (!exactMatch) { |
| 9082 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9083 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9084 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9085 | } |
| 9086 | final long identity = Binder.clearCallingIdentity(); |
| 9087 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9088 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9089 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9090 | && phone.getEmergencyNumberTracker() |
| 9091 | .isEmergencyNumber(number, exactMatch)) { |
| 9092 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9093 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9094 | } |
| 9095 | return false; |
| 9096 | } finally { |
| 9097 | Binder.restoreCallingIdentity(identity); |
| 9098 | } |
| 9099 | } |
| 9100 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9101 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9102 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9103 | */ |
| 9104 | @Override |
| 9105 | public void startEmergencyCallbackMode() { |
| 9106 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9107 | "startEmergencyCallbackMode"); |
| 9108 | enforceModifyPermission(); |
| 9109 | final long identity = Binder.clearCallingIdentity(); |
| 9110 | try { |
| 9111 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9112 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9113 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9114 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9115 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9116 | gsmCdmaPhone.obtainMessage( |
| 9117 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9118 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9119 | } |
| 9120 | } |
| 9121 | } finally { |
| 9122 | Binder.restoreCallingIdentity(identity); |
| 9123 | } |
| 9124 | } |
| 9125 | |
| 9126 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9127 | * Update emergency number list for test mode. |
| 9128 | */ |
| 9129 | @Override |
| 9130 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9131 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9132 | "updateEmergencyNumberListTestMode"); |
| 9133 | |
| 9134 | final long identity = Binder.clearCallingIdentity(); |
| 9135 | try { |
| 9136 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9137 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9138 | if (tracker != null) { |
| 9139 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9140 | } |
| 9141 | } |
| 9142 | } finally { |
| 9143 | Binder.restoreCallingIdentity(identity); |
| 9144 | } |
| 9145 | } |
| 9146 | |
| 9147 | /** |
| 9148 | * Get the full emergency number list for test mode. |
| 9149 | */ |
| 9150 | @Override |
| 9151 | public List<String> getEmergencyNumberListTestMode() { |
| 9152 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9153 | "getEmergencyNumberListTestMode"); |
| 9154 | |
| 9155 | final long identity = Binder.clearCallingIdentity(); |
| 9156 | try { |
| 9157 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9158 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9159 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9160 | if (tracker != null) { |
| 9161 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9162 | emergencyNumbers.add(num.getNumber()); |
| 9163 | } |
| 9164 | } |
| 9165 | } |
| 9166 | return new ArrayList<>(emergencyNumbers); |
| 9167 | } finally { |
| 9168 | Binder.restoreCallingIdentity(identity); |
| 9169 | } |
| 9170 | } |
| 9171 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9172 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9173 | public int getEmergencyNumberDbVersion(int subId) { |
| 9174 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9175 | |
| 9176 | final long identity = Binder.clearCallingIdentity(); |
| 9177 | try { |
| 9178 | final Phone phone = getPhone(subId); |
| 9179 | if (phone == null) { |
| 9180 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9181 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9182 | } |
| 9183 | return phone.getEmergencyNumberDbVersion(); |
| 9184 | } finally { |
| 9185 | Binder.restoreCallingIdentity(identity); |
| 9186 | } |
| 9187 | } |
| 9188 | |
| 9189 | @Override |
| 9190 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9191 | enforceModifyPermission(); |
| 9192 | |
| 9193 | final long identity = Binder.clearCallingIdentity(); |
| 9194 | try { |
| 9195 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9196 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9197 | if (tracker != null) { |
| 9198 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9199 | } |
| 9200 | } |
| 9201 | } finally { |
| 9202 | Binder.restoreCallingIdentity(identity); |
| 9203 | } |
| 9204 | } |
| 9205 | |
| 9206 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9207 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9208 | enforceActiveEmergencySessionPermission(); |
| 9209 | |
| 9210 | final long identity = Binder.clearCallingIdentity(); |
| 9211 | try { |
| 9212 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9213 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9214 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9215 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9216 | } |
| 9217 | } |
| 9218 | } finally { |
| 9219 | Binder.restoreCallingIdentity(identity); |
| 9220 | } |
| 9221 | } |
| 9222 | |
| 9223 | @Override |
| 9224 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9225 | enforceActiveEmergencySessionPermission(); |
| 9226 | |
| 9227 | final long identity = Binder.clearCallingIdentity(); |
| 9228 | try { |
| 9229 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9230 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9231 | if (tracker != null) { |
| 9232 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9233 | } |
| 9234 | } |
| 9235 | } finally { |
| 9236 | Binder.restoreCallingIdentity(identity); |
| 9237 | } |
| 9238 | } |
| 9239 | |
| 9240 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9241 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9242 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9243 | Phone phone = getPhone(subId); |
| 9244 | if (phone == null) { |
| 9245 | return null; |
| 9246 | } |
| 9247 | final long identity = Binder.clearCallingIdentity(); |
| 9248 | try { |
| 9249 | UiccProfile profile = UiccController.getInstance() |
| 9250 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9251 | if (profile != null) { |
| 9252 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9253 | } |
| 9254 | } finally { |
| 9255 | Binder.restoreCallingIdentity(identity); |
| 9256 | } |
| 9257 | return null; |
| 9258 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9259 | |
| 9260 | /** |
| 9261 | * Enable or disable a modem stack. |
| 9262 | */ |
| 9263 | @Override |
| 9264 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9265 | enforceModifyPermission(); |
| 9266 | |
| 9267 | final long identity = Binder.clearCallingIdentity(); |
| 9268 | try { |
| 9269 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9270 | if (phone == null) { |
| 9271 | return false; |
| 9272 | } else { |
| 9273 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9274 | } |
| 9275 | } finally { |
| 9276 | Binder.restoreCallingIdentity(identity); |
| 9277 | } |
| 9278 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9279 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9280 | /** |
| 9281 | * Whether a modem stack is enabled or not. |
| 9282 | */ |
| 9283 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9284 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9285 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9286 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9287 | if (phone == null) return false; |
| 9288 | |
| 9289 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9290 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9291 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9292 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9293 | } |
| 9294 | |
| 9295 | final long identity = Binder.clearCallingIdentity(); |
| 9296 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9297 | try { |
| 9298 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9299 | } catch (NoSuchElementException ex) { |
| 9300 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9301 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9302 | } finally { |
| 9303 | Binder.restoreCallingIdentity(identity); |
| 9304 | } |
| 9305 | } |
| 9306 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9307 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9308 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9309 | enforceModifyPermission(); |
| 9310 | |
| 9311 | final long identity = Binder.clearCallingIdentity(); |
| 9312 | try { |
| 9313 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9314 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9315 | .commit(); |
| 9316 | } finally { |
| 9317 | Binder.restoreCallingIdentity(identity); |
| 9318 | } |
| 9319 | } |
| 9320 | |
| 9321 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9322 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9323 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9324 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9325 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9326 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9327 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9328 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9329 | |
| 9330 | final long identity = Binder.clearCallingIdentity(); |
| 9331 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9332 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9333 | } finally { |
| 9334 | Binder.restoreCallingIdentity(identity); |
| 9335 | } |
| 9336 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9337 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9338 | @TelephonyManager.IsMultiSimSupportedResult |
| 9339 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9340 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9341 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9342 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9343 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9344 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9345 | } |
| 9346 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9347 | // supported by the modem, indicate that it is restricted. |
| 9348 | PhoneCapability staticCapability = |
| 9349 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9350 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9351 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9352 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9353 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9354 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9355 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9356 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9357 | } |
| 9358 | // Check if support of multiple SIMs is restricted by carrier |
| 9359 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9360 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9361 | } |
| 9362 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9363 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9364 | } |
| 9365 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9366 | /** |
| 9367 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9368 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9369 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9370 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9371 | * @param numOfSims number of active sims we want to switch to |
| 9372 | */ |
| 9373 | @Override |
| 9374 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9375 | if (numOfSims == 1) { |
| 9376 | enforceModifyPermission(); |
| 9377 | } else { |
| 9378 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9379 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9380 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9381 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9382 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9383 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9384 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9385 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9386 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9387 | return; |
| 9388 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9389 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9390 | } finally { |
| 9391 | Binder.restoreCallingIdentity(identity); |
| 9392 | } |
| 9393 | } |
| 9394 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9395 | @Override |
| 9396 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9397 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9398 | Phone phone = getPhone(subId); |
| 9399 | if (phone == null) { |
| 9400 | return false; |
| 9401 | } |
| 9402 | final long identity = Binder.clearCallingIdentity(); |
| 9403 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9404 | UiccPort uiccPort = phone.getUiccPort(); |
| 9405 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9406 | return false; |
| 9407 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9408 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9409 | if (uiccProfile == null) { |
| 9410 | return false; |
| 9411 | } |
| 9412 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9413 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9414 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9415 | } |
| 9416 | return false; |
| 9417 | } finally { |
| 9418 | Binder.restoreCallingIdentity(identity); |
| 9419 | } |
| 9420 | } |
| 9421 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9422 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9423 | * Get whether making changes to modem configurations will trigger reboot. |
| 9424 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9425 | */ |
| 9426 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9427 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9428 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9429 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9430 | mApp, subId, callingPackage, callingFeatureId, |
| 9431 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9432 | return false; |
| 9433 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9434 | final long identity = Binder.clearCallingIdentity(); |
| 9435 | try { |
| 9436 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9437 | } finally { |
| 9438 | Binder.restoreCallingIdentity(identity); |
| 9439 | } |
| 9440 | } |
| 9441 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9442 | private void updateModemStateMetrics() { |
| 9443 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9444 | // TODO: check the state for each modem if the api is ready. |
| 9445 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9446 | } |
| 9447 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9448 | @Override |
| 9449 | public int[] getSlotsMapping() { |
| 9450 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 9451 | |
| 9452 | final long identity = Binder.clearCallingIdentity(); |
| 9453 | try { |
| 9454 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 9455 | // All logical slots should have a mapping to a physical slot. |
| 9456 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 9457 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 9458 | for (int i = 0; i < slotInfos.length; i++) { |
| 9459 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 9460 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 9461 | } |
| 9462 | } |
| 9463 | return logicalSlotsMapping; |
| 9464 | } finally { |
| 9465 | Binder.restoreCallingIdentity(identity); |
| 9466 | } |
| 9467 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9468 | |
| 9469 | /** |
| 9470 | * Get the IRadio HAL Version |
| 9471 | */ |
| 9472 | @Override |
| 9473 | public int getRadioHalVersion() { |
| 9474 | Phone phone = getDefaultPhone(); |
| 9475 | if (phone == null) return -1; |
| 9476 | HalVersion hv = phone.getHalVersion(); |
| 9477 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9478 | return hv.major * 100 + hv.minor; |
| 9479 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9480 | |
| 9481 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9482 | * Get the current calling package name. |
| 9483 | * @return the current calling package name |
| 9484 | */ |
| 9485 | @Override |
| 9486 | public String getCurrentPackageName() { |
| 9487 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9488 | } |
| 9489 | |
| 9490 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9491 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9492 | * corresponding network requests on a subId. |
| 9493 | * |
| 9494 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9495 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9496 | * 2) APN is un-metered for this subscription, or |
| 9497 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9498 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9499 | * |
| 9500 | * @return whether data is allowed for a apn type. |
| 9501 | * |
| 9502 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9503 | */ |
| 9504 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9505 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9506 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9507 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9508 | |
| 9509 | // Now that all security checks passes, perform the operation as ourselves. |
| 9510 | final long identity = Binder.clearCallingIdentity(); |
| 9511 | try { |
| 9512 | Phone phone = getPhone(subId); |
| 9513 | if (phone == null) return false; |
| 9514 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9515 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9516 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9517 | } finally { |
| 9518 | Binder.restoreCallingIdentity(identity); |
| 9519 | } |
| 9520 | } |
| 9521 | |
| 9522 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9523 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9524 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9525 | |
| 9526 | // Now that all security checks passes, perform the operation as ourselves. |
| 9527 | final long identity = Binder.clearCallingIdentity(); |
| 9528 | try { |
| 9529 | Phone phone = getPhone(subId); |
| 9530 | if (phone == null) return true; // By default return true. |
| 9531 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9532 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9533 | } finally { |
| 9534 | Binder.restoreCallingIdentity(identity); |
| 9535 | } |
| 9536 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9537 | |
| 9538 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9539 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9540 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9541 | enforceModifyPermission(); |
| 9542 | long token = Binder.clearCallingIdentity(); |
| 9543 | try { |
| 9544 | Phone phone = getPhone(subscriptionId); |
| 9545 | if (phone == null) { |
| 9546 | try { |
| 9547 | if (resultCallback != null) { |
| 9548 | resultCallback.accept(false); |
| 9549 | } |
| 9550 | } catch (RemoteException e) { |
| 9551 | // ignore |
| 9552 | } |
| 9553 | return; |
| 9554 | } |
| 9555 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9556 | Pair.create(specifiers, (x) -> { |
| 9557 | try { |
| 9558 | if (resultCallback != null) { |
| 9559 | resultCallback.accept(x); |
| 9560 | } |
| 9561 | } catch (RemoteException e) { |
| 9562 | // ignore |
| 9563 | } |
| 9564 | }); |
| 9565 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9566 | } finally { |
| 9567 | Binder.restoreCallingIdentity(token); |
| 9568 | } |
| 9569 | } |
| 9570 | |
| 9571 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9572 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9573 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9574 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9575 | mApp, subId, "getSystemSelectionChannels"); |
| 9576 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9577 | final long identity = Binder.clearCallingIdentity(); |
| 9578 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 9579 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 9580 | if (result instanceof IllegalStateException) { |
| 9581 | throw (IllegalStateException) result; |
| 9582 | } |
| 9583 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9584 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9585 | return specifiers; |
| 9586 | } finally { |
| 9587 | Binder.restoreCallingIdentity(identity); |
| 9588 | } |
| 9589 | } |
| 9590 | |
| 9591 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9592 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9593 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9594 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9595 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9596 | if (iccRecords == null) { |
| 9597 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9598 | return false; |
| 9599 | } |
| 9600 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9601 | } |
| 9602 | |
| 9603 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9604 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9605 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9606 | if (callingPackage == null) { |
| 9607 | callingPackage = getCurrentPackageName(); |
| 9608 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9609 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9610 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9611 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9612 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9613 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9614 | } |
| 9615 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9616 | Intent intent = new Intent(); |
| 9617 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9618 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9619 | // Bring up choose default SMS subscription dialog right now |
| 9620 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9621 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9622 | mApp.startActivity(intent); |
| 9623 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9624 | |
| 9625 | @Override |
| 9626 | public String getMmsUAProfUrl(int subId) { |
| 9627 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9628 | final long identity = Binder.clearCallingIdentity(); |
| 9629 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9630 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9631 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9632 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9633 | return carrierUAProfUrl; |
| 9634 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9635 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9636 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9637 | } finally { |
| 9638 | Binder.restoreCallingIdentity(identity); |
| 9639 | } |
| 9640 | } |
| 9641 | |
| 9642 | @Override |
| 9643 | public String getMmsUserAgent(int subId) { |
| 9644 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9645 | final long identity = Binder.clearCallingIdentity(); |
| 9646 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9647 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9648 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9649 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9650 | return carrierUserAgent; |
| 9651 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9652 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9653 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9654 | } finally { |
| 9655 | Binder.restoreCallingIdentity(identity); |
| 9656 | } |
| 9657 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9658 | |
| 9659 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9660 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9661 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9662 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9663 | final long identity = Binder.clearCallingIdentity(); |
| 9664 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9665 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9666 | if (phone == null) return false; |
| 9667 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9668 | switch (policy) { |
| 9669 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9670 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9671 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9672 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9673 | default: |
| 9674 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9675 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9676 | } finally { |
| 9677 | Binder.restoreCallingIdentity(identity); |
| 9678 | } |
| 9679 | } |
| 9680 | |
| 9681 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9682 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9683 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9684 | enforceModifyPermission(); |
| 9685 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9686 | final long identity = Binder.clearCallingIdentity(); |
| 9687 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9688 | Phone phone = getPhone(subscriptionId); |
| 9689 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9690 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9691 | switch (policy) { |
| 9692 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9693 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9694 | break; |
| 9695 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9696 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9697 | break; |
| 9698 | default: |
| 9699 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9700 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9701 | } finally { |
| 9702 | Binder.restoreCallingIdentity(identity); |
| 9703 | } |
| 9704 | } |
| 9705 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9706 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9707 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9708 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9709 | * otherwise. |
| 9710 | */ |
| 9711 | @Override |
| 9712 | public void setCepEnabled(boolean isCepEnabled) { |
| 9713 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9714 | |
| 9715 | final long identity = Binder.clearCallingIdentity(); |
| 9716 | try { |
| 9717 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9718 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9719 | Phone defaultPhone = phone.getImsPhone(); |
| 9720 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9721 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9722 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9723 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9724 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9725 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9726 | + imsPhone.getMsisdn()); |
| 9727 | } |
| 9728 | } |
| 9729 | } finally { |
| 9730 | Binder.restoreCallingIdentity(identity); |
| 9731 | } |
| 9732 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9733 | |
| 9734 | /** |
| 9735 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9736 | * |
| 9737 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9738 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9739 | * before being read. |
| 9740 | */ |
| 9741 | @Override |
| 9742 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9743 | isCompressed) { |
| 9744 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9745 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9746 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9747 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9748 | } |
| 9749 | if (!isImsAvailableOnDevice()) { |
| 9750 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9751 | "IMS not available on device."); |
| 9752 | } |
| 9753 | |
| 9754 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9755 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9756 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9757 | } finally { |
| 9758 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9759 | } |
| 9760 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9761 | |
| 9762 | @Override |
| 9763 | public boolean isIccLockEnabled(int subId) { |
| 9764 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9765 | |
| 9766 | // Now that all security checks passes, perform the operation as ourselves. |
| 9767 | final long identity = Binder.clearCallingIdentity(); |
| 9768 | try { |
| 9769 | Phone phone = getPhone(subId); |
| 9770 | if (phone != null && phone.getIccCard() != null) { |
| 9771 | return phone.getIccCard().getIccLockEnabled(); |
| 9772 | } else { |
| 9773 | return false; |
| 9774 | } |
| 9775 | } finally { |
| 9776 | Binder.restoreCallingIdentity(identity); |
| 9777 | } |
| 9778 | } |
| 9779 | |
| 9780 | /** |
| 9781 | * Set the ICC pin lock enabled or disabled. |
| 9782 | * |
| 9783 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9784 | * three cases: |
| 9785 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9786 | * successfully. |
| 9787 | * - Positive number and zero for remaining password attempts. |
| 9788 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9789 | * |
| 9790 | */ |
| 9791 | @Override |
| 9792 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9793 | enforceModifyPermission(); |
| 9794 | |
| 9795 | Phone phone = getPhone(subId); |
| 9796 | if (phone == null) { |
| 9797 | return 0; |
| 9798 | } |
| 9799 | // Now that all security checks passes, perform the operation as ourselves. |
| 9800 | final long identity = Binder.clearCallingIdentity(); |
| 9801 | try { |
| 9802 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9803 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9804 | return attemptsRemaining; |
| 9805 | |
| 9806 | } catch (Exception e) { |
| 9807 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9808 | } finally { |
| 9809 | Binder.restoreCallingIdentity(identity); |
| 9810 | } |
| 9811 | return 0; |
| 9812 | } |
| 9813 | |
| 9814 | /** |
| 9815 | * Change the ICC password used in ICC pin lock. |
| 9816 | * |
| 9817 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9818 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9819 | * - Positive number and zero for remaining password attempts. |
| 9820 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9821 | * |
| 9822 | */ |
| 9823 | @Override |
| 9824 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9825 | enforceModifyPermission(); |
| 9826 | |
| 9827 | Phone phone = getPhone(subId); |
| 9828 | if (phone == null) { |
| 9829 | return 0; |
| 9830 | } |
| 9831 | // Now that all security checks passes, perform the operation as ourselves. |
| 9832 | final long identity = Binder.clearCallingIdentity(); |
| 9833 | try { |
| 9834 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9835 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9836 | return attemptsRemaining; |
| 9837 | |
| 9838 | } catch (Exception e) { |
| 9839 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9840 | } finally { |
| 9841 | Binder.restoreCallingIdentity(identity); |
| 9842 | } |
| 9843 | return 0; |
| 9844 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9845 | |
| 9846 | /** |
| 9847 | * Request for receiving user activity notification |
| 9848 | */ |
| 9849 | @Override |
| 9850 | public void requestUserActivityNotification() { |
| 9851 | if (!mNotifyUserActivity.get() |
| 9852 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9853 | mNotifyUserActivity.set(true); |
| 9854 | } |
| 9855 | } |
| 9856 | |
| 9857 | /** |
| 9858 | * Called when userActivity is signalled in the power manager. |
| 9859 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9860 | */ |
| 9861 | @Override |
| 9862 | public void userActivity() { |
| 9863 | // *************************************** |
| 9864 | // * Inherited from PhoneWindowManager * |
| 9865 | // *************************************** |
| 9866 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9867 | // WITH ITS LOCKS HELD. |
| 9868 | // |
| 9869 | // This code must be VERY careful about the locks |
| 9870 | // it acquires. |
| 9871 | // In fact, the current code acquires way too many, |
| 9872 | // and probably has lurking deadlocks. |
| 9873 | |
| 9874 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9875 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9876 | } |
| 9877 | |
| 9878 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9879 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9880 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9881 | } |
| 9882 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9883 | |
| 9884 | @Override |
| 9885 | public boolean canConnectTo5GInDsdsMode() { |
| 9886 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9887 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9888 | |
| 9889 | @Override |
| 9890 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9891 | String callingFeatureId) { |
| 9892 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9893 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9894 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9895 | } |
| 9896 | |
| 9897 | Phone phone = getPhone(subId); |
| 9898 | if (phone == null) { |
| 9899 | throw new RuntimeException("phone is not available"); |
| 9900 | } |
| 9901 | // Now that all security checks passes, perform the operation as ourselves. |
| 9902 | final long identity = Binder.clearCallingIdentity(); |
| 9903 | try { |
| 9904 | return phone.getEquivalentHomePlmns(); |
| 9905 | } finally { |
| 9906 | Binder.restoreCallingIdentity(identity); |
| 9907 | } |
| 9908 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9909 | |
| 9910 | @Override |
| 9911 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 9912 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 9913 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 9914 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9915 | if (radioInterfaceCapabilities == null) { |
| 9916 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9917 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 9918 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9919 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9920 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9921 | @Override |
| 9922 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9923 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9924 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 9925 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9926 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 9927 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9928 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9929 | if (DBG) { |
| 9930 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9931 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9932 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9933 | } |
| 9934 | |
| 9935 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9936 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9937 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9938 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9939 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9940 | if (callback != null) { |
| 9941 | try { |
| 9942 | callback.onAuthenticationFailure( |
| 9943 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9944 | } catch (RemoteException exception) { |
| 9945 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9946 | } |
| 9947 | return; |
| 9948 | } |
| 9949 | } |
| 9950 | |
| 9951 | final long token = Binder.clearCallingIdentity(); |
| 9952 | try { |
| 9953 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9954 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9955 | forceBootStrapping, callback)); |
| 9956 | } finally { |
| 9957 | Binder.restoreCallingIdentity(token); |
| 9958 | } |
| 9959 | } |
| 9960 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9961 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 9962 | * Attempts to set the radio power state for all phones for thermal reason. |
| 9963 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9964 | * requested radio power state will actually be set. See {@link |
| 9965 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9966 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9967 | * @param enable {@code true} if trying to turn radio on. |
| 9968 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9969 | * false}. |
| 9970 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 9971 | private boolean setRadioPowerForThermal(boolean enable) { |
| 9972 | boolean isPhoneAvailable = false; |
| 9973 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 9974 | Phone phone = PhoneFactory.getPhone(i); |
| 9975 | if (phone != null) { |
| 9976 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9977 | isPhoneAvailable = true; |
| 9978 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9979 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 9980 | |
| 9981 | // return true if successfully informed the phone object about the thermal radio power |
| 9982 | // request. |
| 9983 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9984 | } |
| 9985 | |
| 9986 | private int handleDataThrottlingRequest(int subId, |
| 9987 | DataThrottlingRequest dataThrottlingRequest) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 9988 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 9989 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 9990 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 9991 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 9992 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 9993 | } |
| 9994 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9995 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9996 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 9997 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9998 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9999 | } |
| 10000 | |
| 10001 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 10002 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10003 | if (isDataThrottlingSupported) { |
| 10004 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10005 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10006 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10007 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10008 | } else if (thermalMitigationResult |
| 10009 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10010 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10011 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10012 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10013 | } |
| 10014 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10015 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10016 | |
| 10017 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10018 | } |
| 10019 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10020 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10021 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10022 | for (String pckg : context.getResources() |
| 10023 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10024 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10025 | } |
| 10026 | } |
| 10027 | |
| 10028 | return sThermalMitigationAllowlistedPackages; |
| 10029 | } |
| 10030 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10031 | private boolean isAnyPhoneInEmergencyState() { |
| 10032 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10033 | if (tm.isInEmergencyCall()) { |
| 10034 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10035 | return true; |
| 10036 | } |
| 10037 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10038 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10039 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10040 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10041 | + phone.isInEcm()); |
| 10042 | return true; |
| 10043 | } |
| 10044 | } |
| 10045 | |
| 10046 | return false; |
| 10047 | } |
| 10048 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10049 | /** |
| 10050 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10051 | * @param packageName name of package to be allowlisted |
| 10052 | * @param context |
| 10053 | */ |
| 10054 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10055 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10056 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10057 | } |
| 10058 | |
| 10059 | /** |
| 10060 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10061 | * @param packageName name of package to remove from allowlist |
| 10062 | * @param context |
| 10063 | */ |
| 10064 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10065 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10066 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10067 | } |
| 10068 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10069 | /** |
| 10070 | * Thermal mitigation request to control functionalities at modem. |
| 10071 | * |
| 10072 | * @param subId the id of the subscription. |
| 10073 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10074 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10075 | * |
| 10076 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10077 | */ |
| 10078 | @Override |
| 10079 | @ThermalMitigationResult |
| 10080 | public int sendThermalMitigationRequest( |
| 10081 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10082 | ThermalMitigationRequest thermalMitigationRequest, |
| 10083 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10084 | enforceModifyPermission(); |
| 10085 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10086 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10087 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10088 | .contains(callingPackage)) { |
| 10089 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10090 | + "calling package: " + callingPackage); |
| 10091 | } |
| 10092 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10093 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10094 | final long identity = Binder.clearCallingIdentity(); |
| 10095 | |
| 10096 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10097 | try { |
| 10098 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10099 | switch (thermalMitigationAction) { |
| 10100 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10101 | thermalMitigationResult = |
| 10102 | handleDataThrottlingRequest(subId, |
| 10103 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 10104 | break; |
| 10105 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10106 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10107 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10108 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10109 | } |
| 10110 | |
| 10111 | // Ensure that radio is on. If not able to power on due to phone being |
| 10112 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10113 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10114 | thermalMitigationResult = |
| 10115 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10116 | break; |
| 10117 | } |
| 10118 | |
| 10119 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 10120 | false); |
| 10121 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10122 | break; |
| 10123 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10124 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10125 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10126 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10127 | } |
| 10128 | |
| 10129 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10130 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10131 | Phone phone = getPhone(subId); |
| 10132 | if (phone == null) { |
| 10133 | thermalMitigationResult = |
| 10134 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10135 | break; |
| 10136 | } |
| 10137 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10138 | TelephonyConnectionService service = |
| 10139 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10140 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10141 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10142 | thermalMitigationResult = |
| 10143 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10144 | break; |
| 10145 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10146 | thermalMitigationResult = |
| 10147 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10148 | break; |
| 10149 | } |
| 10150 | } else { |
| 10151 | thermalMitigationResult = |
| 10152 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10153 | break; |
| 10154 | } |
| 10155 | |
| 10156 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10157 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10158 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10159 | thermalMitigationResult = |
| 10160 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10161 | break; |
| 10162 | } |
| 10163 | thermalMitigationResult = |
| 10164 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10165 | break; |
| 10166 | default: |
| 10167 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10168 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10169 | } |
| 10170 | } catch (IllegalArgumentException e) { |
| 10171 | throw e; |
| 10172 | } catch (Exception e) { |
| 10173 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10174 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10175 | } finally { |
| 10176 | Binder.restoreCallingIdentity(identity); |
| 10177 | } |
| 10178 | |
| 10179 | if (DBG) { |
| 10180 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10181 | + thermalMitigationResult); |
| 10182 | } |
| 10183 | |
| 10184 | return thermalMitigationResult; |
| 10185 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10186 | |
| 10187 | /** |
| 10188 | * Set the GbaService Package Name that Telephony will bind to. |
| 10189 | * |
| 10190 | * @param subId The sim that the GbaService is associated with. |
| 10191 | * @param packageName The name of the package to be replaced with. |
| 10192 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10193 | */ |
| 10194 | @Override |
| 10195 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10196 | enforceModifyPermission(); |
| 10197 | |
| 10198 | final long identity = Binder.clearCallingIdentity(); |
| 10199 | try { |
| 10200 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10201 | } finally { |
| 10202 | Binder.restoreCallingIdentity(identity); |
| 10203 | } |
| 10204 | } |
| 10205 | |
| 10206 | /** |
| 10207 | * Return the package name of the currently bound GbaService. |
| 10208 | * |
| 10209 | * @param subId The sim that the GbaService is associated with. |
| 10210 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10211 | */ |
| 10212 | @Override |
| 10213 | public String getBoundGbaService(int subId) { |
| 10214 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10215 | |
| 10216 | final long identity = Binder.clearCallingIdentity(); |
| 10217 | try { |
| 10218 | return getGbaManager(subId).getServicePackage(); |
| 10219 | } finally { |
| 10220 | Binder.restoreCallingIdentity(identity); |
| 10221 | } |
| 10222 | } |
| 10223 | |
| 10224 | /** |
| 10225 | * Set the release time for telephony to unbind GbaService. |
| 10226 | * |
| 10227 | * @param subId The sim that the GbaService is associated with. |
| 10228 | * @param interval The release time to unbind GbaService by millisecond. |
| 10229 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10230 | */ |
| 10231 | @Override |
| 10232 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10233 | enforceModifyPermission(); |
| 10234 | |
| 10235 | final long identity = Binder.clearCallingIdentity(); |
| 10236 | try { |
| 10237 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10238 | } finally { |
| 10239 | Binder.restoreCallingIdentity(identity); |
| 10240 | } |
| 10241 | } |
| 10242 | |
| 10243 | /** |
| 10244 | * Return the release time for telephony to unbind GbaService. |
| 10245 | * |
| 10246 | * @param subId The sim that the GbaService is associated with. |
| 10247 | * @return The release time to unbind GbaService by millisecond. |
| 10248 | */ |
| 10249 | @Override |
| 10250 | public int getGbaReleaseTime(int subId) { |
| 10251 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10252 | |
| 10253 | final long identity = Binder.clearCallingIdentity(); |
| 10254 | try { |
| 10255 | return getGbaManager(subId).getReleaseTime(); |
| 10256 | } finally { |
| 10257 | Binder.restoreCallingIdentity(identity); |
| 10258 | } |
| 10259 | } |
| 10260 | |
| 10261 | private GbaManager getGbaManager(int subId) { |
| 10262 | GbaManager instance = GbaManager.getInstance(subId); |
| 10263 | if (instance == null) { |
| 10264 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10265 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10266 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10267 | } |
| 10268 | return instance; |
| 10269 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10270 | |
| 10271 | /** |
| 10272 | * indicate whether the device and the carrier can support |
| 10273 | * RCS VoLTE single registration. |
| 10274 | */ |
| 10275 | @Override |
| 10276 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10277 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10278 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10279 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10280 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10281 | |
| 10282 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10283 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10284 | } |
| 10285 | |
| 10286 | final long identity = Binder.clearCallingIdentity(); |
| 10287 | try { |
| 10288 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10289 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10290 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10291 | if (isCapable != null) { |
| 10292 | return isCapable; |
| 10293 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10294 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10295 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10296 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10297 | } finally { |
| 10298 | Binder.restoreCallingIdentity(identity); |
| 10299 | } |
| 10300 | } |
| 10301 | |
| 10302 | /** |
| 10303 | * Register RCS provisioning callback. |
| 10304 | */ |
| 10305 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10306 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10307 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10308 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10309 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10310 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10311 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10312 | |
| 10313 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10314 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10315 | } |
| 10316 | if (!isImsAvailableOnDevice()) { |
| 10317 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10318 | "IMS not available on device."); |
| 10319 | } |
| 10320 | |
| 10321 | final long identity = Binder.clearCallingIdentity(); |
| 10322 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10323 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10324 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10325 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10326 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10327 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10328 | } finally { |
| 10329 | Binder.restoreCallingIdentity(identity); |
| 10330 | } |
| 10331 | } |
| 10332 | |
| 10333 | /** |
| 10334 | * Unregister RCS provisioning callback. |
| 10335 | */ |
| 10336 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10337 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10338 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10339 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10340 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10341 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10342 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10343 | |
| 10344 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10345 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10346 | } |
| 10347 | if (!isImsAvailableOnDevice()) { |
| 10348 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10349 | "IMS not available on device."); |
| 10350 | } |
| 10351 | |
| 10352 | final long identity = Binder.clearCallingIdentity(); |
| 10353 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10354 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10355 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10356 | } finally { |
| 10357 | Binder.restoreCallingIdentity(identity); |
| 10358 | } |
| 10359 | } |
| 10360 | |
| 10361 | /** |
| 10362 | * trigger RCS reconfiguration. |
| 10363 | */ |
| 10364 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10365 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10366 | "triggerRcsReconfiguration", |
| 10367 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10368 | |
| 10369 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10370 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10371 | } |
| 10372 | if (!isImsAvailableOnDevice()) { |
| 10373 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10374 | "IMS not available on device."); |
| 10375 | } |
| 10376 | |
| 10377 | final long identity = Binder.clearCallingIdentity(); |
| 10378 | try { |
| 10379 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10380 | } finally { |
| 10381 | Binder.restoreCallingIdentity(identity); |
| 10382 | } |
| 10383 | } |
| 10384 | |
| 10385 | /** |
| 10386 | * Provide the client configuration parameters of the RCS application. |
| 10387 | */ |
| 10388 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10389 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10390 | "setRcsClientConfiguration", |
| 10391 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10392 | |
| 10393 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10394 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10395 | } |
| 10396 | if (!isImsAvailableOnDevice()) { |
| 10397 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10398 | "IMS not available on device."); |
| 10399 | } |
| 10400 | |
| 10401 | final long identity = Binder.clearCallingIdentity(); |
| 10402 | |
| 10403 | try { |
| 10404 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10405 | if (configBinder == null) { |
| 10406 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10407 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10408 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10409 | } else { |
| 10410 | configBinder.setRcsClientConfiguration(rcc); |
| 10411 | } |
| 10412 | } catch (RemoteException e) { |
| 10413 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10414 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10415 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10416 | } finally { |
| 10417 | Binder.restoreCallingIdentity(identity); |
| 10418 | } |
| 10419 | } |
| 10420 | |
| 10421 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10422 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10423 | */ |
| 10424 | @Override |
| 10425 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10426 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10427 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10428 | |
| 10429 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10430 | } |
| 10431 | |
| 10432 | /** |
| 10433 | * Gets the test mode for RCS VoLTE single registration. |
| 10434 | */ |
| 10435 | @Override |
| 10436 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10437 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10438 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10439 | |
| 10440 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10441 | } |
| 10442 | |
| 10443 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10444 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10445 | */ |
| 10446 | @Override |
| 10447 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10448 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10449 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10450 | enforceModifyPermission(); |
| 10451 | |
| 10452 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10453 | : Boolean.parseBoolean(enabledStr); |
| 10454 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10455 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10456 | } |
| 10457 | |
| 10458 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10459 | * Sends a device to device communication message. Only usable via shell. |
| 10460 | * @param message message to send. |
| 10461 | * @param value message value. |
| 10462 | */ |
| 10463 | @Override |
| 10464 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10465 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10466 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10467 | enforceModifyPermission(); |
| 10468 | |
| 10469 | final long identity = Binder.clearCallingIdentity(); |
| 10470 | try { |
| 10471 | TelephonyConnectionService service = |
| 10472 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10473 | if (service == null) { |
| 10474 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10475 | return; |
| 10476 | } |
| 10477 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10478 | } finally { |
| 10479 | Binder.restoreCallingIdentity(identity); |
| 10480 | } |
| 10481 | } |
| 10482 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10483 | /** |
| 10484 | * Sets the specified device to device transport active. |
| 10485 | * @param transport The transport to set active. |
| 10486 | */ |
| 10487 | @Override |
| 10488 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10489 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10490 | "setActiveDeviceToDeviceTransport"); |
| 10491 | enforceModifyPermission(); |
| 10492 | |
| 10493 | final long identity = Binder.clearCallingIdentity(); |
| 10494 | try { |
| 10495 | TelephonyConnectionService service = |
| 10496 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10497 | if (service == null) { |
| 10498 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10499 | return; |
| 10500 | } |
| 10501 | service.setActiveDeviceToDeviceTransport(transport); |
| 10502 | } finally { |
| 10503 | Binder.restoreCallingIdentity(identity); |
| 10504 | } |
| 10505 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10506 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10507 | @Override |
| 10508 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10509 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10510 | "setDeviceToDeviceForceEnabled"); |
| 10511 | |
| 10512 | final long identity = Binder.clearCallingIdentity(); |
| 10513 | try { |
| 10514 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10515 | p -> { |
| 10516 | Phone thePhone = p.getImsPhone(); |
| 10517 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10518 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10519 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10520 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10521 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10522 | (ImsPhoneCallTracker) tracker; |
| 10523 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10524 | } |
| 10525 | } |
| 10526 | } |
| 10527 | ); |
| 10528 | } finally { |
| 10529 | Binder.restoreCallingIdentity(identity); |
| 10530 | } |
| 10531 | } |
| 10532 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10533 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10534 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10535 | */ |
| 10536 | @Override |
| 10537 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10538 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10539 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10540 | } |
| 10541 | |
| 10542 | /** |
| 10543 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10544 | */ |
| 10545 | @Override |
| 10546 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10547 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10548 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10549 | enforceModifyPermission(); |
| 10550 | |
| 10551 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10552 | : Boolean.parseBoolean(enabledStr); |
| 10553 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10554 | subId, enabled); |
| 10555 | } |
| 10556 | |
| 10557 | /** |
| 10558 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10559 | */ |
| 10560 | @Override |
| 10561 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10562 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10563 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10564 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10565 | |
| 10566 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 10567 | * Overrides the ims feature validation result |
| 10568 | */ |
| 10569 | @Override |
| 10570 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 10571 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10572 | "setImsFeatureValidationOverride"); |
| 10573 | |
| 10574 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10575 | : Boolean.parseBoolean(enabledStr); |
| 10576 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 10577 | subId, enabled); |
| 10578 | } |
| 10579 | |
| 10580 | /** |
| 10581 | * Gets the ims feature validation override value |
| 10582 | */ |
| 10583 | @Override |
| 10584 | public boolean getImsFeatureValidationOverride(int subId) { |
| 10585 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10586 | "getImsFeatureValidationOverride"); |
| 10587 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 10588 | } |
| 10589 | |
| 10590 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10591 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10592 | * their mobile plan. |
| 10593 | */ |
| 10594 | @Override |
| 10595 | public String getMobileProvisioningUrl() { |
| 10596 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10597 | final long identity = Binder.clearCallingIdentity(); |
| 10598 | try { |
| 10599 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10600 | } finally { |
| 10601 | Binder.restoreCallingIdentity(identity); |
| 10602 | } |
| 10603 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10604 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10605 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10606 | * Get the EAB contact from the EAB database. |
| 10607 | */ |
| 10608 | @Override |
| 10609 | public String getContactFromEab(String contact) { |
| 10610 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10611 | enforceModifyPermission(); |
| 10612 | final long identity = Binder.clearCallingIdentity(); |
| 10613 | try { |
| 10614 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10615 | } finally { |
| 10616 | Binder.restoreCallingIdentity(identity); |
| 10617 | } |
| 10618 | } |
| 10619 | |
| 10620 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 10621 | * Get the EAB capability from the EAB database. |
| 10622 | */ |
| 10623 | @Override |
| 10624 | public String getCapabilityFromEab(String contact) { |
| 10625 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 10626 | enforceModifyPermission(); |
| 10627 | final long identity = Binder.clearCallingIdentity(); |
| 10628 | try { |
| 10629 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 10630 | } finally { |
| 10631 | Binder.restoreCallingIdentity(identity); |
| 10632 | } |
| 10633 | } |
| 10634 | |
| 10635 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10636 | * Remove the EAB contacts from the EAB database. |
| 10637 | */ |
| 10638 | @Override |
| 10639 | public int removeContactFromEab(int subId, String contacts) { |
| 10640 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10641 | enforceModifyPermission(); |
| 10642 | final long identity = Binder.clearCallingIdentity(); |
| 10643 | try { |
| 10644 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10645 | } finally { |
| 10646 | Binder.restoreCallingIdentity(identity); |
| 10647 | } |
| 10648 | } |
| 10649 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10650 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10651 | public boolean getDeviceUceEnabled() { |
| 10652 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10653 | final long identity = Binder.clearCallingIdentity(); |
| 10654 | try { |
| 10655 | return mApp.getDeviceUceEnabled(); |
| 10656 | } finally { |
| 10657 | Binder.restoreCallingIdentity(identity); |
| 10658 | } |
| 10659 | } |
| 10660 | |
| 10661 | @Override |
| 10662 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10663 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10664 | final long identity = Binder.clearCallingIdentity(); |
| 10665 | try { |
| 10666 | mApp.setDeviceUceEnabled(isEnabled); |
| 10667 | } finally { |
| 10668 | Binder.restoreCallingIdentity(identity); |
| 10669 | } |
| 10670 | } |
| 10671 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10672 | /** |
| 10673 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10674 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10675 | */ |
| 10676 | // Used for SHELL command only right now. |
| 10677 | @Override |
| 10678 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 10679 | List<String> featureTags) { |
| 10680 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10681 | "addUceRegistrationOverrideShell"); |
| 10682 | final long identity = Binder.clearCallingIdentity(); |
| 10683 | try { |
| 10684 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 10685 | new ArraySet<>(featureTags)); |
| 10686 | } catch (ImsException e) { |
| 10687 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10688 | } finally { |
| 10689 | Binder.restoreCallingIdentity(identity); |
| 10690 | } |
| 10691 | } |
| 10692 | |
| 10693 | /** |
| 10694 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10695 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10696 | */ |
| 10697 | // Used for SHELL command only right now. |
| 10698 | @Override |
| 10699 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 10700 | List<String> featureTags) { |
| 10701 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10702 | "removeUceRegistrationOverrideShell"); |
| 10703 | final long identity = Binder.clearCallingIdentity(); |
| 10704 | try { |
| 10705 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 10706 | new ArraySet<>(featureTags)); |
| 10707 | } catch (ImsException e) { |
| 10708 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10709 | } finally { |
| 10710 | Binder.restoreCallingIdentity(identity); |
| 10711 | } |
| 10712 | } |
| 10713 | |
| 10714 | /** |
| 10715 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 10716 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10717 | */ |
| 10718 | // Used for SHELL command only right now. |
| 10719 | @Override |
| 10720 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 10721 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10722 | "clearUceRegistrationOverrideShell"); |
| 10723 | final long identity = Binder.clearCallingIdentity(); |
| 10724 | try { |
| 10725 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 10726 | } catch (ImsException e) { |
| 10727 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10728 | } finally { |
| 10729 | Binder.restoreCallingIdentity(identity); |
| 10730 | } |
| 10731 | } |
| 10732 | |
| 10733 | /** |
| 10734 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10735 | */ |
| 10736 | // Used for SHELL command only right now. |
| 10737 | @Override |
| 10738 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 10739 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10740 | "getLatestRcsContactUceCapabilityShell"); |
| 10741 | final long identity = Binder.clearCallingIdentity(); |
| 10742 | try { |
| 10743 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 10744 | } catch (ImsException e) { |
| 10745 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10746 | } finally { |
| 10747 | Binder.restoreCallingIdentity(identity); |
| 10748 | } |
| 10749 | } |
| 10750 | |
| 10751 | /** |
| 10752 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 10753 | * device does not have an active PUBLISH. |
| 10754 | */ |
| 10755 | // Used for SHELL command only right now. |
| 10756 | @Override |
| 10757 | public String getLastUcePidfXmlShell(int subId) { |
| 10758 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 10759 | final long identity = Binder.clearCallingIdentity(); |
| 10760 | try { |
| 10761 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 10762 | } catch (ImsException e) { |
| 10763 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10764 | } finally { |
| 10765 | Binder.restoreCallingIdentity(identity); |
| 10766 | } |
| 10767 | } |
| 10768 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 10769 | /** |
| 10770 | * Remove UCE requests cannot be sent to the network status. |
| 10771 | */ |
| 10772 | // Used for SHELL command only right now. |
| 10773 | @Override |
| 10774 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 10775 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 10776 | final long identity = Binder.clearCallingIdentity(); |
| 10777 | try { |
| 10778 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 10779 | } catch (ImsException e) { |
| 10780 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10781 | } finally { |
| 10782 | Binder.restoreCallingIdentity(identity); |
| 10783 | } |
| 10784 | } |
| 10785 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 10786 | /** |
| 10787 | * Remove UCE requests cannot be sent to the network status. |
| 10788 | */ |
| 10789 | // Used for SHELL command only. |
| 10790 | @Override |
| 10791 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 10792 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 10793 | final long identity = Binder.clearCallingIdentity(); |
| 10794 | try { |
| 10795 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 10796 | } catch (ImsException e) { |
| 10797 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10798 | } finally { |
| 10799 | Binder.restoreCallingIdentity(identity); |
| 10800 | } |
| 10801 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10802 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10803 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10804 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10805 | String callingPackage) { |
| 10806 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10807 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 10808 | |
| 10809 | final int callingUid = Binder.getCallingUid(); |
| 10810 | // Verify that tha callingPackage belongs to the calling UID |
| 10811 | mApp.getSystemService(AppOpsManager.class) |
| 10812 | .checkPackage(callingUid, callingPackage); |
| 10813 | |
| 10814 | validateSignalStrengthUpdateRequest(request, callingUid); |
| 10815 | |
| 10816 | final long identity = Binder.clearCallingIdentity(); |
| 10817 | try { |
| 10818 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10819 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10820 | |
| 10821 | if (result instanceof IllegalStateException) { |
| 10822 | throw (IllegalStateException) result; |
| 10823 | } |
| 10824 | } finally { |
| 10825 | Binder.restoreCallingIdentity(identity); |
| 10826 | } |
| 10827 | } |
| 10828 | |
| 10829 | @Override |
| 10830 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10831 | String callingPackage) { |
| 10832 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10833 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 10834 | |
| 10835 | final int callingUid = Binder.getCallingUid(); |
| 10836 | // Verify that tha callingPackage belongs to the calling UID |
| 10837 | mApp.getSystemService(AppOpsManager.class) |
| 10838 | .checkPackage(callingUid, callingPackage); |
| 10839 | |
| 10840 | final long identity = Binder.clearCallingIdentity(); |
| 10841 | try { |
| 10842 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10843 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10844 | |
| 10845 | if (result instanceof IllegalStateException) { |
| 10846 | throw (IllegalStateException) result; |
| 10847 | } |
| 10848 | } finally { |
| 10849 | Binder.restoreCallingIdentity(identity); |
| 10850 | } |
| 10851 | } |
| 10852 | |
| 10853 | private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request, |
| 10854 | int callingUid) { |
| 10855 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 10856 | // phone/system process do not have further restriction on request |
| 10857 | return; |
| 10858 | } |
| 10859 | |
| 10860 | // Applications has restrictions on how to use the request: |
| 10861 | // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle |
| 10862 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
| 10863 | // This is not system caller which has been checked above |
| 10864 | throw new IllegalArgumentException( |
| 10865 | "Only system can set isSystemThresholdReportingRequestedWhileIdle"); |
| 10866 | } |
| 10867 | |
| 10868 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 10869 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 10870 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 10871 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 10872 | || info.isEnabled()) { |
| 10873 | throw new IllegalArgumentException( |
| 10874 | "Only system can set hide fields in SignalThresholdInfo"); |
| 10875 | } |
| 10876 | |
| 10877 | // Thresholds length for each RAN need in range. This has been validated in |
| 10878 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 10879 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 10880 | final int[] thresholds = info.getThresholds(); |
| 10881 | Objects.requireNonNull(thresholds); |
| 10882 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 10883 | || thresholds.length |
| 10884 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 10885 | throw new IllegalArgumentException( |
| 10886 | "thresholds length is out of range: " + thresholds.length); |
| 10887 | } |
| 10888 | } |
| 10889 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10890 | |
| 10891 | /** |
| 10892 | * Gets the current phone capability. |
| 10893 | * |
| 10894 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 10895 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 10896 | * It's used to evaluate possible phone config change, for example from single |
| 10897 | * SIM device to multi-SIM device. |
| 10898 | */ |
| 10899 | @Override |
| 10900 | public PhoneCapability getPhoneCapability() { |
| 10901 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 10902 | final long identity = Binder.clearCallingIdentity(); |
| 10903 | try { |
| 10904 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 10905 | } finally { |
| 10906 | Binder.restoreCallingIdentity(identity); |
| 10907 | } |
| 10908 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 10909 | |
| 10910 | /** |
| 10911 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 10912 | * required to be done shortly after the API is invoked. |
| 10913 | */ |
| 10914 | @Override |
| 10915 | @TelephonyManager.PrepareUnattendedRebootResult |
| 10916 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 10917 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 10918 | enforceRebootPermission(); |
| 10919 | |
| 10920 | final long identity = Binder.clearCallingIdentity(); |
| 10921 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 10922 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 10923 | } finally { |
| 10924 | Binder.restoreCallingIdentity(identity); |
| 10925 | } |
| 10926 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 10927 | |
| 10928 | /** |
| 10929 | * Request to get the current slicing configuration including URSP rules and |
| 10930 | * NSSAIs (configured, allowed and rejected). |
| 10931 | * |
| 10932 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 10933 | */ |
| 10934 | @Override |
| 10935 | public void getSlicingConfig(ResultReceiver callback) { |
| 10936 | enforceReadPrivilegedPermission("getSlicingConfig"); |
| 10937 | |
| 10938 | final long identity = Binder.clearCallingIdentity(); |
| 10939 | try { |
| 10940 | Phone phone = getDefaultPhone(); |
| 10941 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 10942 | } finally { |
| 10943 | Binder.restoreCallingIdentity(identity); |
| 10944 | } |
| 10945 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 10946 | } |