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) { |
| 5527 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5528 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5529 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5530 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5531 | } |
| 5532 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5533 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5534 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5535 | } |
| 5536 | if (fplmns == null) { |
| 5537 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5538 | } |
| 5539 | for (String fplmn : fplmns) { |
| 5540 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5541 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5542 | } |
| 5543 | } |
| 5544 | final long identity = Binder.clearCallingIdentity(); |
| 5545 | try { |
| 5546 | Object response = sendRequest( |
| 5547 | CMD_SET_FORBIDDEN_PLMNS, |
| 5548 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5549 | subId); |
| 5550 | return (int) response; |
| 5551 | } finally { |
| 5552 | Binder.restoreCallingIdentity(identity); |
| 5553 | } |
| 5554 | } |
| 5555 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5556 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5557 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5558 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5559 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5560 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5561 | final long identity = Binder.clearCallingIdentity(); |
| 5562 | try { |
| 5563 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5564 | if (response.payload == null) { |
| 5565 | return ""; |
| 5566 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5567 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5568 | // Append the returned status code to the end of the response payload. |
| 5569 | String s = Integer.toHexString( |
| 5570 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5571 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5572 | return s; |
| 5573 | } finally { |
| 5574 | Binder.restoreCallingIdentity(identity); |
| 5575 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5576 | } |
| 5577 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5578 | /** |
| 5579 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5580 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5581 | * |
| 5582 | * @param itemID the ID of the item to read |
| 5583 | * @return the NV item as a String, or null on error. |
| 5584 | */ |
| 5585 | @Override |
| 5586 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5587 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5588 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5589 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5590 | |
| 5591 | final long identity = Binder.clearCallingIdentity(); |
| 5592 | try { |
| 5593 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5594 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5595 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5596 | return value; |
| 5597 | } finally { |
| 5598 | Binder.restoreCallingIdentity(identity); |
| 5599 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5600 | } |
| 5601 | |
| 5602 | /** |
| 5603 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5604 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5605 | * |
| 5606 | * @param itemID the ID of the item to read |
| 5607 | * @param itemValue the value to write, as a String |
| 5608 | * @return true on success; false on any failure |
| 5609 | */ |
| 5610 | @Override |
| 5611 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5612 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5613 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5614 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5615 | |
| 5616 | final long identity = Binder.clearCallingIdentity(); |
| 5617 | try { |
| 5618 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5619 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5620 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5621 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5622 | return success; |
| 5623 | } finally { |
| 5624 | Binder.restoreCallingIdentity(identity); |
| 5625 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5626 | } |
| 5627 | |
| 5628 | /** |
| 5629 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5630 | * Used for device configuration by some CDMA operators. |
| 5631 | * |
| 5632 | * @param preferredRoamingList byte array containing the new PRL |
| 5633 | * @return true on success; false on any failure |
| 5634 | */ |
| 5635 | @Override |
| 5636 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5637 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5638 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5639 | |
| 5640 | final long identity = Binder.clearCallingIdentity(); |
| 5641 | try { |
| 5642 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5643 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5644 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5645 | return success; |
| 5646 | } finally { |
| 5647 | Binder.restoreCallingIdentity(identity); |
| 5648 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5649 | } |
| 5650 | |
| 5651 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5652 | * Rollback modem configurations to factory default except some config which are in whitelist. |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5653 | * Used for device configuration by some CDMA operators. |
| 5654 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5655 | * @param slotIndex - device slot. |
| 5656 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5657 | * @return true on success; false on any failure |
| 5658 | */ |
| 5659 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5660 | public boolean resetModemConfig(int slotIndex) { |
| 5661 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5662 | if (phone != null) { |
| 5663 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5664 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5665 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5666 | final long identity = Binder.clearCallingIdentity(); |
| 5667 | try { |
| 5668 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5669 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5670 | return success; |
| 5671 | } finally { |
| 5672 | Binder.restoreCallingIdentity(identity); |
| 5673 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5674 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5675 | return false; |
| 5676 | } |
| 5677 | |
| 5678 | /** |
| 5679 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5680 | * |
| 5681 | * @param slotIndex - device slot. |
| 5682 | * |
| 5683 | * @return true on success; false on any failure |
| 5684 | */ |
| 5685 | @Override |
| 5686 | public boolean rebootModem(int slotIndex) { |
| 5687 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5688 | if (phone != null) { |
| 5689 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5690 | mApp, phone.getSubId(), "rebootModem"); |
| 5691 | |
| 5692 | final long identity = Binder.clearCallingIdentity(); |
| 5693 | try { |
| 5694 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5695 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5696 | return success; |
| 5697 | } finally { |
| 5698 | Binder.restoreCallingIdentity(identity); |
| 5699 | } |
| 5700 | } |
| 5701 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5702 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5703 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5704 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5705 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5706 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5707 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5708 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5709 | return new String[0]; |
| 5710 | } |
| 5711 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5712 | final long identity = Binder.clearCallingIdentity(); |
| 5713 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5714 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5715 | } finally { |
| 5716 | Binder.restoreCallingIdentity(identity); |
| 5717 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5718 | } |
| 5719 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5720 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5721 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5722 | * {@link #disableIms(int)}. |
| 5723 | * @param slotIndex device slot. |
| 5724 | */ |
| 5725 | public void resetIms(int slotIndex) { |
| 5726 | enforceModifyPermission(); |
| 5727 | |
| 5728 | final long identity = Binder.clearCallingIdentity(); |
| 5729 | try { |
| 5730 | if (mImsResolver == null) { |
| 5731 | // may happen if the does not support IMS. |
| 5732 | return; |
| 5733 | } |
| 5734 | mImsResolver.disableIms(slotIndex); |
| 5735 | mImsResolver.enableIms(slotIndex); |
| 5736 | } finally { |
| 5737 | Binder.restoreCallingIdentity(identity); |
| 5738 | } |
| 5739 | } |
| 5740 | |
| 5741 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5742 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5743 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5744 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5745 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5746 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5747 | |
| 5748 | final long identity = Binder.clearCallingIdentity(); |
| 5749 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5750 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5751 | // may happen if the device does not support IMS. |
| 5752 | return; |
| 5753 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5754 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5755 | } finally { |
| 5756 | Binder.restoreCallingIdentity(identity); |
| 5757 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5758 | } |
| 5759 | |
| 5760 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5761 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5762 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5763 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5764 | public void disableIms(int slotId) { |
| 5765 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5766 | |
| 5767 | final long identity = Binder.clearCallingIdentity(); |
| 5768 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5769 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5770 | // may happen if the device does not support IMS. |
| 5771 | return; |
| 5772 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5773 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5774 | } finally { |
| 5775 | Binder.restoreCallingIdentity(identity); |
| 5776 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5777 | } |
| 5778 | |
| 5779 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5780 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5781 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5782 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5783 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5784 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5785 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5786 | |
| 5787 | final long identity = Binder.clearCallingIdentity(); |
| 5788 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5789 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5790 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5791 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5792 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5793 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5794 | } finally { |
| 5795 | Binder.restoreCallingIdentity(identity); |
| 5796 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5797 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5798 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5799 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5800 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5801 | @Override |
| 5802 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5803 | enforceModifyPermission(); |
| 5804 | |
| 5805 | final long identity = Binder.clearCallingIdentity(); |
| 5806 | try { |
| 5807 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5808 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5809 | } finally { |
| 5810 | Binder.restoreCallingIdentity(identity); |
| 5811 | } |
| 5812 | } |
| 5813 | |
| 5814 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5815 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5816 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5817 | */ |
| 5818 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5819 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5820 | |
| 5821 | final long identity = Binder.clearCallingIdentity(); |
| 5822 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5823 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5824 | // may happen if the device does not support IMS. |
| 5825 | return null; |
| 5826 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5827 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5828 | } finally { |
| 5829 | Binder.restoreCallingIdentity(identity); |
| 5830 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5831 | } |
| 5832 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5833 | /** |
| 5834 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5835 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5836 | */ |
| 5837 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5838 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5839 | |
| 5840 | final long identity = Binder.clearCallingIdentity(); |
| 5841 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5842 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5843 | // may happen if the device does not support IMS. |
| 5844 | return null; |
| 5845 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5846 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5847 | } finally { |
| 5848 | Binder.restoreCallingIdentity(identity); |
| 5849 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5850 | } |
| 5851 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5852 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5853 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5854 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5855 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5856 | * @param isCarrierService true if the ImsService is the carrier override, false if the |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5857 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5858 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5859 | * @param packageName The name of the package that the current configuration will be replaced |
| 5860 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5861 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5862 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5863 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5864 | int[] featureTypes, String packageName) { |
| 5865 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5866 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5867 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5868 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5869 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5870 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5871 | final long identity = Binder.clearCallingIdentity(); |
| 5872 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5873 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5874 | // may happen if the device does not support IMS. |
| 5875 | return false; |
| 5876 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5877 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5878 | for (int featureType : featureTypes) { |
| 5879 | featureConfig.put(featureType, packageName); |
| 5880 | } |
| 5881 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5882 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5883 | } finally { |
| 5884 | Binder.restoreCallingIdentity(identity); |
| 5885 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5886 | } |
| 5887 | |
| 5888 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5889 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5890 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5891 | * |
| 5892 | * This should only be used for testing. |
| 5893 | * |
| 5894 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5895 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5896 | */ |
| 5897 | @Override |
| 5898 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5899 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5900 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5901 | "clearCarrierImsServiceOverride"); |
| 5902 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5903 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5904 | "clearCarrierImsServiceOverride"); |
| 5905 | |
| 5906 | final long identity = Binder.clearCallingIdentity(); |
| 5907 | try { |
| 5908 | if (mImsResolver == null) { |
| 5909 | // may happen if the device does not support IMS. |
| 5910 | return false; |
| 5911 | } |
| 5912 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5913 | } finally { |
| 5914 | Binder.restoreCallingIdentity(identity); |
| 5915 | } |
| 5916 | } |
| 5917 | |
| 5918 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5919 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5920 | * |
| 5921 | * @param slotId The slot that the ImsService is associated with. |
| 5922 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5923 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5924 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5925 | * @return the package name of the ImsService configuration. |
| 5926 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5927 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5928 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5929 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5930 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5931 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5932 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5933 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5934 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5935 | final long identity = Binder.clearCallingIdentity(); |
| 5936 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5937 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5938 | // may happen if the device does not support IMS. |
| 5939 | return ""; |
| 5940 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5941 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5942 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5943 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5944 | } finally { |
| 5945 | Binder.restoreCallingIdentity(identity); |
| 5946 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5947 | } |
| 5948 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5949 | /** |
| 5950 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5951 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5952 | * @param callback A callback with an integer containing the |
| 5953 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5954 | */ |
| 5955 | @Override |
| 5956 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5957 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5958 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5959 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5960 | "IMS not available on device."); |
| 5961 | } |
| 5962 | final long token = Binder.clearCallingIdentity(); |
| 5963 | try { |
| 5964 | int slotId = getSlotIndex(subId); |
| 5965 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5966 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5967 | + subId + "'"); |
| 5968 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5969 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5970 | verifyImsMmTelConfiguredOrThrow(slotId); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5971 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5972 | try { |
| 5973 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5974 | } catch (RemoteException e) { |
| 5975 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5976 | + "Ignore"); |
| 5977 | } |
| 5978 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5979 | } catch (ImsException e) { |
| 5980 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5981 | } finally { |
| 5982 | Binder.restoreCallingIdentity(token); |
| 5983 | } |
| 5984 | } |
| 5985 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5986 | /** |
| 5987 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5988 | */ |
| 5989 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5990 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5991 | |
| 5992 | final long identity = Binder.clearCallingIdentity(); |
| 5993 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5994 | // NOTE: Before S, this method only set the default phone. |
| 5995 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5996 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5997 | phone.setImsRegistrationState(registered); |
| 5998 | } |
| 5999 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6000 | } finally { |
| 6001 | Binder.restoreCallingIdentity(identity); |
| 6002 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6003 | } |
| 6004 | |
| 6005 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6006 | * Set the network selection mode to automatic. |
| 6007 | * |
| 6008 | */ |
| 6009 | @Override |
| 6010 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6011 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6012 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6013 | |
| 6014 | final long identity = Binder.clearCallingIdentity(); |
| 6015 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6016 | if (!isActiveSubscription(subId)) { |
| 6017 | return; |
| 6018 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6019 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6020 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6021 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6022 | } finally { |
| 6023 | Binder.restoreCallingIdentity(identity); |
| 6024 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6025 | } |
| 6026 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6027 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6028 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6029 | * |
| 6030 | * @param subId the id of the subscription. |
| 6031 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6032 | * the operator to attach to. |
| 6033 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6034 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6035 | * normal network selection next time. |
| 6036 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6037 | */ |
| 6038 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6039 | public boolean setNetworkSelectionModeManual( |
| 6040 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6041 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6042 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6043 | |
| 6044 | if (!isActiveSubscription(subId)) { |
| 6045 | return false; |
| 6046 | } |
| 6047 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6048 | final long identity = Binder.clearCallingIdentity(); |
| 6049 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6050 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6051 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6052 | if (DBG) { |
| 6053 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6054 | + " operator: " + operatorInfo); |
| 6055 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6056 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6057 | } finally { |
| 6058 | Binder.restoreCallingIdentity(identity); |
| 6059 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6060 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6061 | /** |
| 6062 | * Get the manual network selection |
| 6063 | * |
| 6064 | * @param subId the id of the subscription. |
| 6065 | * |
| 6066 | * @return the previously saved user selected PLMN |
| 6067 | */ |
| 6068 | @Override |
| 6069 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6070 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6071 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6072 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 6073 | |
| 6074 | final long identity = Binder.clearCallingIdentity(); |
| 6075 | try { |
| 6076 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6077 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6078 | } |
| 6079 | |
| 6080 | final Phone phone = getPhone(subId); |
| 6081 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6082 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6083 | } |
| 6084 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6085 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6086 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6087 | } finally { |
| 6088 | Binder.restoreCallingIdentity(identity); |
| 6089 | } |
| 6090 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6091 | |
| 6092 | /** |
| 6093 | * Scans for available networks. |
| 6094 | */ |
| 6095 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6096 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6097 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6098 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6099 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6100 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6101 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6102 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6103 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6104 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6105 | .setCallingPid(Binder.getCallingPid()) |
| 6106 | .setCallingUid(Binder.getCallingUid()) |
| 6107 | .setMethod("getCellNetworkScanResults") |
| 6108 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6109 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6110 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6111 | .build()); |
| 6112 | switch (locationResult) { |
| 6113 | case DENIED_HARD: |
| 6114 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6115 | case DENIED_SOFT: |
| 6116 | return null; |
| 6117 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6118 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6119 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6120 | try { |
| 6121 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6122 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6123 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6124 | } finally { |
| 6125 | Binder.restoreCallingIdentity(identity); |
| 6126 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6127 | } |
| 6128 | |
| 6129 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6130 | * Get the call forwarding info, given the call forwarding reason. |
| 6131 | */ |
| 6132 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6133 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6134 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6135 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6136 | long identity = Binder.clearCallingIdentity(); |
| 6137 | try { |
| 6138 | if (DBG) { |
| 6139 | log("getCallForwarding: subId " + subId |
| 6140 | + " callForwardingReason" + callForwardingReason); |
| 6141 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6142 | |
| 6143 | Phone phone = getPhone(subId); |
| 6144 | if (phone == null) { |
| 6145 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6146 | callback.onError( |
| 6147 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6148 | } catch (RemoteException e) { |
| 6149 | // ignore |
| 6150 | } |
| 6151 | return; |
| 6152 | } |
| 6153 | |
| 6154 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6155 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6156 | @Override |
| 6157 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6158 | try { |
| 6159 | callback.onCallForwardingInfoAvailable(info); |
| 6160 | } catch (RemoteException e) { |
| 6161 | // ignore |
| 6162 | } |
| 6163 | } |
| 6164 | |
| 6165 | @Override |
| 6166 | public void onError(int error) { |
| 6167 | try { |
| 6168 | callback.onError(error); |
| 6169 | } catch (RemoteException e) { |
| 6170 | // ignore |
| 6171 | } |
| 6172 | } |
| 6173 | }); |
| 6174 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6175 | } finally { |
| 6176 | Binder.restoreCallingIdentity(identity); |
| 6177 | } |
| 6178 | } |
| 6179 | |
| 6180 | /** |
| 6181 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6182 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6183 | */ |
| 6184 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6185 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6186 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6187 | enforceModifyPermission(); |
| 6188 | long identity = Binder.clearCallingIdentity(); |
| 6189 | try { |
| 6190 | if (DBG) { |
| 6191 | log("setCallForwarding: subId " + subId |
| 6192 | + " callForwardingInfo" + callForwardingInfo); |
| 6193 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6194 | |
| 6195 | Phone phone = getPhone(subId); |
| 6196 | if (phone == null) { |
| 6197 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6198 | callback.accept( |
| 6199 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6200 | } catch (RemoteException e) { |
| 6201 | // ignore |
| 6202 | } |
| 6203 | return; |
| 6204 | } |
| 6205 | |
| 6206 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6207 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6208 | |
| 6209 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6210 | } finally { |
| 6211 | Binder.restoreCallingIdentity(identity); |
| 6212 | } |
| 6213 | } |
| 6214 | |
| 6215 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6216 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6217 | */ |
| 6218 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6219 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6220 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6221 | long identity = Binder.clearCallingIdentity(); |
| 6222 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6223 | Phone phone = getPhone(subId); |
| 6224 | if (phone == null) { |
| 6225 | try { |
| 6226 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6227 | } catch (RemoteException e) { |
| 6228 | // ignore |
| 6229 | } |
| 6230 | return; |
| 6231 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6232 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6233 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6234 | boolean requireUssd = c.getBoolean( |
| 6235 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6236 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6237 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6238 | if (requireUssd) { |
| 6239 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6240 | getSubscriptionCarrierId(subId)); |
| 6241 | String newUssdCommand = ""; |
| 6242 | try { |
| 6243 | newUssdCommand = carrierXmlParser.getFeature( |
| 6244 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6245 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6246 | } catch (NullPointerException e) { |
| 6247 | loge("Failed to generate USSD number" + e); |
| 6248 | } |
| 6249 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6250 | mMainThreadHandler, callback, carrierXmlParser, |
| 6251 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6252 | final String ussdCommand = newUssdCommand; |
| 6253 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6254 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6255 | }); |
| 6256 | } else { |
| 6257 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6258 | callback::accept); |
| 6259 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6260 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6261 | } finally { |
| 6262 | Binder.restoreCallingIdentity(identity); |
| 6263 | } |
| 6264 | } |
| 6265 | |
| 6266 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6267 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6268 | */ |
| 6269 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6270 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6271 | enforceModifyPermission(); |
| 6272 | long identity = Binder.clearCallingIdentity(); |
| 6273 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6274 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6275 | |
| 6276 | Phone phone = getPhone(subId); |
| 6277 | if (phone == null) { |
| 6278 | try { |
| 6279 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6280 | } catch (RemoteException e) { |
| 6281 | // ignore |
| 6282 | } |
| 6283 | return; |
| 6284 | } |
| 6285 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6286 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6287 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6288 | boolean requireUssd = c.getBoolean( |
| 6289 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6290 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6291 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6292 | if (requireUssd) { |
| 6293 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6294 | getSubscriptionCarrierId(subId)); |
| 6295 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6296 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6297 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6298 | String newUssdCommand = ""; |
| 6299 | try { |
| 6300 | newUssdCommand = carrierXmlParser.getFeature( |
| 6301 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6302 | .makeCommand(ssAction, null); |
| 6303 | } catch (NullPointerException e) { |
| 6304 | loge("Failed to generate USSD number" + e); |
| 6305 | } |
| 6306 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6307 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6308 | final String ussdCommand = newUssdCommand; |
| 6309 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6310 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6311 | }); |
| 6312 | } else { |
| 6313 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6314 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6315 | |
| 6316 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6317 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6318 | } finally { |
| 6319 | Binder.restoreCallingIdentity(identity); |
| 6320 | } |
| 6321 | } |
| 6322 | |
| 6323 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6324 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6325 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6326 | * @param subId id of the subscription |
| 6327 | * @param request contains the radio access networks with bands/channels to scan |
| 6328 | * @param messenger callback messenger for scan results or errors |
| 6329 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6330 | * @return the id of the requested scan which can be used to stop the scan. |
| 6331 | */ |
| 6332 | @Override |
| 6333 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6334 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6335 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6336 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6337 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6338 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6339 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6340 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6341 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6342 | .setCallingPid(Binder.getCallingPid()) |
| 6343 | .setCallingUid(Binder.getCallingUid()) |
| 6344 | .setMethod("requestNetworkScan") |
| 6345 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
James.cf Lin | 1d4d739 | 2020-07-03 18:22:53 +0800 | [diff] [blame] | 6346 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6347 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6348 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6349 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6350 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6351 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6352 | if (e != null) { |
| 6353 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6354 | throw e; |
| 6355 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6356 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6357 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6358 | } |
| 6359 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6360 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6361 | int callingUid = Binder.getCallingUid(); |
| 6362 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6363 | final long identity = Binder.clearCallingIdentity(); |
| 6364 | try { |
| 6365 | return mNetworkScanRequestTracker.startNetworkScan( |
| 6366 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6367 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6368 | } finally { |
| 6369 | Binder.restoreCallingIdentity(identity); |
| 6370 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6371 | } |
| 6372 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6373 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6374 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6375 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6376 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6377 | boolean hasNetworkScanPermission = |
| 6378 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6379 | == PERMISSION_GRANTED; |
| 6380 | |
| 6381 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6382 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6383 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6384 | } |
| 6385 | |
| 6386 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6387 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6388 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6389 | return new SecurityException("Specific channels must not be" |
| 6390 | + " scanned without location access."); |
| 6391 | } |
| 6392 | } |
| 6393 | } |
| 6394 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6395 | return null; |
| 6396 | } |
| 6397 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6398 | /** |
| 6399 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6400 | * |
| 6401 | * @param subId id of the subscription |
| 6402 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6403 | */ |
| 6404 | @Override |
| 6405 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6406 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6407 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6408 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6409 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6410 | final long identity = Binder.clearCallingIdentity(); |
| 6411 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6412 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6413 | } finally { |
| 6414 | Binder.restoreCallingIdentity(identity); |
| 6415 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6416 | } |
| 6417 | |
| 6418 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6419 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6420 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6421 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6422 | */ |
| 6423 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6424 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6425 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6426 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6427 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6428 | |
| 6429 | final long identity = Binder.clearCallingIdentity(); |
| 6430 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6431 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6432 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6433 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6434 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6435 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6436 | } finally { |
| 6437 | Binder.restoreCallingIdentity(identity); |
| 6438 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6439 | } |
| 6440 | |
| 6441 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6442 | * Get the allowed network types for certain reason. |
| 6443 | * |
| 6444 | * @param subId the id of the subscription. |
| 6445 | * @param reason the reason the allowed network type change is taking place |
| 6446 | * @return the allowed network types. |
| 6447 | */ |
| 6448 | @Override |
| 6449 | public long getAllowedNetworkTypesForReason(int subId, |
| 6450 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6451 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6452 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6453 | final long identity = Binder.clearCallingIdentity(); |
| 6454 | try { |
| 6455 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6456 | } finally { |
| 6457 | Binder.restoreCallingIdentity(identity); |
| 6458 | } |
| 6459 | } |
| 6460 | |
| 6461 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6462 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6463 | * @param subId subscription id of the sim card |
| 6464 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6465 | * This can be passed following states |
| 6466 | * <ol> |
| 6467 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6468 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6469 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6470 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6471 | * </ol> |
| 6472 | * @return operation result. |
| 6473 | */ |
| 6474 | @Override |
| 6475 | public int setNrDualConnectivityState(int subId, |
| 6476 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6477 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6478 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6479 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6480 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6481 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6482 | } |
| 6483 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6484 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6485 | final long identity = Binder.clearCallingIdentity(); |
| 6486 | try { |
| 6487 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6488 | nrDualConnectivityState, subId, |
| 6489 | workSource); |
| 6490 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6491 | return result; |
| 6492 | } finally { |
| 6493 | Binder.restoreCallingIdentity(identity); |
| 6494 | } |
| 6495 | } |
| 6496 | |
| 6497 | /** |
| 6498 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6499 | * @return true if dual connectivity is enabled else false |
| 6500 | */ |
| 6501 | @Override |
| 6502 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6503 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6504 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6505 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6506 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6507 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6508 | return false; |
| 6509 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6510 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6511 | final long identity = Binder.clearCallingIdentity(); |
| 6512 | try { |
| 6513 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6514 | null, subId, workSource); |
| 6515 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6516 | return isEnabled; |
| 6517 | } finally { |
| 6518 | Binder.restoreCallingIdentity(identity); |
| 6519 | } |
| 6520 | } |
| 6521 | |
| 6522 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6523 | * Set the allowed network types of the device and |
| 6524 | * provide the reason triggering the allowed network change. |
| 6525 | * |
| 6526 | * @param subId the id of the subscription. |
| 6527 | * @param reason the reason the allowed network type change is taking place |
| 6528 | * @param allowedNetworkTypes the allowed network types. |
| 6529 | * @return true on success; false on any failure. |
| 6530 | */ |
| 6531 | @Override |
| 6532 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6533 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6534 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6535 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6536 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6537 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6538 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6539 | return false; |
| 6540 | } |
| 6541 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6542 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6543 | return false; |
| 6544 | } |
| 6545 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6546 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6547 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6548 | |
| 6549 | |
| 6550 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6551 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6552 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6553 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6554 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6555 | final long identity = Binder.clearCallingIdentity(); |
| 6556 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6557 | Boolean success = (Boolean) sendRequest( |
| 6558 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6559 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6560 | |
| 6561 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6562 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6563 | } finally { |
| 6564 | Binder.restoreCallingIdentity(identity); |
| 6565 | } |
| 6566 | } |
| 6567 | |
| 6568 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6569 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6570 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6571 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6572 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6573 | * @hide |
| 6574 | */ |
| 6575 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6576 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6577 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6578 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6579 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6580 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6581 | if (phone != null) { |
| 6582 | return phone.hasMatchedTetherApnSetting(); |
| 6583 | } else { |
| 6584 | return false; |
| 6585 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6586 | } finally { |
| 6587 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6588 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6589 | } |
| 6590 | |
| 6591 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6592 | * Enable or disable always reporting signal strength changes from radio. |
| 6593 | * |
| 6594 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6595 | */ |
| 6596 | @Override |
| 6597 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6598 | enforceModifyPermission(); |
| 6599 | enforceSystemCaller(); |
| 6600 | |
| 6601 | final long identity = Binder.clearCallingIdentity(); |
| 6602 | final Phone phone = getPhone(subId); |
| 6603 | try { |
| 6604 | if (phone != null) { |
| 6605 | if (DBG) { |
| 6606 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6607 | + " isEnable=" + isEnable); |
| 6608 | } |
| 6609 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6610 | } else { |
| 6611 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6612 | + subId); |
| 6613 | } |
| 6614 | } finally { |
| 6615 | Binder.restoreCallingIdentity(identity); |
| 6616 | } |
| 6617 | } |
| 6618 | |
| 6619 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6620 | * Get the user enabled state of Mobile Data. |
| 6621 | * |
| 6622 | * TODO: remove and use isUserDataEnabled. |
| 6623 | * This can't be removed now because some vendor codes |
| 6624 | * calls through ITelephony directly while they should |
| 6625 | * use TelephonyManager. |
| 6626 | * |
| 6627 | * @return true on enabled |
| 6628 | */ |
| 6629 | @Override |
| 6630 | public boolean getDataEnabled(int subId) { |
| 6631 | return isUserDataEnabled(subId); |
| 6632 | } |
| 6633 | |
| 6634 | /** |
| 6635 | * Get whether mobile data is enabled per user setting. |
| 6636 | * |
| 6637 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6638 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6639 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6640 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6641 | * |
| 6642 | * @return {@code true} if data is enabled else {@code false} |
| 6643 | */ |
| 6644 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6645 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6646 | try { |
| 6647 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6648 | null); |
| 6649 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6650 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6651 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6652 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6653 | |
| 6654 | final long identity = Binder.clearCallingIdentity(); |
| 6655 | try { |
| 6656 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6657 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6658 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6659 | if (phone != null) { |
| 6660 | boolean retVal = phone.isUserDataEnabled(); |
| 6661 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6662 | return retVal; |
| 6663 | } else { |
| 6664 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6665 | return false; |
| 6666 | } |
| 6667 | } finally { |
| 6668 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6669 | } |
| 6670 | } |
| 6671 | |
| 6672 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6673 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6674 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6675 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6676 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6677 | * @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] | 6678 | */ |
| 6679 | @Override |
| 6680 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6681 | try { |
| 6682 | try { |
| 6683 | mApp.enforceCallingOrSelfPermission( |
| 6684 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6685 | null); |
| 6686 | } catch (Exception e) { |
| 6687 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6688 | "isDataEnabled"); |
| 6689 | } |
| 6690 | } catch (Exception e) { |
| 6691 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6692 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6693 | |
| 6694 | final long identity = Binder.clearCallingIdentity(); |
| 6695 | try { |
| 6696 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6697 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6698 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6699 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6700 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6701 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6702 | return retVal; |
| 6703 | } else { |
| 6704 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6705 | return false; |
| 6706 | } |
| 6707 | } finally { |
| 6708 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6709 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6710 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6711 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6712 | /** |
| 6713 | * Check if data is enabled for a specific reason |
| 6714 | * @param subId Subscription index |
| 6715 | * @param reason the reason the data enable change is taking place |
| 6716 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6717 | */ |
| 6718 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6719 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6720 | @TelephonyManager.DataEnabledReason int reason) { |
| 6721 | try { |
| 6722 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6723 | null); |
| 6724 | } catch (Exception e) { |
| 6725 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6726 | "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6727 | } |
| 6728 | |
| 6729 | |
| 6730 | final long identity = Binder.clearCallingIdentity(); |
| 6731 | try { |
| 6732 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6733 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6734 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6735 | + " reason=" + reason); |
| 6736 | } |
| 6737 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6738 | if (phone != null) { |
| 6739 | boolean retVal; |
| 6740 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6741 | retVal = phone.isUserDataEnabled(); |
| 6742 | } else { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6743 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6744 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6745 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6746 | return retVal; |
| 6747 | } else { |
| 6748 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6749 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6750 | + subId + " retVal=false"); |
| 6751 | } |
| 6752 | return false; |
| 6753 | } |
| 6754 | } finally { |
| 6755 | Binder.restoreCallingIdentity(identity); |
| 6756 | } |
| 6757 | } |
| 6758 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6759 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6760 | Phone phone) { |
Sarah Chin | 3394efe | 2021-04-09 10:37:15 -0700 | [diff] [blame] | 6761 | if (uid == Process.PHONE_UID) { |
| 6762 | // Skip the check if it's the phone UID (system UID removed in b/184713596) |
| 6763 | // 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] | 6764 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6765 | } |
| 6766 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6767 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6768 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6769 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6770 | || subController == null) return privilegeFromSim; |
| 6771 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6772 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6773 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6774 | |
| 6775 | final long identity = Binder.clearCallingIdentity(); |
| 6776 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6777 | int subId = phone.getSubId(); |
| 6778 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6779 | // A test override is in place for the privileges for this subId, so don't try to |
| 6780 | // read the subscription privileges. |
| 6781 | return privilegeFromSim; |
| 6782 | } |
| 6783 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6784 | SubscriptionManager subManager = (SubscriptionManager) |
| 6785 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6786 | for (String pkg : packages) { |
| 6787 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6788 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6789 | } |
| 6790 | } |
| 6791 | return privilegeFromSim; |
| 6792 | } finally { |
| 6793 | Binder.restoreCallingIdentity(identity); |
| 6794 | } |
| 6795 | } |
| 6796 | |
| 6797 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6798 | String pkgName) { |
| 6799 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6800 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6801 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6802 | || subController == null) return privilegeFromSim; |
| 6803 | |
| 6804 | final long identity = Binder.clearCallingIdentity(); |
| 6805 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6806 | int subId = phone.getSubId(); |
| 6807 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6808 | // A test override is in place for the privileges for this subId, so don't try to |
| 6809 | // read the subscription privileges. |
| 6810 | return privilegeFromSim; |
| 6811 | } |
| 6812 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6813 | SubscriptionManager subManager = (SubscriptionManager) |
| 6814 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6815 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6816 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6817 | } finally { |
| 6818 | Binder.restoreCallingIdentity(identity); |
| 6819 | } |
| 6820 | } |
| 6821 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6822 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6823 | public int getCarrierPrivilegeStatus(int subId) { |
| 6824 | final Phone phone = getPhone(subId); |
| 6825 | if (phone == null) { |
| 6826 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6827 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6828 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6829 | UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
| 6830 | if (port == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6831 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6832 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6833 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6834 | |
| 6835 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6836 | port.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6837 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6838 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6839 | |
| 6840 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6841 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6842 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6843 | final Phone phone = getPhone(subId); |
| 6844 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6845 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6846 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6847 | } |
| 6848 | UiccProfile profile = |
| 6849 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6850 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6851 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6852 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6853 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6854 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6855 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6856 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6857 | } |
| 6858 | |
| 6859 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6860 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6861 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6862 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6863 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6864 | } |
| 6865 | |
| 6866 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6867 | UiccPort port = UiccController.getInstance().getUiccPort(phoneId); |
| 6868 | if (port == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6869 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6870 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6871 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6872 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6873 | port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6874 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6875 | } |
| 6876 | |
| 6877 | @Override |
| 6878 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Sarah Chin | fc3169b | 2021-04-28 20:21:03 -0700 | [diff] [blame] | 6879 | // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6880 | if (TextUtils.isEmpty(pkgName)) |
| 6881 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6882 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6883 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6884 | UiccPort port = UiccController.getInstance().getUiccPort(i); |
| 6885 | if (port == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6886 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6887 | continue; |
| 6888 | } |
| 6889 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6890 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6891 | port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6892 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6893 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6894 | break; |
| 6895 | } |
| 6896 | } |
| 6897 | |
| 6898 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6899 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6900 | |
| 6901 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6902 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6903 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6904 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6905 | loge("phoneId " + phoneId + " is not valid."); |
| 6906 | return null; |
| 6907 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6908 | UiccPort port = UiccController.getInstance().getUiccPort(phoneId); |
| 6909 | if (port == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6910 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6911 | return null ; |
| 6912 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6913 | return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6914 | } |
| 6915 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6916 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6917 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6918 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6919 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6920 | List<String> privilegedPackages = new ArrayList<>(); |
| 6921 | List<PackageInfo> packages = null; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6922 | UiccPort port = UiccController.getInstance().getUiccPort(phoneId); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6923 | // has UICC in that slot. |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6924 | if (port != null) { |
| 6925 | if (port.hasCarrierPrivilegeRules()) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6926 | if (packages == null) { |
| 6927 | // Only check packages in user 0 for now |
| 6928 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6929 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6930 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6931 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6932 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6933 | } |
| 6934 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6935 | PackageInfo pkgInfo = packages.get(p); |
| 6936 | if (pkgInfo != null && pkgInfo.packageName != null |
Sooraj Sasindran | 97bce6f | 2021-09-28 21:37:29 +0000 | [diff] [blame] | 6937 | && getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6938 | port.getCarrierPrivilegeStatus(pkgInfo), |
| 6939 | getPhone(phoneId), pkgInfo.packageName) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6940 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6941 | privilegedPackages.add(pkgInfo.packageName); |
| 6942 | } |
| 6943 | } |
| 6944 | } |
| 6945 | } |
| 6946 | return privilegedPackages; |
| 6947 | } |
| 6948 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6949 | @Override |
| 6950 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6951 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6952 | |
| 6953 | final long identity = Binder.clearCallingIdentity(); |
| 6954 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6955 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6956 | try { |
| 6957 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6958 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6959 | } |
| 6960 | } finally { |
| 6961 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6962 | } |
| 6963 | return privilegedPackages; |
| 6964 | } |
| 6965 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6966 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6967 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6968 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 6969 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6970 | return null; |
| 6971 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6972 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6973 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6974 | return null; |
| 6975 | } |
| 6976 | return iccId; |
| 6977 | } |
| 6978 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6979 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6980 | public void setCallComposerStatus(int subId, int status) { |
| 6981 | enforceModifyPermission(); |
| 6982 | |
| 6983 | final long identity = Binder.clearCallingIdentity(); |
| 6984 | try { |
| 6985 | Phone phone = getPhone(subId); |
| 6986 | if (phone != null) { |
| 6987 | Phone defaultPhone = phone.getImsPhone(); |
| 6988 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6989 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6990 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6991 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6992 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6993 | } |
| 6994 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6995 | } catch (ImsException e) { |
| 6996 | throw new ServiceSpecificException(e.getCode()); |
| 6997 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6998 | Binder.restoreCallingIdentity(identity); |
| 6999 | } |
| 7000 | } |
| 7001 | |
| 7002 | @Override |
| 7003 | public int getCallComposerStatus(int subId) { |
| 7004 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7005 | |
| 7006 | final long identity = Binder.clearCallingIdentity(); |
| 7007 | try { |
| 7008 | Phone phone = getPhone(subId); |
| 7009 | if (phone != null) { |
| 7010 | Phone defaultPhone = phone.getImsPhone(); |
| 7011 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7012 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7013 | return imsPhone.getCallComposerStatus(); |
| 7014 | } |
| 7015 | } |
| 7016 | } finally { |
| 7017 | Binder.restoreCallingIdentity(identity); |
| 7018 | } |
| 7019 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7020 | } |
| 7021 | |
| 7022 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7023 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7024 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7025 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7026 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7027 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7028 | final long identity = Binder.clearCallingIdentity(); |
| 7029 | try { |
| 7030 | final String iccId = getIccId(subId); |
| 7031 | final Phone phone = getPhone(subId); |
| 7032 | if (phone == null) { |
| 7033 | return false; |
| 7034 | } |
| 7035 | final String subscriberId = phone.getSubscriberId(); |
| 7036 | |
| 7037 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7038 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7039 | + subscriberId + " to " + number); |
| 7040 | } |
| 7041 | |
| 7042 | if (TextUtils.isEmpty(iccId)) { |
| 7043 | return false; |
| 7044 | } |
| 7045 | |
| 7046 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7047 | |
| 7048 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7049 | if (alphaTag == null) { |
| 7050 | editor.remove(alphaTagPrefKey); |
| 7051 | } else { |
| 7052 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7053 | } |
| 7054 | |
| 7055 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7056 | // track all merged IMSIs based on line number |
| 7057 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7058 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7059 | if (number == null) { |
| 7060 | editor.remove(numberPrefKey); |
| 7061 | editor.remove(subscriberPrefKey); |
| 7062 | } else { |
| 7063 | editor.putString(numberPrefKey, number); |
| 7064 | editor.putString(subscriberPrefKey, subscriberId); |
| 7065 | } |
| 7066 | |
| 7067 | editor.commit(); |
| 7068 | return true; |
| 7069 | } finally { |
| 7070 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7071 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7072 | } |
| 7073 | |
| 7074 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7075 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7076 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7077 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7078 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7079 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7080 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7081 | return null; |
| 7082 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7083 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7084 | final long identity = Binder.clearCallingIdentity(); |
| 7085 | try { |
| 7086 | String iccId = getIccId(subId); |
| 7087 | if (iccId != null) { |
| 7088 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7089 | if (DBG_MERGE) { |
| 7090 | log("getLine1NumberForDisplay returning " |
| 7091 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7092 | } |
| 7093 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7094 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7095 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7096 | return null; |
| 7097 | } finally { |
| 7098 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7099 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7100 | } |
| 7101 | |
| 7102 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7103 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7104 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7105 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7106 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7107 | return null; |
| 7108 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7109 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7110 | final long identity = Binder.clearCallingIdentity(); |
| 7111 | try { |
| 7112 | String iccId = getIccId(subId); |
| 7113 | if (iccId != null) { |
| 7114 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7115 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7116 | } |
| 7117 | return null; |
| 7118 | } finally { |
| 7119 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7120 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7121 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7122 | |
| 7123 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7124 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7125 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7126 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7127 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7128 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7129 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7130 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7131 | return null; |
| 7132 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7133 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7134 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7135 | // the process, where TelephonyManager was instantiated. |
| 7136 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7137 | final long identity = Binder.clearCallingIdentity(); |
| 7138 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7139 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7140 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7141 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7142 | |
| 7143 | // Figure out what subscribers are currently active |
| 7144 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7145 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7146 | // Only consider subs which match the current subId |
| 7147 | // This logic can be simplified. See b/131189269 for progress. |
| 7148 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7149 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7150 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7151 | |
| 7152 | // First pass, find a number override for an active subscriber |
| 7153 | String mergeNumber = null; |
| 7154 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7155 | for (String key : prefs.keySet()) { |
| 7156 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7157 | final String subscriberId = (String) prefs.get(key); |
| 7158 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7159 | final String iccId = key.substring( |
| 7160 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7161 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7162 | mergeNumber = (String) prefs.get(numberKey); |
| 7163 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7164 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7165 | + " for active subscriber " + subscriberId); |
| 7166 | } |
| 7167 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7168 | break; |
| 7169 | } |
| 7170 | } |
| 7171 | } |
| 7172 | } |
| 7173 | |
| 7174 | // Shortcut when no active merged subscribers |
| 7175 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7176 | return null; |
| 7177 | } |
| 7178 | |
| 7179 | // Second pass, find all subscribers under that line override |
| 7180 | final ArraySet<String> result = new ArraySet<>(); |
| 7181 | for (String key : prefs.keySet()) { |
| 7182 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7183 | final String number = (String) prefs.get(key); |
| 7184 | if (mergeNumber.equals(number)) { |
| 7185 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7186 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7187 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7188 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7189 | result.add(subscriberId); |
| 7190 | } |
| 7191 | } |
| 7192 | } |
| 7193 | } |
| 7194 | |
| 7195 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7196 | Arrays.sort(resultArray); |
| 7197 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7198 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7199 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7200 | } |
| 7201 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7202 | } finally { |
| 7203 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7204 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7205 | } |
| 7206 | |
| 7207 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7208 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7209 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7210 | |
| 7211 | final long identity = Binder.clearCallingIdentity(); |
| 7212 | try { |
| 7213 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7214 | TelephonyManager.class); |
| 7215 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7216 | if (subscriberId == null) { |
| 7217 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7218 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7219 | + subId); |
| 7220 | } |
| 7221 | return null; |
| 7222 | } |
| 7223 | |
| 7224 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 7225 | .getSubscriptionInfo(subId); |
| 7226 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 7227 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7228 | if (groupUuid == null) { |
| 7229 | return new String[]{subscriberId}; |
| 7230 | } |
| 7231 | |
| 7232 | // Get all subscriberIds from the group. |
| 7233 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 7234 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7235 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7236 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7237 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7238 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7239 | if (subscriberId != null) { |
| 7240 | mergedSubscriberIds.add(subscriberId); |
| 7241 | } |
| 7242 | } |
| 7243 | |
| 7244 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7245 | } finally { |
| 7246 | Binder.restoreCallingIdentity(identity); |
| 7247 | |
| 7248 | } |
| 7249 | } |
| 7250 | |
| 7251 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7252 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7253 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7254 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7255 | |
| 7256 | final long identity = Binder.clearCallingIdentity(); |
| 7257 | try { |
| 7258 | final Phone phone = getPhone(subId); |
| 7259 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7260 | } finally { |
| 7261 | Binder.restoreCallingIdentity(identity); |
| 7262 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7263 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7264 | |
| 7265 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7266 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7267 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7268 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7269 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7270 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7271 | |
| 7272 | final long identity = Binder.clearCallingIdentity(); |
| 7273 | try { |
| 7274 | final Phone phone = getPhone(subId); |
| 7275 | if (phone == null) { |
| 7276 | return false; |
| 7277 | } |
| 7278 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7279 | cdmaNonRoamingList); |
| 7280 | } finally { |
| 7281 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7282 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7283 | } |
| 7284 | |
| 7285 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7286 | @Deprecated |
| 7287 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7288 | enforceModifyPermission(); |
| 7289 | |
| 7290 | int returnValue = 0; |
| 7291 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7292 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7293 | if(result.exception == null) { |
| 7294 | if (result.result != null) { |
| 7295 | byte[] responseData = (byte[])(result.result); |
| 7296 | if(responseData.length > oemResp.length) { |
| 7297 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7298 | responseData.length + "bytes. Buffer Size is " + |
| 7299 | oemResp.length + "bytes."); |
| 7300 | } |
| 7301 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7302 | returnValue = responseData.length; |
| 7303 | } |
| 7304 | } else { |
| 7305 | CommandException ex = (CommandException) result.exception; |
| 7306 | returnValue = ex.getCommandError().ordinal(); |
| 7307 | if(returnValue > 0) returnValue *= -1; |
| 7308 | } |
| 7309 | } catch (RuntimeException e) { |
| 7310 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7311 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7312 | if(returnValue > 0) returnValue *= -1; |
| 7313 | } |
| 7314 | |
| 7315 | return returnValue; |
| 7316 | } |
| 7317 | |
| 7318 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7319 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7320 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7321 | try { |
| 7322 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7323 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7324 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7325 | } catch (SecurityException e) { |
| 7326 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7327 | throw e; |
| 7328 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7329 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7330 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7331 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7332 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7333 | final long identity = Binder.clearCallingIdentity(); |
| 7334 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7335 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7336 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7337 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7338 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7339 | } finally { |
| 7340 | Binder.restoreCallingIdentity(identity); |
| 7341 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7342 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7343 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7344 | |
| 7345 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7346 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7347 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7348 | try { |
| 7349 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7350 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7351 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7352 | } |
| 7353 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7354 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7355 | } |
| 7356 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7357 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7358 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7359 | throw new SecurityException("App must be the dialer role holder to" |
| 7360 | + " upload a call composer pic"); |
| 7361 | } |
| 7362 | |
| 7363 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7364 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7365 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7366 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7367 | boolean readUntilEnd = false; |
| 7368 | int totalBytesRead = 0; |
| 7369 | byte[] buffer = new byte[16 * 1024]; |
| 7370 | while (true) { |
| 7371 | int numRead; |
| 7372 | try { |
| 7373 | numRead = input.read(buffer); |
| 7374 | } catch (IOException e) { |
| 7375 | try { |
| 7376 | fd.checkError(); |
| 7377 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7378 | null); |
| 7379 | } catch (IOException e1) { |
| 7380 | // This means that the other side closed explicitly with an error. If this |
| 7381 | // happens, log and ignore. |
| 7382 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7383 | } |
| 7384 | break; |
| 7385 | } |
| 7386 | if (numRead == -1) { |
| 7387 | readUntilEnd = true; |
| 7388 | break; |
| 7389 | } |
| 7390 | totalBytesRead += numRead; |
| 7391 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7392 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7393 | try { |
| 7394 | input.close(); |
| 7395 | } catch (IOException e) { |
| 7396 | // ignore |
| 7397 | } |
| 7398 | break; |
| 7399 | } |
| 7400 | output.write(buffer, 0, numRead); |
| 7401 | } |
| 7402 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7403 | // close is above, where the picture size is too big. |
| 7404 | |
| 7405 | try { |
| 7406 | fd.checkError(); |
| 7407 | } catch (IOException e) { |
| 7408 | loge("Remote end for call composer closed with an error: " + e); |
| 7409 | return; |
| 7410 | } |
| 7411 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7412 | if (!readUntilEnd) { |
| 7413 | loge("Did not finish reading entire image; aborting"); |
| 7414 | return; |
| 7415 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7416 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7417 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7418 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7419 | new CallComposerPictureTransfer.Factory() {}, |
| 7420 | imageData, |
| 7421 | (result) -> { |
| 7422 | if (result.first != null) { |
| 7423 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7424 | Bundle outputResult = new Bundle(); |
| 7425 | outputResult.putParcelable( |
| 7426 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7427 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7428 | outputResult); |
| 7429 | } else { |
| 7430 | callback.send(result.second, null); |
| 7431 | } |
| 7432 | } |
| 7433 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7434 | }); |
| 7435 | } |
| 7436 | |
| 7437 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7438 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7439 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7440 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7441 | |
| 7442 | final long identity = Binder.clearCallingIdentity(); |
| 7443 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7444 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7445 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7446 | } finally { |
| 7447 | Binder.restoreCallingIdentity(identity); |
| 7448 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7449 | } |
| 7450 | |
| 7451 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7452 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7453 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7454 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7455 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7456 | return false; |
| 7457 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7458 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7459 | final long identity = Binder.clearCallingIdentity(); |
| 7460 | try { |
| 7461 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7462 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7463 | // In the long run, we may instead need to check if there exists a connection service |
| 7464 | // which can support video calling. |
| 7465 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7466 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7467 | return imsManager.isVtEnabledByPlatform() |
| 7468 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7469 | && imsManager.isVtEnabledByUser(); |
| 7470 | } finally { |
| 7471 | Binder.restoreCallingIdentity(identity); |
| 7472 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7473 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7474 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7475 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7476 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7477 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7478 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7479 | mApp, subId, callingPackage, callingFeatureId, |
| 7480 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7481 | return false; |
| 7482 | } |
| 7483 | |
| 7484 | final long identity = Binder.clearCallingIdentity(); |
| 7485 | try { |
| 7486 | CarrierConfigManager configManager = |
| 7487 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7488 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7489 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7490 | } finally { |
| 7491 | Binder.restoreCallingIdentity(identity); |
| 7492 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7493 | } |
| 7494 | |
| 7495 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7496 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7497 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7498 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7499 | return false; |
| 7500 | } |
| 7501 | |
| 7502 | final long identity = Binder.clearCallingIdentity(); |
| 7503 | try { |
| 7504 | CarrierConfigManager configManager = |
| 7505 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7506 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7507 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7508 | } finally { |
| 7509 | Binder.restoreCallingIdentity(identity); |
| 7510 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7511 | } |
| 7512 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7513 | @Override |
| 7514 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7515 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7516 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7517 | } |
| 7518 | |
| 7519 | @Override |
| 7520 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7521 | final long identity = Binder.clearCallingIdentity(); |
| 7522 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7523 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7524 | } finally { |
| 7525 | Binder.restoreCallingIdentity(identity); |
| 7526 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7527 | } |
| 7528 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7529 | /** |
| 7530 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7531 | * support for the feature and device firmware support. |
| 7532 | * |
| 7533 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7534 | */ |
| 7535 | @Override |
| 7536 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7537 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7538 | final Phone phone = getPhone(subscriptionId); |
| 7539 | if (phone == null) { |
| 7540 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7541 | return false; |
| 7542 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7543 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7544 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7545 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7546 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7547 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7548 | return isCarrierSupported && isDeviceSupported; |
| 7549 | } finally { |
| 7550 | Binder.restoreCallingIdentity(identity); |
| 7551 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7552 | } |
| 7553 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7554 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7555 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7556 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7557 | * 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] | 7558 | */ |
| 7559 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7560 | final long identity = Binder.clearCallingIdentity(); |
| 7561 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7562 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7563 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7564 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7565 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7566 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7567 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7568 | } finally { |
| 7569 | Binder.restoreCallingIdentity(identity); |
| 7570 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7571 | } |
| 7572 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7573 | @Deprecated |
| 7574 | @Override |
| 7575 | public String getDeviceId(String callingPackage) { |
| 7576 | return getDeviceIdWithFeature(callingPackage, null); |
| 7577 | } |
| 7578 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7579 | /** |
| 7580 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7581 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7582 | * |
| 7583 | * <p>Requires Permission: |
| 7584 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7585 | */ |
| 7586 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7587 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7588 | try { |
| 7589 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7590 | } catch (SecurityException se) { |
| 7591 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7592 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7593 | + Binder.getCallingUid()); |
| 7594 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7595 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7596 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7597 | return null; |
| 7598 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7599 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7600 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7601 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7602 | return null; |
| 7603 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7604 | |
| 7605 | final long identity = Binder.clearCallingIdentity(); |
| 7606 | try { |
| 7607 | return phone.getDeviceId(); |
| 7608 | } finally { |
| 7609 | Binder.restoreCallingIdentity(identity); |
| 7610 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7611 | } |
| 7612 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7613 | /** |
| 7614 | * {@hide} |
| 7615 | * Returns the IMS Registration Status on a particular subid |
| 7616 | * |
| 7617 | * @param subId |
| 7618 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7619 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7620 | Phone phone = getPhone(subId); |
| 7621 | if (phone != null) { |
| 7622 | return phone.isImsRegistered(); |
| 7623 | } else { |
| 7624 | return false; |
| 7625 | } |
| 7626 | } |
| 7627 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7628 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7629 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7630 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7631 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7632 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7633 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7634 | } |
| 7635 | final long identity = Binder.clearCallingIdentity(); |
| 7636 | try { |
| 7637 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7638 | } finally { |
| 7639 | Binder.restoreCallingIdentity(identity); |
| 7640 | } |
| 7641 | } |
| 7642 | |
| 7643 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7644 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7645 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7646 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7647 | mApp, |
| 7648 | subscriptionId, |
| 7649 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7650 | final long identity = Binder.clearCallingIdentity(); |
| 7651 | try { |
| 7652 | Phone phone = getPhone(subscriptionId); |
| 7653 | if (phone == null) { |
| 7654 | return null; |
| 7655 | } |
| 7656 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7657 | } finally { |
| 7658 | Binder.restoreCallingIdentity(identity); |
| 7659 | } |
| 7660 | } |
| 7661 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7662 | /** |
| 7663 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7664 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7665 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7666 | final long identity = Binder.clearCallingIdentity(); |
| 7667 | try { |
| 7668 | Phone phone = getPhone(subId); |
| 7669 | if (phone != null) { |
| 7670 | return phone.isWifiCallingEnabled(); |
| 7671 | } else { |
| 7672 | return false; |
| 7673 | } |
| 7674 | } finally { |
| 7675 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7676 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7677 | } |
| 7678 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7679 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7680 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7681 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7682 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7683 | final long identity = Binder.clearCallingIdentity(); |
| 7684 | try { |
| 7685 | Phone phone = getPhone(subId); |
| 7686 | if (phone != null) { |
| 7687 | return phone.isVideoEnabled(); |
| 7688 | } else { |
| 7689 | return false; |
| 7690 | } |
| 7691 | } finally { |
| 7692 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7693 | } |
| 7694 | } |
| 7695 | |
| 7696 | /** |
| 7697 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7698 | * defined in {@link ImsRegistrationImplBase}. |
| 7699 | */ |
| 7700 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7701 | final long identity = Binder.clearCallingIdentity(); |
| 7702 | try { |
| 7703 | Phone phone = getPhone(subId); |
| 7704 | if (phone != null) { |
| 7705 | return phone.getImsRegistrationTech(); |
| 7706 | } else { |
| 7707 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7708 | } |
| 7709 | } finally { |
| 7710 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7711 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7712 | } |
| 7713 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7714 | @Override |
| 7715 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7716 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7717 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7718 | return; |
| 7719 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7720 | Phone defaultPhone = getDefaultPhone(); |
| 7721 | if (defaultPhone != null) { |
| 7722 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7723 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7724 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7725 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7726 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7727 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7728 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7729 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7730 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7731 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7732 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7733 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7734 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7735 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7736 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7737 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7738 | // There has been issues when Sms raw table somehow stores orphan |
| 7739 | // fragments. They lead to garbled message when new fragments come |
| 7740 | // in and combined with those stale ones. In case this happens again, |
| 7741 | // user can reset all network settings which will clean up this table. |
| 7742 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7743 | // Clean up IMS settings as well here. |
| 7744 | int slotId = getSlotIndex(subId); |
| 7745 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7746 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7747 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7748 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7749 | if (defaultPhone == null) { |
| 7750 | return; |
| 7751 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7752 | // Erase modem config if erase modem on network setting is enabled. |
| 7753 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7754 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7755 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7756 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7757 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7758 | |
| 7759 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7760 | } finally { |
| 7761 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7762 | } |
| 7763 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7764 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7765 | @VisibleForTesting |
| 7766 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7767 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7768 | return; |
| 7769 | } |
| 7770 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7771 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7772 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7773 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7774 | "user=" + defaultNetworkType); |
| 7775 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7776 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7777 | defaultNetworkType, null); |
| 7778 | } |
| 7779 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7780 | private void cleanUpSmsRawTable(Context context) { |
| 7781 | ContentResolver resolver = context.getContentResolver(); |
| 7782 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7783 | resolver.delete(uri, null, null); |
| 7784 | } |
| 7785 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7786 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7787 | public String getSimLocaleForSubscriber(int subId) { |
| 7788 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7789 | final Phone phone = getPhone(subId); |
| 7790 | if (phone == null) { |
| 7791 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7792 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7793 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7794 | final long identity = Binder.clearCallingIdentity(); |
| 7795 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7796 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7797 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7798 | if (info == null) { |
| 7799 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7800 | return null; |
| 7801 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7802 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7803 | // preferences (EF-PL and EF-LI)... |
| 7804 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7805 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7806 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7807 | if (localeFromDefaultSim != null) { |
| 7808 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7809 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7810 | + localeFromDefaultSim); |
| 7811 | return localeFromDefaultSim.toLanguageTag(); |
| 7812 | } else { |
| 7813 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7814 | } |
| 7815 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7816 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7817 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7818 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7819 | // the SIM and carrier preferences does not include a country we add the country |
| 7820 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7821 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7822 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7823 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7824 | return mccLocale.toLanguageTag(); |
| 7825 | } |
| 7826 | |
| 7827 | if (DBG) log("No locale found - returning null"); |
| 7828 | return null; |
| 7829 | } finally { |
| 7830 | Binder.restoreCallingIdentity(identity); |
| 7831 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7832 | } |
| 7833 | |
| 7834 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7835 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7836 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7837 | } |
| 7838 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7839 | /** |
| 7840 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7841 | */ |
| 7842 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7843 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7844 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7845 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7846 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7847 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7848 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7849 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7850 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7851 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7852 | * representing the state of the modem. |
| 7853 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7854 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7855 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7856 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7857 | */ |
| 7858 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7859 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7860 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7861 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7862 | |
| 7863 | final long identity = Binder.clearCallingIdentity(); |
| 7864 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7865 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7866 | } finally { |
| 7867 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7868 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7869 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7870 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7871 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7872 | // less than total activity duration. |
| 7873 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7874 | if (info == null) { |
| 7875 | return false; |
| 7876 | } |
| 7877 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7878 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7879 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7880 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7881 | return (info.isValid() |
| 7882 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7883 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7884 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7885 | && (totalTxTimeMs <= activityDurationMs)); |
| 7886 | } |
| 7887 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7888 | /** |
| 7889 | * {@hide} |
| 7890 | * Returns the service state information on specified subscription. |
| 7891 | */ |
| 7892 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7893 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7894 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7895 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7896 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7897 | return null; |
| 7898 | } |
| 7899 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7900 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7901 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7902 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7903 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7904 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7905 | .setCallingPid(Binder.getCallingPid()) |
| 7906 | .setCallingUid(Binder.getCallingUid()) |
| 7907 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7908 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7909 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7910 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7911 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7912 | .build()); |
| 7913 | |
| 7914 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7915 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7916 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7917 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7918 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7919 | .setCallingPid(Binder.getCallingPid()) |
| 7920 | .setCallingUid(Binder.getCallingUid()) |
| 7921 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7922 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7923 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7924 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7925 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7926 | .build()); |
| 7927 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7928 | boolean hasFinePermission = |
| 7929 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7930 | boolean hasCoarsePermission = |
| 7931 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7932 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7933 | final Phone phone = getPhone(subId); |
| 7934 | if (phone == null) { |
| 7935 | return null; |
| 7936 | } |
| 7937 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7938 | final long identity = Binder.clearCallingIdentity(); |
| 7939 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7940 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7941 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7942 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7943 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7944 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7945 | Rlog.d(LOG_TAG, |
| 7946 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7947 | return null; |
| 7948 | } |
| 7949 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7950 | ServiceState ss = phone.getServiceState(); |
| 7951 | |
| 7952 | // Scrub out the location info in ServiceState depending on what level of access |
| 7953 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7954 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7955 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7956 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7957 | } finally { |
| 7958 | Binder.restoreCallingIdentity(identity); |
| 7959 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7960 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7961 | |
| 7962 | /** |
| 7963 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7964 | * |
| 7965 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7966 | * voicemail ringtone. |
| 7967 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7968 | * PhoneAccount. |
| 7969 | */ |
| 7970 | @Override |
| 7971 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7972 | final long identity = Binder.clearCallingIdentity(); |
| 7973 | try { |
| 7974 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7975 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7976 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7977 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7978 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7979 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7980 | } finally { |
| 7981 | Binder.restoreCallingIdentity(identity); |
| 7982 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7983 | } |
| 7984 | |
| 7985 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7986 | * Sets the per-account voicemail ringtone. |
| 7987 | * |
| 7988 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7989 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7990 | * |
| 7991 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7992 | * voicemail ringtone. |
| 7993 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7994 | * PhoneAccount. |
| 7995 | */ |
| 7996 | @Override |
| 7997 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7998 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7999 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8000 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8001 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8002 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8003 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8004 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8005 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8006 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8007 | |
| 8008 | final long identity = Binder.clearCallingIdentity(); |
| 8009 | try { |
| 8010 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8011 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8012 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8013 | } |
| 8014 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8015 | } finally { |
| 8016 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8017 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8018 | } |
| 8019 | |
| 8020 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8021 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8022 | * |
| 8023 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8024 | * voicemail vibration setting. |
| 8025 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8026 | */ |
| 8027 | @Override |
| 8028 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8029 | final long identity = Binder.clearCallingIdentity(); |
| 8030 | try { |
| 8031 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8032 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8033 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8034 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8035 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8036 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8037 | } finally { |
| 8038 | Binder.restoreCallingIdentity(identity); |
| 8039 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8040 | } |
| 8041 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8042 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8043 | * Sets the per-account voicemail vibration. |
| 8044 | * |
| 8045 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8046 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8047 | * |
| 8048 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8049 | * voicemail vibration setting. |
| 8050 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8051 | * specific PhoneAccount. |
| 8052 | */ |
| 8053 | @Override |
| 8054 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8055 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8056 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8057 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8058 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8059 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8060 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8061 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8062 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8063 | } |
| 8064 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8065 | final long identity = Binder.clearCallingIdentity(); |
| 8066 | try { |
| 8067 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8068 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8069 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8070 | } |
| 8071 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8072 | } finally { |
| 8073 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8074 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8075 | } |
| 8076 | |
| 8077 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8078 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8079 | * |
| 8080 | * @throws SecurityException if the caller does not have the required permission |
| 8081 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8082 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8083 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8084 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8085 | } |
| 8086 | |
| 8087 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8088 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8089 | * permission. |
| 8090 | * |
| 8091 | * @throws SecurityException if the caller does not have the required permission |
| 8092 | */ |
| 8093 | private void enforceSendSmsPermission() { |
| 8094 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8095 | } |
| 8096 | |
| 8097 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8098 | * Make sure called from the package in charge of visual voicemail. |
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 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8101 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8102 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8103 | final long identity = Binder.clearCallingIdentity(); |
| 8104 | try { |
| 8105 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8106 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8107 | if (componentName == null) { |
| 8108 | throw new SecurityException( |
| 8109 | "Caller not current active visual voicemail package[null]"); |
| 8110 | } |
| 8111 | String vvmPackage = componentName.getPackageName(); |
| 8112 | if (!callingPackage.equals(vvmPackage)) { |
| 8113 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 8114 | + vvmPackage + "]"); |
| 8115 | } |
| 8116 | } finally { |
| 8117 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8118 | } |
| 8119 | } |
| 8120 | |
| 8121 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8122 | * Return the application ID for the app type. |
| 8123 | * |
| 8124 | * @param subId the subscription ID that this request applies to. |
| 8125 | * @param appType the uicc app type. |
| 8126 | * @return Application ID for specificied app type, or null if no uicc. |
| 8127 | */ |
| 8128 | @Override |
| 8129 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8130 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8131 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8132 | |
| 8133 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8134 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8135 | if (phone == null) { |
| 8136 | return null; |
| 8137 | } |
| 8138 | String aid = null; |
| 8139 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8140 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8141 | .getApplicationByType(appType).getAid(); |
| 8142 | } catch (Exception e) { |
| 8143 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8144 | } |
| 8145 | return aid; |
| 8146 | } finally { |
| 8147 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8148 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8149 | } |
| 8150 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8151 | /** |
| 8152 | * Return the Electronic Serial Number. |
| 8153 | * |
| 8154 | * @param subId the subscription ID that this request applies to. |
| 8155 | * @return ESN or null if error. |
| 8156 | */ |
| 8157 | @Override |
| 8158 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8159 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8160 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8161 | |
| 8162 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8163 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8164 | if (phone == null) { |
| 8165 | return null; |
| 8166 | } |
| 8167 | String esn = null; |
| 8168 | try { |
| 8169 | esn = phone.getEsn(); |
| 8170 | } catch (Exception e) { |
| 8171 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8172 | } |
| 8173 | return esn; |
| 8174 | } finally { |
| 8175 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8176 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8177 | } |
| 8178 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8179 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8180 | * Return the Preferred Roaming List Version. |
| 8181 | * |
| 8182 | * @param subId the subscription ID that this request applies to. |
| 8183 | * @return PRLVersion or null if error. |
| 8184 | */ |
| 8185 | @Override |
| 8186 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8187 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8188 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8189 | |
| 8190 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8191 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8192 | if (phone == null) { |
| 8193 | return null; |
| 8194 | } |
| 8195 | String cdmaPrlVersion = null; |
| 8196 | try { |
| 8197 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8198 | } catch (Exception e) { |
| 8199 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8200 | } |
| 8201 | return cdmaPrlVersion; |
| 8202 | } finally { |
| 8203 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8204 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8205 | } |
| 8206 | |
| 8207 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8208 | * Get snapshot of Telephony histograms |
| 8209 | * @return List of Telephony histograms |
| 8210 | * @hide |
| 8211 | */ |
| 8212 | @Override |
| 8213 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8214 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8215 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8216 | |
| 8217 | final long identity = Binder.clearCallingIdentity(); |
| 8218 | try { |
| 8219 | return RIL.getTelephonyRILTimingHistograms(); |
| 8220 | } finally { |
| 8221 | Binder.restoreCallingIdentity(identity); |
| 8222 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8223 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8224 | |
| 8225 | /** |
| 8226 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8227 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8228 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8229 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8230 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8231 | * @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] | 8232 | */ |
| 8233 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8234 | @TelephonyManager.SetCarrierRestrictionResult |
| 8235 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8236 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8237 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8238 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8239 | if (carrierRestrictionRules == null) { |
| 8240 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8241 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8242 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8243 | final long identity = Binder.clearCallingIdentity(); |
| 8244 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8245 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8246 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8247 | } finally { |
| 8248 | Binder.restoreCallingIdentity(identity); |
| 8249 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8250 | } |
| 8251 | |
| 8252 | /** |
| 8253 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8254 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8255 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8256 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8257 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8258 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8259 | */ |
| 8260 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8261 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8262 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8263 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8264 | |
| 8265 | final long identity = Binder.clearCallingIdentity(); |
| 8266 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8267 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8268 | if (response instanceof CarrierRestrictionRules) { |
| 8269 | return (CarrierRestrictionRules) response; |
| 8270 | } |
| 8271 | // Response is an Exception of some kind, |
| 8272 | // which is signalled to the user as a NULL retval |
| 8273 | return null; |
| 8274 | } catch (Exception e) { |
| 8275 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8276 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8277 | } finally { |
| 8278 | Binder.restoreCallingIdentity(identity); |
| 8279 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8280 | } |
| 8281 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8282 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8283 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8284 | * @param subId the subscription ID that this action applies to. |
| 8285 | * @param enabled control enable or disable radio. |
| 8286 | * {@hide} |
| 8287 | */ |
| 8288 | @Override |
| 8289 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8290 | enforceModifyPermission(); |
| 8291 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8292 | |
| 8293 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8294 | if (phone == null) { |
| 8295 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8296 | return; |
| 8297 | } |
| 8298 | try { |
| 8299 | phone.carrierActionSetRadioEnabled(enabled); |
| 8300 | } catch (Exception e) { |
| 8301 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8302 | } finally { |
| 8303 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8304 | } |
| 8305 | } |
| 8306 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8307 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8308 | * Enable or disable Voice over NR (VoNR) |
| 8309 | * @param subId the subscription ID that this action applies to. |
| 8310 | * @param enabled enable or disable VoNR. |
| 8311 | * @return operation result. |
| 8312 | */ |
| 8313 | @Override |
| 8314 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8315 | enforceModifyPermission(); |
| 8316 | final Phone phone = getPhone(subId); |
| 8317 | |
| 8318 | final long identity = Binder.clearCallingIdentity(); |
| 8319 | if (phone == null) { |
| 8320 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8321 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8322 | } |
| 8323 | |
| 8324 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8325 | try { |
| 8326 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8327 | workSource); |
| 8328 | if (DBG) log("setVoNrEnabled result: " + result); |
| 8329 | return result; |
| 8330 | } finally { |
| 8331 | Binder.restoreCallingIdentity(identity); |
| 8332 | } |
| 8333 | } |
| 8334 | |
| 8335 | /** |
| 8336 | * Is voice over NR enabled |
| 8337 | * @return true if VoNR is enabled else false |
| 8338 | */ |
| 8339 | @Override |
| 8340 | public boolean isVoNrEnabled(int subId) { |
| 8341 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8342 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8343 | final long identity = Binder.clearCallingIdentity(); |
| 8344 | try { |
| 8345 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8346 | null, subId, workSource); |
| 8347 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8348 | return isEnabled; |
| 8349 | } finally { |
| 8350 | Binder.restoreCallingIdentity(identity); |
| 8351 | } |
| 8352 | } |
| 8353 | |
| 8354 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8355 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8356 | * network status based on which carrier apps could apply actions accordingly, |
| 8357 | * enable/disable default url handler for example. |
| 8358 | * |
| 8359 | * @param subId the subscription ID that this action applies to. |
| 8360 | * @param report control start/stop reporting the default network status. |
| 8361 | * {@hide} |
| 8362 | */ |
| 8363 | @Override |
| 8364 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8365 | enforceModifyPermission(); |
| 8366 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8367 | |
| 8368 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8369 | if (phone == null) { |
| 8370 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8371 | return; |
| 8372 | } |
| 8373 | try { |
| 8374 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8375 | } catch (Exception e) { |
| 8376 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8377 | } finally { |
| 8378 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8379 | } |
| 8380 | } |
| 8381 | |
| 8382 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8383 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8384 | * @param subId the subscription ID that this action applies to. |
| 8385 | * {@hide} |
| 8386 | */ |
| 8387 | @Override |
| 8388 | public void carrierActionResetAll(int subId) { |
| 8389 | enforceModifyPermission(); |
| 8390 | final Phone phone = getPhone(subId); |
| 8391 | if (phone == null) { |
| 8392 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8393 | return; |
| 8394 | } |
| 8395 | try { |
| 8396 | phone.carrierActionResetAll(); |
| 8397 | } catch (Exception e) { |
| 8398 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8399 | } |
| 8400 | } |
| 8401 | |
| 8402 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8403 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8404 | * bug report is being generated. |
| 8405 | */ |
| 8406 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8407 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8408 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8409 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8410 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8411 | + Binder.getCallingPid() |
| 8412 | + ", uid=" + Binder.getCallingUid() |
| 8413 | + "without permission " |
| 8414 | + android.Manifest.permission.DUMP); |
| 8415 | return; |
| 8416 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8417 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8418 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8419 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8420 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8421 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8422 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8423 | @NonNull String[] args) { |
| 8424 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8425 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8426 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8427 | } |
| 8428 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8429 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8430 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8431 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8432 | * @param reason the reason the data enable change is taking place |
| 8433 | * @param enabled True if enabling the data, otherwise disabling. |
| 8434 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8435 | */ |
| 8436 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8437 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8438 | boolean enabled) { |
| 8439 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8440 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8441 | try { |
| 8442 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8443 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8444 | } catch (SecurityException se) { |
| 8445 | enforceModifyPermission(); |
| 8446 | } |
| 8447 | } else { |
| 8448 | enforceModifyPermission(); |
| 8449 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8450 | |
| 8451 | final long identity = Binder.clearCallingIdentity(); |
| 8452 | try { |
| 8453 | Phone phone = getPhone(subId); |
| 8454 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8455 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8456 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8457 | } else { |
| 8458 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 8459 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8460 | } |
| 8461 | } finally { |
| 8462 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8463 | } |
| 8464 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8465 | |
| 8466 | /** |
| 8467 | * Get Client request stats |
| 8468 | * @return List of Client Request Stats |
| 8469 | * @hide |
| 8470 | */ |
| 8471 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8472 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8473 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8474 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8475 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8476 | return null; |
| 8477 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8478 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8479 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8480 | final long identity = Binder.clearCallingIdentity(); |
| 8481 | try { |
| 8482 | if (phone != null) { |
| 8483 | return phone.getClientRequestStats(); |
| 8484 | } |
| 8485 | |
| 8486 | return null; |
| 8487 | } finally { |
| 8488 | Binder.restoreCallingIdentity(identity); |
| 8489 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8490 | } |
| 8491 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8492 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8493 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8494 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8495 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8496 | |
| 8497 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8498 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8499 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8500 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8501 | * @param state State of SIM (power down, power up, pass through) |
| 8502 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8503 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8504 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8505 | * |
| 8506 | **/ |
| 8507 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8508 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8509 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8510 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8511 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8512 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8513 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8514 | final long identity = Binder.clearCallingIdentity(); |
| 8515 | try { |
| 8516 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8517 | phone.setSimPowerState(state, null, workSource); |
| 8518 | } |
| 8519 | } finally { |
| 8520 | Binder.restoreCallingIdentity(identity); |
| 8521 | } |
| 8522 | } |
| 8523 | |
| 8524 | /** |
| 8525 | * Set SIM card power state. |
| 8526 | * |
| 8527 | * @param slotIndex SIM slot id. |
| 8528 | * @param state State of SIM (power down, power up, pass through) |
| 8529 | * @param callback callback to trigger after success or failure |
| 8530 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8531 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8532 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8533 | * |
| 8534 | **/ |
| 8535 | @Override |
| 8536 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8537 | IIntegerConsumer callback) { |
| 8538 | enforceModifyPermission(); |
| 8539 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8540 | |
| 8541 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8542 | |
| 8543 | final long identity = Binder.clearCallingIdentity(); |
| 8544 | try { |
| 8545 | if (phone != null) { |
| 8546 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8547 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8548 | } |
| 8549 | } finally { |
| 8550 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8551 | } |
| 8552 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8553 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8554 | private boolean isUssdApiAllowed(int subId) { |
| 8555 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8556 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8557 | if (configManager == null) { |
| 8558 | return false; |
| 8559 | } |
| 8560 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8561 | if (pb == null) { |
| 8562 | return false; |
| 8563 | } |
| 8564 | return pb.getBoolean( |
| 8565 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8566 | } |
| 8567 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8568 | /** |
| 8569 | * Check if phone is in emergency callback mode |
| 8570 | * @return true if phone is in emergency callback mode |
| 8571 | * @param subId sub id |
| 8572 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8573 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8574 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8575 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8576 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8577 | |
| 8578 | final long identity = Binder.clearCallingIdentity(); |
| 8579 | try { |
| 8580 | if (phone != null) { |
| 8581 | return phone.isInEcm(); |
| 8582 | } else { |
| 8583 | return false; |
| 8584 | } |
| 8585 | } finally { |
| 8586 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8587 | } |
| 8588 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8589 | |
| 8590 | /** |
| 8591 | * Get the current signal strength information for the given subscription. |
| 8592 | * Because this information is not updated when the device is in a low power state |
| 8593 | * it should not be relied-upon to be current. |
| 8594 | * @param subId Subscription index |
| 8595 | * @return the most recent cached signal strength info from the modem |
| 8596 | */ |
| 8597 | @Override |
| 8598 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8599 | final long identity = Binder.clearCallingIdentity(); |
| 8600 | try { |
| 8601 | Phone p = getPhone(subId); |
| 8602 | if (p == null) { |
| 8603 | return null; |
| 8604 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8605 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8606 | return p.getSignalStrength(); |
| 8607 | } finally { |
| 8608 | Binder.restoreCallingIdentity(identity); |
| 8609 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8610 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8611 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8612 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8613 | * Get the current modem radio state for the given slot. |
| 8614 | * @param slotIndex slot index. |
| 8615 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8616 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8617 | * @return the current radio power state from the modem |
| 8618 | */ |
| 8619 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8620 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8621 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8622 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8623 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8624 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8625 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8626 | } |
| 8627 | |
| 8628 | final long identity = Binder.clearCallingIdentity(); |
| 8629 | try { |
| 8630 | return phone.getRadioPowerState(); |
| 8631 | } finally { |
| 8632 | Binder.restoreCallingIdentity(identity); |
| 8633 | } |
| 8634 | } |
| 8635 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8636 | } |
| 8637 | |
| 8638 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8639 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8640 | * |
| 8641 | * <p>Requires one of the following permissions: |
| 8642 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8643 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8644 | * privileges. |
| 8645 | * |
| 8646 | * @param subId subscription id |
| 8647 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8648 | * {@code false}. |
| 8649 | */ |
| 8650 | @Override |
| 8651 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8652 | try { |
| 8653 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8654 | null); |
| 8655 | } catch (Exception e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8656 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8657 | mApp, subId, "isDataRoamingEnabled"); |
| 8658 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8659 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8660 | boolean isEnabled = false; |
| 8661 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8662 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8663 | Phone phone = getPhone(subId); |
| 8664 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8665 | } finally { |
| 8666 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8667 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8668 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8669 | } |
| 8670 | |
| 8671 | |
| 8672 | /** |
| 8673 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8674 | * |
| 8675 | * <p> Requires permission: |
| 8676 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8677 | * privileges. |
| 8678 | * |
| 8679 | * @param subId subscription id |
| 8680 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8681 | */ |
| 8682 | @Override |
| 8683 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8684 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8685 | mApp, subId, "setDataRoamingEnabled"); |
| 8686 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8687 | final long identity = Binder.clearCallingIdentity(); |
| 8688 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8689 | Phone phone = getPhone(subId); |
| 8690 | if (phone != null) { |
| 8691 | phone.setDataRoamingEnabled(isEnabled); |
| 8692 | } |
| 8693 | } finally { |
| 8694 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8695 | } |
| 8696 | } |
| 8697 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8698 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8699 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8700 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8701 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8702 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8703 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8704 | boolean isAllowed = true; |
| 8705 | final long identity = Binder.clearCallingIdentity(); |
| 8706 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8707 | Phone phone = getPhone(subId); |
| 8708 | if (phone != null) { |
| 8709 | isAllowed = phone.isCspPlmnEnabled(); |
| 8710 | } |
| 8711 | } finally { |
| 8712 | Binder.restoreCallingIdentity(identity); |
| 8713 | } |
| 8714 | return isAllowed; |
| 8715 | } |
| 8716 | |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8717 | private boolean haveCarrierPrivilegeAccess(UiccCard card, String callingPackage) { |
| 8718 | // TODO once MEP API refactoring CL is merged, loop port list from UiccCardInfo, |
| 8719 | // and if find the matching UiccPort by UiccController.getUiccPortForSlot(slot, portIdx) |
| 8720 | // Update each UiccPort object based on privilege access |
| 8721 | UiccPort[] uiccPorts = card.getUiccPortList(); |
| 8722 | for (UiccPort port : uiccPorts) { |
| 8723 | UiccProfile profile = port.getUiccProfile(); |
| 8724 | if (profile == null || |
| 8725 | profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8726 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8727 | return false; |
| 8728 | } |
| 8729 | } |
| 8730 | return true; |
| 8731 | } |
| 8732 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8733 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8734 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8735 | // Verify that tha callingPackage belongs to the calling UID |
| 8736 | mApp.getSystemService(AppOpsManager.class) |
| 8737 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8738 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8739 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8740 | try { |
| 8741 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8742 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8743 | } catch (SecurityException e) { |
| 8744 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8745 | // has carrier privileges on an active UICC |
| 8746 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8747 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8748 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8749 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8750 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8751 | |
| 8752 | final long identity = Binder.clearCallingIdentity(); |
| 8753 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8754 | UiccController uiccController = UiccController.getInstance(); |
| 8755 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8756 | if (hasReadPermission) { |
| 8757 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8758 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8759 | |
| 8760 | // Remove private info if the caller doesn't have access |
| 8761 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8762 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8763 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8764 | // is available |
| 8765 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8766 | // TODO remove card.getUiccPortList().length once MEP API refactoring CL is merged |
| 8767 | // Get UiccPortInfo from CardInfo and process further based on each UiccPort |
| 8768 | if (card == null || card.getUiccPortList().length == 0) { |
| 8769 | // assume no access if the card or ports are unavailable |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8770 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8771 | continue; |
| 8772 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8773 | |
| 8774 | if (haveCarrierPrivilegeAccess(card, callingPackage)) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8775 | filteredInfos.add(cardInfo); |
| 8776 | } else { |
| 8777 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8778 | } |
| 8779 | } |
| 8780 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8781 | } finally { |
| 8782 | Binder.restoreCallingIdentity(identity); |
| 8783 | } |
| 8784 | } |
| 8785 | |
| 8786 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8787 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8788 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8789 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8790 | final long identity = Binder.clearCallingIdentity(); |
| 8791 | try { |
| 8792 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8793 | if (slots == null) { |
| 8794 | Rlog.i(LOG_TAG, "slots is null."); |
| 8795 | return null; |
| 8796 | } |
| 8797 | |
| 8798 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8799 | for (int i = 0; i < slots.length; i++) { |
| 8800 | UiccSlot slot = slots[i]; |
| 8801 | if (slot == null) { |
| 8802 | continue; |
| 8803 | } |
| 8804 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8805 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8806 | UiccCard card = slot.getUiccCard(); |
| 8807 | if (card != null) { |
| 8808 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8809 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8810 | cardId = slot.getEid(); |
| 8811 | if (TextUtils.isEmpty(cardId)) { |
| 8812 | cardId = slot.getIccId(); |
| 8813 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8814 | } |
| 8815 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8816 | if (cardId != null) { |
| 8817 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8818 | // if cardId is an EID, it's all digits so this is fine |
| 8819 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8820 | } |
| 8821 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8822 | int cardState = 0; |
| 8823 | switch (slot.getCardState()) { |
| 8824 | case CARDSTATE_ABSENT: |
| 8825 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8826 | break; |
| 8827 | case CARDSTATE_PRESENT: |
| 8828 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8829 | break; |
| 8830 | case CARDSTATE_ERROR: |
| 8831 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8832 | break; |
| 8833 | case CARDSTATE_RESTRICTED: |
| 8834 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8835 | break; |
| 8836 | default: |
| 8837 | break; |
| 8838 | |
| 8839 | } |
| 8840 | |
| 8841 | infos[i] = new UiccSlotInfo( |
| 8842 | slot.isActive(), |
| 8843 | slot.isEuicc(), |
| 8844 | cardId, |
| 8845 | cardState, |
| 8846 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8847 | slot.isExtendedApduSupported(), |
| 8848 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8849 | } |
| 8850 | return infos; |
| 8851 | } finally { |
| 8852 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8853 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8854 | } |
| 8855 | |
| 8856 | @Override |
| 8857 | public boolean switchSlots(int[] physicalSlots) { |
| 8858 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8859 | |
| 8860 | final long identity = Binder.clearCallingIdentity(); |
| 8861 | try { |
| 8862 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8863 | } finally { |
| 8864 | Binder.restoreCallingIdentity(identity); |
| 8865 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8866 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8867 | |
| 8868 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8869 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8870 | final long identity = Binder.clearCallingIdentity(); |
| 8871 | try { |
| 8872 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8873 | } finally { |
| 8874 | Binder.restoreCallingIdentity(identity); |
| 8875 | } |
| 8876 | } |
| 8877 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8878 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8879 | * A test API to reload the UICC profile. |
| 8880 | * |
| 8881 | * <p>Requires that the calling app has permission |
| 8882 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8883 | * @hide |
| 8884 | */ |
| 8885 | @Override |
| 8886 | public void refreshUiccProfile(int subId) { |
| 8887 | enforceModifyPermission(); |
| 8888 | |
| 8889 | final long identity = Binder.clearCallingIdentity(); |
| 8890 | try { |
| 8891 | Phone phone = getPhone(subId); |
| 8892 | if (phone == null) { |
| 8893 | return; |
| 8894 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8895 | UiccPort uiccPort = phone.getUiccPort(); |
| 8896 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8897 | return; |
| 8898 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8899 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8900 | if (uiccProfile == null) { |
| 8901 | return; |
| 8902 | } |
| 8903 | uiccProfile.refresh(); |
| 8904 | } finally { |
| 8905 | Binder.restoreCallingIdentity(identity); |
| 8906 | } |
| 8907 | } |
| 8908 | |
| 8909 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8910 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8911 | */ |
| 8912 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8913 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8914 | } |
| 8915 | |
| 8916 | /** |
| 8917 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8918 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8919 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8920 | */ |
| 8921 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8922 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8923 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8924 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8925 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8926 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8927 | return isDataRoamingEnabled; |
| 8928 | } |
| 8929 | |
| 8930 | /** |
| 8931 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8932 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8933 | */ |
| 8934 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8935 | List<Integer> list = TelephonyProperties.default_network(); |
| 8936 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8937 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8938 | return list.get(phoneId); |
| 8939 | } |
| 8940 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8941 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8942 | |
| 8943 | @Override |
| 8944 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8945 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8946 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8947 | |
| 8948 | final long identity = Binder.clearCallingIdentity(); |
| 8949 | try { |
| 8950 | final Phone phone = getPhone(subId); |
| 8951 | if (phone == null) { |
| 8952 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8953 | return; |
| 8954 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8955 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8956 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8957 | if (carrierPrivilegeRules == null) { |
| 8958 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8959 | } else { |
| 8960 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8961 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8962 | } finally { |
| 8963 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8964 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8965 | } |
| 8966 | |
| 8967 | @Override |
| 8968 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8969 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8970 | |
| 8971 | final long identity = Binder.clearCallingIdentity(); |
| 8972 | try { |
| 8973 | final Phone phone = getPhone(subId); |
| 8974 | if (phone == null) { |
| 8975 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8976 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8977 | } |
| 8978 | return phone.getCarrierIdListVersion(); |
| 8979 | } finally { |
| 8980 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8981 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8982 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8983 | |
| 8984 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8985 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8986 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8987 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8988 | mApp, subId, callingPackage, callingFeatureId, |
| 8989 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8990 | return -1; |
| 8991 | } |
| 8992 | |
| 8993 | final long identity = Binder.clearCallingIdentity(); |
| 8994 | try { |
| 8995 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8996 | } finally { |
| 8997 | Binder.restoreCallingIdentity(identity); |
| 8998 | } |
| 8999 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9000 | |
| 9001 | @Override |
| 9002 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9003 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9004 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9005 | mApp, subId, "getCdmaRoamingMode"); |
| 9006 | |
| 9007 | final long identity = Binder.clearCallingIdentity(); |
| 9008 | try { |
| 9009 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9010 | } finally { |
| 9011 | Binder.restoreCallingIdentity(identity); |
| 9012 | } |
| 9013 | } |
| 9014 | |
| 9015 | @Override |
| 9016 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9017 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9018 | mApp, subId, "setCdmaRoamingMode"); |
| 9019 | |
| 9020 | final long identity = Binder.clearCallingIdentity(); |
| 9021 | try { |
| 9022 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9023 | } finally { |
| 9024 | Binder.restoreCallingIdentity(identity); |
| 9025 | } |
| 9026 | } |
| 9027 | |
| 9028 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9029 | public int getCdmaSubscriptionMode(int subId) { |
| 9030 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9031 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9032 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9033 | |
| 9034 | final long identity = Binder.clearCallingIdentity(); |
| 9035 | try { |
| 9036 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9037 | } finally { |
| 9038 | Binder.restoreCallingIdentity(identity); |
| 9039 | } |
| 9040 | } |
| 9041 | |
| 9042 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9043 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9044 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9045 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9046 | |
| 9047 | final long identity = Binder.clearCallingIdentity(); |
| 9048 | try { |
| 9049 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9050 | } finally { |
| 9051 | Binder.restoreCallingIdentity(identity); |
| 9052 | } |
| 9053 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9054 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9055 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9056 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9057 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9058 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9059 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9060 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9061 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9062 | } |
| 9063 | final long identity = Binder.clearCallingIdentity(); |
| 9064 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9065 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9066 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9067 | if (phone.getEmergencyNumberTracker() != null |
| 9068 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9069 | emergencyNumberListInternal.put( |
| 9070 | phone.getSubId(), |
| 9071 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9072 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9073 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9074 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9075 | } finally { |
| 9076 | Binder.restoreCallingIdentity(identity); |
| 9077 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9078 | } |
| 9079 | |
| 9080 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9081 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9082 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9083 | if (!exactMatch) { |
| 9084 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9085 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9086 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9087 | } |
| 9088 | final long identity = Binder.clearCallingIdentity(); |
| 9089 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9090 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9091 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9092 | && phone.getEmergencyNumberTracker() |
| 9093 | .isEmergencyNumber(number, exactMatch)) { |
| 9094 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9095 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9096 | } |
| 9097 | return false; |
| 9098 | } finally { |
| 9099 | Binder.restoreCallingIdentity(identity); |
| 9100 | } |
| 9101 | } |
| 9102 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9103 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9104 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9105 | */ |
| 9106 | @Override |
| 9107 | public void startEmergencyCallbackMode() { |
| 9108 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9109 | "startEmergencyCallbackMode"); |
| 9110 | enforceModifyPermission(); |
| 9111 | final long identity = Binder.clearCallingIdentity(); |
| 9112 | try { |
| 9113 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9114 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9115 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9116 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9117 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9118 | gsmCdmaPhone.obtainMessage( |
| 9119 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9120 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9121 | } |
| 9122 | } |
| 9123 | } finally { |
| 9124 | Binder.restoreCallingIdentity(identity); |
| 9125 | } |
| 9126 | } |
| 9127 | |
| 9128 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9129 | * Update emergency number list for test mode. |
| 9130 | */ |
| 9131 | @Override |
| 9132 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9133 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9134 | "updateEmergencyNumberListTestMode"); |
| 9135 | |
| 9136 | final long identity = Binder.clearCallingIdentity(); |
| 9137 | try { |
| 9138 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9139 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9140 | if (tracker != null) { |
| 9141 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9142 | } |
| 9143 | } |
| 9144 | } finally { |
| 9145 | Binder.restoreCallingIdentity(identity); |
| 9146 | } |
| 9147 | } |
| 9148 | |
| 9149 | /** |
| 9150 | * Get the full emergency number list for test mode. |
| 9151 | */ |
| 9152 | @Override |
| 9153 | public List<String> getEmergencyNumberListTestMode() { |
| 9154 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9155 | "getEmergencyNumberListTestMode"); |
| 9156 | |
| 9157 | final long identity = Binder.clearCallingIdentity(); |
| 9158 | try { |
| 9159 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9160 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9161 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9162 | if (tracker != null) { |
| 9163 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9164 | emergencyNumbers.add(num.getNumber()); |
| 9165 | } |
| 9166 | } |
| 9167 | } |
| 9168 | return new ArrayList<>(emergencyNumbers); |
| 9169 | } finally { |
| 9170 | Binder.restoreCallingIdentity(identity); |
| 9171 | } |
| 9172 | } |
| 9173 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9174 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9175 | public int getEmergencyNumberDbVersion(int subId) { |
| 9176 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9177 | |
| 9178 | final long identity = Binder.clearCallingIdentity(); |
| 9179 | try { |
| 9180 | final Phone phone = getPhone(subId); |
| 9181 | if (phone == null) { |
| 9182 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9183 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9184 | } |
| 9185 | return phone.getEmergencyNumberDbVersion(); |
| 9186 | } finally { |
| 9187 | Binder.restoreCallingIdentity(identity); |
| 9188 | } |
| 9189 | } |
| 9190 | |
| 9191 | @Override |
| 9192 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9193 | enforceModifyPermission(); |
| 9194 | |
| 9195 | final long identity = Binder.clearCallingIdentity(); |
| 9196 | try { |
| 9197 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9198 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9199 | if (tracker != null) { |
| 9200 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9201 | } |
| 9202 | } |
| 9203 | } finally { |
| 9204 | Binder.restoreCallingIdentity(identity); |
| 9205 | } |
| 9206 | } |
| 9207 | |
| 9208 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9209 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9210 | enforceActiveEmergencySessionPermission(); |
| 9211 | |
| 9212 | final long identity = Binder.clearCallingIdentity(); |
| 9213 | try { |
| 9214 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9215 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9216 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9217 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9218 | } |
| 9219 | } |
| 9220 | } finally { |
| 9221 | Binder.restoreCallingIdentity(identity); |
| 9222 | } |
| 9223 | } |
| 9224 | |
| 9225 | @Override |
| 9226 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9227 | enforceActiveEmergencySessionPermission(); |
| 9228 | |
| 9229 | final long identity = Binder.clearCallingIdentity(); |
| 9230 | try { |
| 9231 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9232 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9233 | if (tracker != null) { |
| 9234 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9235 | } |
| 9236 | } |
| 9237 | } finally { |
| 9238 | Binder.restoreCallingIdentity(identity); |
| 9239 | } |
| 9240 | } |
| 9241 | |
| 9242 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9243 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9244 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9245 | Phone phone = getPhone(subId); |
| 9246 | if (phone == null) { |
| 9247 | return null; |
| 9248 | } |
| 9249 | final long identity = Binder.clearCallingIdentity(); |
| 9250 | try { |
| 9251 | UiccProfile profile = UiccController.getInstance() |
| 9252 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9253 | if (profile != null) { |
| 9254 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9255 | } |
| 9256 | } finally { |
| 9257 | Binder.restoreCallingIdentity(identity); |
| 9258 | } |
| 9259 | return null; |
| 9260 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9261 | |
| 9262 | /** |
| 9263 | * Enable or disable a modem stack. |
| 9264 | */ |
| 9265 | @Override |
| 9266 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9267 | enforceModifyPermission(); |
| 9268 | |
| 9269 | final long identity = Binder.clearCallingIdentity(); |
| 9270 | try { |
| 9271 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9272 | if (phone == null) { |
| 9273 | return false; |
| 9274 | } else { |
| 9275 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9276 | } |
| 9277 | } finally { |
| 9278 | Binder.restoreCallingIdentity(identity); |
| 9279 | } |
| 9280 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9281 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9282 | /** |
| 9283 | * Whether a modem stack is enabled or not. |
| 9284 | */ |
| 9285 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9286 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9287 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9288 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9289 | if (phone == null) return false; |
| 9290 | |
| 9291 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9292 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9293 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9294 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9295 | } |
| 9296 | |
| 9297 | final long identity = Binder.clearCallingIdentity(); |
| 9298 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9299 | try { |
| 9300 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9301 | } catch (NoSuchElementException ex) { |
| 9302 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9303 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9304 | } finally { |
| 9305 | Binder.restoreCallingIdentity(identity); |
| 9306 | } |
| 9307 | } |
| 9308 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9309 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9310 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9311 | enforceModifyPermission(); |
| 9312 | |
| 9313 | final long identity = Binder.clearCallingIdentity(); |
| 9314 | try { |
| 9315 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9316 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9317 | .commit(); |
| 9318 | } finally { |
| 9319 | Binder.restoreCallingIdentity(identity); |
| 9320 | } |
| 9321 | } |
| 9322 | |
| 9323 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9324 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9325 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9326 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9327 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9328 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9329 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9330 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9331 | |
| 9332 | final long identity = Binder.clearCallingIdentity(); |
| 9333 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9334 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9335 | } finally { |
| 9336 | Binder.restoreCallingIdentity(identity); |
| 9337 | } |
| 9338 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9339 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9340 | @TelephonyManager.IsMultiSimSupportedResult |
| 9341 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9342 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9343 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9344 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9345 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9346 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9347 | } |
| 9348 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9349 | // supported by the modem, indicate that it is restricted. |
| 9350 | PhoneCapability staticCapability = |
| 9351 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9352 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9353 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9354 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9355 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9356 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9357 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9358 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9359 | } |
| 9360 | // Check if support of multiple SIMs is restricted by carrier |
| 9361 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9362 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9363 | } |
| 9364 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9365 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9366 | } |
| 9367 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9368 | /** |
| 9369 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9370 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9371 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9372 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9373 | * @param numOfSims number of active sims we want to switch to |
| 9374 | */ |
| 9375 | @Override |
| 9376 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9377 | if (numOfSims == 1) { |
| 9378 | enforceModifyPermission(); |
| 9379 | } else { |
| 9380 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9381 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9382 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9383 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9384 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9385 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9386 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9387 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9388 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9389 | return; |
| 9390 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9391 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9392 | } finally { |
| 9393 | Binder.restoreCallingIdentity(identity); |
| 9394 | } |
| 9395 | } |
| 9396 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9397 | @Override |
| 9398 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9399 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9400 | Phone phone = getPhone(subId); |
| 9401 | if (phone == null) { |
| 9402 | return false; |
| 9403 | } |
| 9404 | final long identity = Binder.clearCallingIdentity(); |
| 9405 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9406 | UiccPort uiccPort = phone.getUiccPort(); |
| 9407 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9408 | return false; |
| 9409 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9410 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9411 | if (uiccProfile == null) { |
| 9412 | return false; |
| 9413 | } |
| 9414 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9415 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9416 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9417 | } |
| 9418 | return false; |
| 9419 | } finally { |
| 9420 | Binder.restoreCallingIdentity(identity); |
| 9421 | } |
| 9422 | } |
| 9423 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9424 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9425 | * Get whether making changes to modem configurations will trigger reboot. |
| 9426 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9427 | */ |
| 9428 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9429 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9430 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9431 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9432 | mApp, subId, callingPackage, callingFeatureId, |
| 9433 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9434 | return false; |
| 9435 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9436 | final long identity = Binder.clearCallingIdentity(); |
| 9437 | try { |
| 9438 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9439 | } finally { |
| 9440 | Binder.restoreCallingIdentity(identity); |
| 9441 | } |
| 9442 | } |
| 9443 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9444 | private void updateModemStateMetrics() { |
| 9445 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9446 | // TODO: check the state for each modem if the api is ready. |
| 9447 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9448 | } |
| 9449 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9450 | @Override |
| 9451 | public int[] getSlotsMapping() { |
| 9452 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 9453 | |
| 9454 | final long identity = Binder.clearCallingIdentity(); |
| 9455 | try { |
| 9456 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 9457 | // All logical slots should have a mapping to a physical slot. |
| 9458 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 9459 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 9460 | for (int i = 0; i < slotInfos.length; i++) { |
| 9461 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 9462 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 9463 | } |
| 9464 | } |
| 9465 | return logicalSlotsMapping; |
| 9466 | } finally { |
| 9467 | Binder.restoreCallingIdentity(identity); |
| 9468 | } |
| 9469 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9470 | |
| 9471 | /** |
| 9472 | * Get the IRadio HAL Version |
| 9473 | */ |
| 9474 | @Override |
| 9475 | public int getRadioHalVersion() { |
| 9476 | Phone phone = getDefaultPhone(); |
| 9477 | if (phone == null) return -1; |
| 9478 | HalVersion hv = phone.getHalVersion(); |
| 9479 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9480 | return hv.major * 100 + hv.minor; |
| 9481 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9482 | |
| 9483 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9484 | * Get the current calling package name. |
| 9485 | * @return the current calling package name |
| 9486 | */ |
| 9487 | @Override |
| 9488 | public String getCurrentPackageName() { |
| 9489 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9490 | } |
| 9491 | |
| 9492 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9493 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9494 | * corresponding network requests on a subId. |
| 9495 | * |
| 9496 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9497 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9498 | * 2) APN is un-metered for this subscription, or |
| 9499 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9500 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9501 | * |
| 9502 | * @return whether data is allowed for a apn type. |
| 9503 | * |
| 9504 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9505 | */ |
| 9506 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9507 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9508 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9509 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9510 | |
| 9511 | // Now that all security checks passes, perform the operation as ourselves. |
| 9512 | final long identity = Binder.clearCallingIdentity(); |
| 9513 | try { |
| 9514 | Phone phone = getPhone(subId); |
| 9515 | if (phone == null) return false; |
| 9516 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9517 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9518 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9519 | } finally { |
| 9520 | Binder.restoreCallingIdentity(identity); |
| 9521 | } |
| 9522 | } |
| 9523 | |
| 9524 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9525 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9526 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9527 | |
| 9528 | // Now that all security checks passes, perform the operation as ourselves. |
| 9529 | final long identity = Binder.clearCallingIdentity(); |
| 9530 | try { |
| 9531 | Phone phone = getPhone(subId); |
| 9532 | if (phone == null) return true; // By default return true. |
| 9533 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9534 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9535 | } finally { |
| 9536 | Binder.restoreCallingIdentity(identity); |
| 9537 | } |
| 9538 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9539 | |
| 9540 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9541 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9542 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9543 | enforceModifyPermission(); |
| 9544 | long token = Binder.clearCallingIdentity(); |
| 9545 | try { |
| 9546 | Phone phone = getPhone(subscriptionId); |
| 9547 | if (phone == null) { |
| 9548 | try { |
| 9549 | if (resultCallback != null) { |
| 9550 | resultCallback.accept(false); |
| 9551 | } |
| 9552 | } catch (RemoteException e) { |
| 9553 | // ignore |
| 9554 | } |
| 9555 | return; |
| 9556 | } |
| 9557 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9558 | Pair.create(specifiers, (x) -> { |
| 9559 | try { |
| 9560 | if (resultCallback != null) { |
| 9561 | resultCallback.accept(x); |
| 9562 | } |
| 9563 | } catch (RemoteException e) { |
| 9564 | // ignore |
| 9565 | } |
| 9566 | }); |
| 9567 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9568 | } finally { |
| 9569 | Binder.restoreCallingIdentity(token); |
| 9570 | } |
| 9571 | } |
| 9572 | |
| 9573 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9574 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9575 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9576 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9577 | mApp, subId, "getSystemSelectionChannels"); |
| 9578 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9579 | final long identity = Binder.clearCallingIdentity(); |
| 9580 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 9581 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 9582 | if (result instanceof IllegalStateException) { |
| 9583 | throw (IllegalStateException) result; |
| 9584 | } |
| 9585 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9586 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9587 | return specifiers; |
| 9588 | } finally { |
| 9589 | Binder.restoreCallingIdentity(identity); |
| 9590 | } |
| 9591 | } |
| 9592 | |
| 9593 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9594 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9595 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9596 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9597 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9598 | if (iccRecords == null) { |
| 9599 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9600 | return false; |
| 9601 | } |
| 9602 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9603 | } |
| 9604 | |
| 9605 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9606 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9607 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9608 | if (callingPackage == null) { |
| 9609 | callingPackage = getCurrentPackageName(); |
| 9610 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9611 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9612 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9613 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9614 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9615 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9616 | } |
| 9617 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9618 | Intent intent = new Intent(); |
| 9619 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9620 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9621 | // Bring up choose default SMS subscription dialog right now |
| 9622 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9623 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9624 | mApp.startActivity(intent); |
| 9625 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9626 | |
| 9627 | @Override |
| 9628 | public String getMmsUAProfUrl(int subId) { |
| 9629 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9630 | final long identity = Binder.clearCallingIdentity(); |
| 9631 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9632 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9633 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9634 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9635 | return carrierUAProfUrl; |
| 9636 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9637 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9638 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9639 | } finally { |
| 9640 | Binder.restoreCallingIdentity(identity); |
| 9641 | } |
| 9642 | } |
| 9643 | |
| 9644 | @Override |
| 9645 | public String getMmsUserAgent(int subId) { |
| 9646 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9647 | final long identity = Binder.clearCallingIdentity(); |
| 9648 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9649 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9650 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9651 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9652 | return carrierUserAgent; |
| 9653 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9654 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9655 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9656 | } finally { |
| 9657 | Binder.restoreCallingIdentity(identity); |
| 9658 | } |
| 9659 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9660 | |
| 9661 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9662 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9663 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9664 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9665 | final long identity = Binder.clearCallingIdentity(); |
| 9666 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9667 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9668 | if (phone == null) return false; |
| 9669 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9670 | switch (policy) { |
| 9671 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9672 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9673 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9674 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9675 | default: |
| 9676 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9677 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9678 | } finally { |
| 9679 | Binder.restoreCallingIdentity(identity); |
| 9680 | } |
| 9681 | } |
| 9682 | |
| 9683 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9684 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9685 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9686 | enforceModifyPermission(); |
| 9687 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9688 | final long identity = Binder.clearCallingIdentity(); |
| 9689 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9690 | Phone phone = getPhone(subscriptionId); |
| 9691 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9692 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9693 | switch (policy) { |
| 9694 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9695 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9696 | break; |
| 9697 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9698 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9699 | break; |
| 9700 | default: |
| 9701 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9702 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9703 | } finally { |
| 9704 | Binder.restoreCallingIdentity(identity); |
| 9705 | } |
| 9706 | } |
| 9707 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9708 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9709 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9710 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9711 | * otherwise. |
| 9712 | */ |
| 9713 | @Override |
| 9714 | public void setCepEnabled(boolean isCepEnabled) { |
| 9715 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9716 | |
| 9717 | final long identity = Binder.clearCallingIdentity(); |
| 9718 | try { |
| 9719 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9720 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9721 | Phone defaultPhone = phone.getImsPhone(); |
| 9722 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9723 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9724 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9725 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9726 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9727 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9728 | + imsPhone.getMsisdn()); |
| 9729 | } |
| 9730 | } |
| 9731 | } finally { |
| 9732 | Binder.restoreCallingIdentity(identity); |
| 9733 | } |
| 9734 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9735 | |
| 9736 | /** |
| 9737 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9738 | * |
| 9739 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9740 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9741 | * before being read. |
| 9742 | */ |
| 9743 | @Override |
| 9744 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9745 | isCompressed) { |
| 9746 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9747 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9748 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9749 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9750 | } |
| 9751 | if (!isImsAvailableOnDevice()) { |
| 9752 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9753 | "IMS not available on device."); |
| 9754 | } |
| 9755 | |
| 9756 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9757 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9758 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9759 | } finally { |
| 9760 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9761 | } |
| 9762 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9763 | |
| 9764 | @Override |
| 9765 | public boolean isIccLockEnabled(int subId) { |
| 9766 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9767 | |
| 9768 | // Now that all security checks passes, perform the operation as ourselves. |
| 9769 | final long identity = Binder.clearCallingIdentity(); |
| 9770 | try { |
| 9771 | Phone phone = getPhone(subId); |
| 9772 | if (phone != null && phone.getIccCard() != null) { |
| 9773 | return phone.getIccCard().getIccLockEnabled(); |
| 9774 | } else { |
| 9775 | return false; |
| 9776 | } |
| 9777 | } finally { |
| 9778 | Binder.restoreCallingIdentity(identity); |
| 9779 | } |
| 9780 | } |
| 9781 | |
| 9782 | /** |
| 9783 | * Set the ICC pin lock enabled or disabled. |
| 9784 | * |
| 9785 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9786 | * three cases: |
| 9787 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9788 | * successfully. |
| 9789 | * - Positive number and zero for remaining password attempts. |
| 9790 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9791 | * |
| 9792 | */ |
| 9793 | @Override |
| 9794 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9795 | enforceModifyPermission(); |
| 9796 | |
| 9797 | Phone phone = getPhone(subId); |
| 9798 | if (phone == null) { |
| 9799 | return 0; |
| 9800 | } |
| 9801 | // Now that all security checks passes, perform the operation as ourselves. |
| 9802 | final long identity = Binder.clearCallingIdentity(); |
| 9803 | try { |
| 9804 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9805 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9806 | return attemptsRemaining; |
| 9807 | |
| 9808 | } catch (Exception e) { |
| 9809 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9810 | } finally { |
| 9811 | Binder.restoreCallingIdentity(identity); |
| 9812 | } |
| 9813 | return 0; |
| 9814 | } |
| 9815 | |
| 9816 | /** |
| 9817 | * Change the ICC password used in ICC pin lock. |
| 9818 | * |
| 9819 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9820 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9821 | * - Positive number and zero for remaining password attempts. |
| 9822 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9823 | * |
| 9824 | */ |
| 9825 | @Override |
| 9826 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9827 | enforceModifyPermission(); |
| 9828 | |
| 9829 | Phone phone = getPhone(subId); |
| 9830 | if (phone == null) { |
| 9831 | return 0; |
| 9832 | } |
| 9833 | // Now that all security checks passes, perform the operation as ourselves. |
| 9834 | final long identity = Binder.clearCallingIdentity(); |
| 9835 | try { |
| 9836 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9837 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9838 | return attemptsRemaining; |
| 9839 | |
| 9840 | } catch (Exception e) { |
| 9841 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9842 | } finally { |
| 9843 | Binder.restoreCallingIdentity(identity); |
| 9844 | } |
| 9845 | return 0; |
| 9846 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9847 | |
| 9848 | /** |
| 9849 | * Request for receiving user activity notification |
| 9850 | */ |
| 9851 | @Override |
| 9852 | public void requestUserActivityNotification() { |
| 9853 | if (!mNotifyUserActivity.get() |
| 9854 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9855 | mNotifyUserActivity.set(true); |
| 9856 | } |
| 9857 | } |
| 9858 | |
| 9859 | /** |
| 9860 | * Called when userActivity is signalled in the power manager. |
| 9861 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9862 | */ |
| 9863 | @Override |
| 9864 | public void userActivity() { |
| 9865 | // *************************************** |
| 9866 | // * Inherited from PhoneWindowManager * |
| 9867 | // *************************************** |
| 9868 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9869 | // WITH ITS LOCKS HELD. |
| 9870 | // |
| 9871 | // This code must be VERY careful about the locks |
| 9872 | // it acquires. |
| 9873 | // In fact, the current code acquires way too many, |
| 9874 | // and probably has lurking deadlocks. |
| 9875 | |
| 9876 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9877 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9878 | } |
| 9879 | |
| 9880 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9881 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9882 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9883 | } |
| 9884 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9885 | |
| 9886 | @Override |
| 9887 | public boolean canConnectTo5GInDsdsMode() { |
| 9888 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9889 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9890 | |
| 9891 | @Override |
| 9892 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9893 | String callingFeatureId) { |
| 9894 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9895 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9896 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9897 | } |
| 9898 | |
| 9899 | Phone phone = getPhone(subId); |
| 9900 | if (phone == null) { |
| 9901 | throw new RuntimeException("phone is not available"); |
| 9902 | } |
| 9903 | // Now that all security checks passes, perform the operation as ourselves. |
| 9904 | final long identity = Binder.clearCallingIdentity(); |
| 9905 | try { |
| 9906 | return phone.getEquivalentHomePlmns(); |
| 9907 | } finally { |
| 9908 | Binder.restoreCallingIdentity(identity); |
| 9909 | } |
| 9910 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9911 | |
| 9912 | @Override |
| 9913 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 9914 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 9915 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 9916 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9917 | if (radioInterfaceCapabilities == null) { |
| 9918 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9919 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 9920 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9921 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9922 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9923 | @Override |
| 9924 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9925 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9926 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 9927 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9928 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 9929 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9930 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9931 | if (DBG) { |
| 9932 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9933 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9934 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9935 | } |
| 9936 | |
| 9937 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9938 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9939 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9940 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9941 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9942 | if (callback != null) { |
| 9943 | try { |
| 9944 | callback.onAuthenticationFailure( |
| 9945 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9946 | } catch (RemoteException exception) { |
| 9947 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9948 | } |
| 9949 | return; |
| 9950 | } |
| 9951 | } |
| 9952 | |
| 9953 | final long token = Binder.clearCallingIdentity(); |
| 9954 | try { |
| 9955 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9956 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9957 | forceBootStrapping, callback)); |
| 9958 | } finally { |
| 9959 | Binder.restoreCallingIdentity(token); |
| 9960 | } |
| 9961 | } |
| 9962 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9963 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 9964 | * Attempts to set the radio power state for all phones for thermal reason. |
| 9965 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9966 | * requested radio power state will actually be set. See {@link |
| 9967 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9968 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9969 | * @param enable {@code true} if trying to turn radio on. |
| 9970 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9971 | * false}. |
| 9972 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 9973 | private boolean setRadioPowerForThermal(boolean enable) { |
| 9974 | boolean isPhoneAvailable = false; |
| 9975 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 9976 | Phone phone = PhoneFactory.getPhone(i); |
| 9977 | if (phone != null) { |
| 9978 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9979 | isPhoneAvailable = true; |
| 9980 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9981 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 9982 | |
| 9983 | // return true if successfully informed the phone object about the thermal radio power |
| 9984 | // request. |
| 9985 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9986 | } |
| 9987 | |
| 9988 | private int handleDataThrottlingRequest(int subId, |
| 9989 | DataThrottlingRequest dataThrottlingRequest) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 9990 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 9991 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 9992 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 9993 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 9994 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 9995 | } |
| 9996 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9997 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9998 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 9999 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10000 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10001 | } |
| 10002 | |
| 10003 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 10004 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10005 | if (isDataThrottlingSupported) { |
| 10006 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10007 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10008 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10009 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10010 | } else if (thermalMitigationResult |
| 10011 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10012 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10013 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10014 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10015 | } |
| 10016 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10017 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10018 | |
| 10019 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10020 | } |
| 10021 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10022 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10023 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10024 | for (String pckg : context.getResources() |
| 10025 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10026 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10027 | } |
| 10028 | } |
| 10029 | |
| 10030 | return sThermalMitigationAllowlistedPackages; |
| 10031 | } |
| 10032 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10033 | private boolean isAnyPhoneInEmergencyState() { |
| 10034 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10035 | if (tm.isInEmergencyCall()) { |
| 10036 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10037 | return true; |
| 10038 | } |
| 10039 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10040 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10041 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10042 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10043 | + phone.isInEcm()); |
| 10044 | return true; |
| 10045 | } |
| 10046 | } |
| 10047 | |
| 10048 | return false; |
| 10049 | } |
| 10050 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10051 | /** |
| 10052 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10053 | * @param packageName name of package to be allowlisted |
| 10054 | * @param context |
| 10055 | */ |
| 10056 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10057 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10058 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10059 | } |
| 10060 | |
| 10061 | /** |
| 10062 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10063 | * @param packageName name of package to remove from allowlist |
| 10064 | * @param context |
| 10065 | */ |
| 10066 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10067 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10068 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10069 | } |
| 10070 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10071 | /** |
| 10072 | * Thermal mitigation request to control functionalities at modem. |
| 10073 | * |
| 10074 | * @param subId the id of the subscription. |
| 10075 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10076 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10077 | * |
| 10078 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10079 | */ |
| 10080 | @Override |
| 10081 | @ThermalMitigationResult |
| 10082 | public int sendThermalMitigationRequest( |
| 10083 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10084 | ThermalMitigationRequest thermalMitigationRequest, |
| 10085 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10086 | enforceModifyPermission(); |
| 10087 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10088 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10089 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10090 | .contains(callingPackage)) { |
| 10091 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10092 | + "calling package: " + callingPackage); |
| 10093 | } |
| 10094 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10095 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10096 | final long identity = Binder.clearCallingIdentity(); |
| 10097 | |
| 10098 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10099 | try { |
| 10100 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10101 | switch (thermalMitigationAction) { |
| 10102 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10103 | thermalMitigationResult = |
| 10104 | handleDataThrottlingRequest(subId, |
| 10105 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 10106 | break; |
| 10107 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10108 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10109 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10110 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10111 | } |
| 10112 | |
| 10113 | // Ensure that radio is on. If not able to power on due to phone being |
| 10114 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10115 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10116 | thermalMitigationResult = |
| 10117 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10118 | break; |
| 10119 | } |
| 10120 | |
| 10121 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 10122 | false); |
| 10123 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10124 | break; |
| 10125 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10126 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10127 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10128 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10129 | } |
| 10130 | |
| 10131 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10132 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10133 | Phone phone = getPhone(subId); |
| 10134 | if (phone == null) { |
| 10135 | thermalMitigationResult = |
| 10136 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10137 | break; |
| 10138 | } |
| 10139 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10140 | TelephonyConnectionService service = |
| 10141 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10142 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10143 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10144 | thermalMitigationResult = |
| 10145 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10146 | break; |
| 10147 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10148 | thermalMitigationResult = |
| 10149 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10150 | break; |
| 10151 | } |
| 10152 | } else { |
| 10153 | thermalMitigationResult = |
| 10154 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10155 | break; |
| 10156 | } |
| 10157 | |
| 10158 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10159 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10160 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10161 | thermalMitigationResult = |
| 10162 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10163 | break; |
| 10164 | } |
| 10165 | thermalMitigationResult = |
| 10166 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10167 | break; |
| 10168 | default: |
| 10169 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10170 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10171 | } |
| 10172 | } catch (IllegalArgumentException e) { |
| 10173 | throw e; |
| 10174 | } catch (Exception e) { |
| 10175 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10176 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10177 | } finally { |
| 10178 | Binder.restoreCallingIdentity(identity); |
| 10179 | } |
| 10180 | |
| 10181 | if (DBG) { |
| 10182 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10183 | + thermalMitigationResult); |
| 10184 | } |
| 10185 | |
| 10186 | return thermalMitigationResult; |
| 10187 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10188 | |
| 10189 | /** |
| 10190 | * Set the GbaService Package Name that Telephony will bind to. |
| 10191 | * |
| 10192 | * @param subId The sim that the GbaService is associated with. |
| 10193 | * @param packageName The name of the package to be replaced with. |
| 10194 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10195 | */ |
| 10196 | @Override |
| 10197 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10198 | enforceModifyPermission(); |
| 10199 | |
| 10200 | final long identity = Binder.clearCallingIdentity(); |
| 10201 | try { |
| 10202 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10203 | } finally { |
| 10204 | Binder.restoreCallingIdentity(identity); |
| 10205 | } |
| 10206 | } |
| 10207 | |
| 10208 | /** |
| 10209 | * Return the package name of the currently bound GbaService. |
| 10210 | * |
| 10211 | * @param subId The sim that the GbaService is associated with. |
| 10212 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10213 | */ |
| 10214 | @Override |
| 10215 | public String getBoundGbaService(int subId) { |
| 10216 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10217 | |
| 10218 | final long identity = Binder.clearCallingIdentity(); |
| 10219 | try { |
| 10220 | return getGbaManager(subId).getServicePackage(); |
| 10221 | } finally { |
| 10222 | Binder.restoreCallingIdentity(identity); |
| 10223 | } |
| 10224 | } |
| 10225 | |
| 10226 | /** |
| 10227 | * Set the release time for telephony to unbind GbaService. |
| 10228 | * |
| 10229 | * @param subId The sim that the GbaService is associated with. |
| 10230 | * @param interval The release time to unbind GbaService by millisecond. |
| 10231 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10232 | */ |
| 10233 | @Override |
| 10234 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10235 | enforceModifyPermission(); |
| 10236 | |
| 10237 | final long identity = Binder.clearCallingIdentity(); |
| 10238 | try { |
| 10239 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10240 | } finally { |
| 10241 | Binder.restoreCallingIdentity(identity); |
| 10242 | } |
| 10243 | } |
| 10244 | |
| 10245 | /** |
| 10246 | * Return the release time for telephony to unbind GbaService. |
| 10247 | * |
| 10248 | * @param subId The sim that the GbaService is associated with. |
| 10249 | * @return The release time to unbind GbaService by millisecond. |
| 10250 | */ |
| 10251 | @Override |
| 10252 | public int getGbaReleaseTime(int subId) { |
| 10253 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10254 | |
| 10255 | final long identity = Binder.clearCallingIdentity(); |
| 10256 | try { |
| 10257 | return getGbaManager(subId).getReleaseTime(); |
| 10258 | } finally { |
| 10259 | Binder.restoreCallingIdentity(identity); |
| 10260 | } |
| 10261 | } |
| 10262 | |
| 10263 | private GbaManager getGbaManager(int subId) { |
| 10264 | GbaManager instance = GbaManager.getInstance(subId); |
| 10265 | if (instance == null) { |
| 10266 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10267 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10268 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10269 | } |
| 10270 | return instance; |
| 10271 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10272 | |
| 10273 | /** |
| 10274 | * indicate whether the device and the carrier can support |
| 10275 | * RCS VoLTE single registration. |
| 10276 | */ |
| 10277 | @Override |
| 10278 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10279 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10280 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10281 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10282 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10283 | |
| 10284 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10285 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10286 | } |
| 10287 | |
| 10288 | final long identity = Binder.clearCallingIdentity(); |
| 10289 | try { |
| 10290 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10291 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10292 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10293 | if (isCapable != null) { |
| 10294 | return isCapable; |
| 10295 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10296 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10297 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10298 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10299 | } finally { |
| 10300 | Binder.restoreCallingIdentity(identity); |
| 10301 | } |
| 10302 | } |
| 10303 | |
| 10304 | /** |
| 10305 | * Register RCS provisioning callback. |
| 10306 | */ |
| 10307 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10308 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10309 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10310 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10311 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10312 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10313 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10314 | |
| 10315 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10316 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10317 | } |
| 10318 | if (!isImsAvailableOnDevice()) { |
| 10319 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10320 | "IMS not available on device."); |
| 10321 | } |
| 10322 | |
| 10323 | final long identity = Binder.clearCallingIdentity(); |
| 10324 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10325 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10326 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10327 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10328 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10329 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10330 | } finally { |
| 10331 | Binder.restoreCallingIdentity(identity); |
| 10332 | } |
| 10333 | } |
| 10334 | |
| 10335 | /** |
| 10336 | * Unregister RCS provisioning callback. |
| 10337 | */ |
| 10338 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10339 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10340 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10341 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10342 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10343 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10344 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10345 | |
| 10346 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10347 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10348 | } |
| 10349 | if (!isImsAvailableOnDevice()) { |
| 10350 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10351 | "IMS not available on device."); |
| 10352 | } |
| 10353 | |
| 10354 | final long identity = Binder.clearCallingIdentity(); |
| 10355 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10356 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10357 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10358 | } finally { |
| 10359 | Binder.restoreCallingIdentity(identity); |
| 10360 | } |
| 10361 | } |
| 10362 | |
| 10363 | /** |
| 10364 | * trigger RCS reconfiguration. |
| 10365 | */ |
| 10366 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10367 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10368 | "triggerRcsReconfiguration", |
| 10369 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10370 | |
| 10371 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10372 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10373 | } |
| 10374 | if (!isImsAvailableOnDevice()) { |
| 10375 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10376 | "IMS not available on device."); |
| 10377 | } |
| 10378 | |
| 10379 | final long identity = Binder.clearCallingIdentity(); |
| 10380 | try { |
| 10381 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10382 | } finally { |
| 10383 | Binder.restoreCallingIdentity(identity); |
| 10384 | } |
| 10385 | } |
| 10386 | |
| 10387 | /** |
| 10388 | * Provide the client configuration parameters of the RCS application. |
| 10389 | */ |
| 10390 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10391 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10392 | "setRcsClientConfiguration", |
| 10393 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10394 | |
| 10395 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10396 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10397 | } |
| 10398 | if (!isImsAvailableOnDevice()) { |
| 10399 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10400 | "IMS not available on device."); |
| 10401 | } |
| 10402 | |
| 10403 | final long identity = Binder.clearCallingIdentity(); |
| 10404 | |
| 10405 | try { |
| 10406 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10407 | if (configBinder == null) { |
| 10408 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10409 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10410 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10411 | } else { |
| 10412 | configBinder.setRcsClientConfiguration(rcc); |
| 10413 | } |
| 10414 | } catch (RemoteException e) { |
| 10415 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10416 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10417 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10418 | } finally { |
| 10419 | Binder.restoreCallingIdentity(identity); |
| 10420 | } |
| 10421 | } |
| 10422 | |
| 10423 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10424 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10425 | */ |
| 10426 | @Override |
| 10427 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10428 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10429 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10430 | |
| 10431 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10432 | } |
| 10433 | |
| 10434 | /** |
| 10435 | * Gets the test mode for RCS VoLTE single registration. |
| 10436 | */ |
| 10437 | @Override |
| 10438 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10439 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10440 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10441 | |
| 10442 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10443 | } |
| 10444 | |
| 10445 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10446 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10447 | */ |
| 10448 | @Override |
| 10449 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10450 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10451 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10452 | enforceModifyPermission(); |
| 10453 | |
| 10454 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10455 | : Boolean.parseBoolean(enabledStr); |
| 10456 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10457 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10458 | } |
| 10459 | |
| 10460 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10461 | * Sends a device to device communication message. Only usable via shell. |
| 10462 | * @param message message to send. |
| 10463 | * @param value message value. |
| 10464 | */ |
| 10465 | @Override |
| 10466 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10467 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10468 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10469 | enforceModifyPermission(); |
| 10470 | |
| 10471 | final long identity = Binder.clearCallingIdentity(); |
| 10472 | try { |
| 10473 | TelephonyConnectionService service = |
| 10474 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10475 | if (service == null) { |
| 10476 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10477 | return; |
| 10478 | } |
| 10479 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10480 | } finally { |
| 10481 | Binder.restoreCallingIdentity(identity); |
| 10482 | } |
| 10483 | } |
| 10484 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10485 | /** |
| 10486 | * Sets the specified device to device transport active. |
| 10487 | * @param transport The transport to set active. |
| 10488 | */ |
| 10489 | @Override |
| 10490 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10491 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10492 | "setActiveDeviceToDeviceTransport"); |
| 10493 | enforceModifyPermission(); |
| 10494 | |
| 10495 | final long identity = Binder.clearCallingIdentity(); |
| 10496 | try { |
| 10497 | TelephonyConnectionService service = |
| 10498 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10499 | if (service == null) { |
| 10500 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10501 | return; |
| 10502 | } |
| 10503 | service.setActiveDeviceToDeviceTransport(transport); |
| 10504 | } finally { |
| 10505 | Binder.restoreCallingIdentity(identity); |
| 10506 | } |
| 10507 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10508 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10509 | @Override |
| 10510 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10511 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10512 | "setDeviceToDeviceForceEnabled"); |
| 10513 | |
| 10514 | final long identity = Binder.clearCallingIdentity(); |
| 10515 | try { |
| 10516 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10517 | p -> { |
| 10518 | Phone thePhone = p.getImsPhone(); |
| 10519 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10520 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10521 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10522 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10523 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10524 | (ImsPhoneCallTracker) tracker; |
| 10525 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10526 | } |
| 10527 | } |
| 10528 | } |
| 10529 | ); |
| 10530 | } finally { |
| 10531 | Binder.restoreCallingIdentity(identity); |
| 10532 | } |
| 10533 | } |
| 10534 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10535 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10536 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10537 | */ |
| 10538 | @Override |
| 10539 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10540 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10541 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10542 | } |
| 10543 | |
| 10544 | /** |
| 10545 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10546 | */ |
| 10547 | @Override |
| 10548 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10549 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10550 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10551 | enforceModifyPermission(); |
| 10552 | |
| 10553 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10554 | : Boolean.parseBoolean(enabledStr); |
| 10555 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10556 | subId, enabled); |
| 10557 | } |
| 10558 | |
| 10559 | /** |
| 10560 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10561 | */ |
| 10562 | @Override |
| 10563 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10564 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10565 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10566 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10567 | |
| 10568 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 10569 | * Overrides the ims feature validation result |
| 10570 | */ |
| 10571 | @Override |
| 10572 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 10573 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10574 | "setImsFeatureValidationOverride"); |
| 10575 | |
| 10576 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10577 | : Boolean.parseBoolean(enabledStr); |
| 10578 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 10579 | subId, enabled); |
| 10580 | } |
| 10581 | |
| 10582 | /** |
| 10583 | * Gets the ims feature validation override value |
| 10584 | */ |
| 10585 | @Override |
| 10586 | public boolean getImsFeatureValidationOverride(int subId) { |
| 10587 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10588 | "getImsFeatureValidationOverride"); |
| 10589 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 10590 | } |
| 10591 | |
| 10592 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10593 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10594 | * their mobile plan. |
| 10595 | */ |
| 10596 | @Override |
| 10597 | public String getMobileProvisioningUrl() { |
| 10598 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10599 | final long identity = Binder.clearCallingIdentity(); |
| 10600 | try { |
| 10601 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10602 | } finally { |
| 10603 | Binder.restoreCallingIdentity(identity); |
| 10604 | } |
| 10605 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10606 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10607 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10608 | * Get the EAB contact from the EAB database. |
| 10609 | */ |
| 10610 | @Override |
| 10611 | public String getContactFromEab(String contact) { |
| 10612 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10613 | enforceModifyPermission(); |
| 10614 | final long identity = Binder.clearCallingIdentity(); |
| 10615 | try { |
| 10616 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10617 | } finally { |
| 10618 | Binder.restoreCallingIdentity(identity); |
| 10619 | } |
| 10620 | } |
| 10621 | |
| 10622 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 10623 | * Get the EAB capability from the EAB database. |
| 10624 | */ |
| 10625 | @Override |
| 10626 | public String getCapabilityFromEab(String contact) { |
| 10627 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 10628 | enforceModifyPermission(); |
| 10629 | final long identity = Binder.clearCallingIdentity(); |
| 10630 | try { |
| 10631 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 10632 | } finally { |
| 10633 | Binder.restoreCallingIdentity(identity); |
| 10634 | } |
| 10635 | } |
| 10636 | |
| 10637 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10638 | * Remove the EAB contacts from the EAB database. |
| 10639 | */ |
| 10640 | @Override |
| 10641 | public int removeContactFromEab(int subId, String contacts) { |
| 10642 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10643 | enforceModifyPermission(); |
| 10644 | final long identity = Binder.clearCallingIdentity(); |
| 10645 | try { |
| 10646 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10647 | } finally { |
| 10648 | Binder.restoreCallingIdentity(identity); |
| 10649 | } |
| 10650 | } |
| 10651 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10652 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10653 | public boolean getDeviceUceEnabled() { |
| 10654 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10655 | final long identity = Binder.clearCallingIdentity(); |
| 10656 | try { |
| 10657 | return mApp.getDeviceUceEnabled(); |
| 10658 | } finally { |
| 10659 | Binder.restoreCallingIdentity(identity); |
| 10660 | } |
| 10661 | } |
| 10662 | |
| 10663 | @Override |
| 10664 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10665 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10666 | final long identity = Binder.clearCallingIdentity(); |
| 10667 | try { |
| 10668 | mApp.setDeviceUceEnabled(isEnabled); |
| 10669 | } finally { |
| 10670 | Binder.restoreCallingIdentity(identity); |
| 10671 | } |
| 10672 | } |
| 10673 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10674 | /** |
| 10675 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10676 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10677 | */ |
| 10678 | // Used for SHELL command only right now. |
| 10679 | @Override |
| 10680 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 10681 | List<String> featureTags) { |
| 10682 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10683 | "addUceRegistrationOverrideShell"); |
| 10684 | final long identity = Binder.clearCallingIdentity(); |
| 10685 | try { |
| 10686 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 10687 | new ArraySet<>(featureTags)); |
| 10688 | } catch (ImsException e) { |
| 10689 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10690 | } finally { |
| 10691 | Binder.restoreCallingIdentity(identity); |
| 10692 | } |
| 10693 | } |
| 10694 | |
| 10695 | /** |
| 10696 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10697 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10698 | */ |
| 10699 | // Used for SHELL command only right now. |
| 10700 | @Override |
| 10701 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 10702 | List<String> featureTags) { |
| 10703 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10704 | "removeUceRegistrationOverrideShell"); |
| 10705 | final long identity = Binder.clearCallingIdentity(); |
| 10706 | try { |
| 10707 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 10708 | new ArraySet<>(featureTags)); |
| 10709 | } catch (ImsException e) { |
| 10710 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10711 | } finally { |
| 10712 | Binder.restoreCallingIdentity(identity); |
| 10713 | } |
| 10714 | } |
| 10715 | |
| 10716 | /** |
| 10717 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 10718 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10719 | */ |
| 10720 | // Used for SHELL command only right now. |
| 10721 | @Override |
| 10722 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 10723 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10724 | "clearUceRegistrationOverrideShell"); |
| 10725 | final long identity = Binder.clearCallingIdentity(); |
| 10726 | try { |
| 10727 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 10728 | } catch (ImsException e) { |
| 10729 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10730 | } finally { |
| 10731 | Binder.restoreCallingIdentity(identity); |
| 10732 | } |
| 10733 | } |
| 10734 | |
| 10735 | /** |
| 10736 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10737 | */ |
| 10738 | // Used for SHELL command only right now. |
| 10739 | @Override |
| 10740 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 10741 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10742 | "getLatestRcsContactUceCapabilityShell"); |
| 10743 | final long identity = Binder.clearCallingIdentity(); |
| 10744 | try { |
| 10745 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 10746 | } catch (ImsException e) { |
| 10747 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10748 | } finally { |
| 10749 | Binder.restoreCallingIdentity(identity); |
| 10750 | } |
| 10751 | } |
| 10752 | |
| 10753 | /** |
| 10754 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 10755 | * device does not have an active PUBLISH. |
| 10756 | */ |
| 10757 | // Used for SHELL command only right now. |
| 10758 | @Override |
| 10759 | public String getLastUcePidfXmlShell(int subId) { |
| 10760 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 10761 | final long identity = Binder.clearCallingIdentity(); |
| 10762 | try { |
| 10763 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 10764 | } catch (ImsException e) { |
| 10765 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10766 | } finally { |
| 10767 | Binder.restoreCallingIdentity(identity); |
| 10768 | } |
| 10769 | } |
| 10770 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 10771 | /** |
| 10772 | * Remove UCE requests cannot be sent to the network status. |
| 10773 | */ |
| 10774 | // Used for SHELL command only right now. |
| 10775 | @Override |
| 10776 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 10777 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 10778 | final long identity = Binder.clearCallingIdentity(); |
| 10779 | try { |
| 10780 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 10781 | } catch (ImsException e) { |
| 10782 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10783 | } finally { |
| 10784 | Binder.restoreCallingIdentity(identity); |
| 10785 | } |
| 10786 | } |
| 10787 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 10788 | /** |
| 10789 | * Remove UCE requests cannot be sent to the network status. |
| 10790 | */ |
| 10791 | // Used for SHELL command only. |
| 10792 | @Override |
| 10793 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 10794 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 10795 | final long identity = Binder.clearCallingIdentity(); |
| 10796 | try { |
| 10797 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 10798 | } catch (ImsException e) { |
| 10799 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10800 | } finally { |
| 10801 | Binder.restoreCallingIdentity(identity); |
| 10802 | } |
| 10803 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10804 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10805 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10806 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10807 | String callingPackage) { |
| 10808 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10809 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 10810 | |
| 10811 | final int callingUid = Binder.getCallingUid(); |
| 10812 | // Verify that tha callingPackage belongs to the calling UID |
| 10813 | mApp.getSystemService(AppOpsManager.class) |
| 10814 | .checkPackage(callingUid, callingPackage); |
| 10815 | |
| 10816 | validateSignalStrengthUpdateRequest(request, callingUid); |
| 10817 | |
| 10818 | final long identity = Binder.clearCallingIdentity(); |
| 10819 | try { |
| 10820 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10821 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10822 | |
| 10823 | if (result instanceof IllegalStateException) { |
| 10824 | throw (IllegalStateException) result; |
| 10825 | } |
| 10826 | } finally { |
| 10827 | Binder.restoreCallingIdentity(identity); |
| 10828 | } |
| 10829 | } |
| 10830 | |
| 10831 | @Override |
| 10832 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10833 | String callingPackage) { |
| 10834 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10835 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 10836 | |
| 10837 | final int callingUid = Binder.getCallingUid(); |
| 10838 | // Verify that tha callingPackage belongs to the calling UID |
| 10839 | mApp.getSystemService(AppOpsManager.class) |
| 10840 | .checkPackage(callingUid, callingPackage); |
| 10841 | |
| 10842 | final long identity = Binder.clearCallingIdentity(); |
| 10843 | try { |
| 10844 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10845 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10846 | |
| 10847 | if (result instanceof IllegalStateException) { |
| 10848 | throw (IllegalStateException) result; |
| 10849 | } |
| 10850 | } finally { |
| 10851 | Binder.restoreCallingIdentity(identity); |
| 10852 | } |
| 10853 | } |
| 10854 | |
| 10855 | private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request, |
| 10856 | int callingUid) { |
| 10857 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 10858 | // phone/system process do not have further restriction on request |
| 10859 | return; |
| 10860 | } |
| 10861 | |
| 10862 | // Applications has restrictions on how to use the request: |
| 10863 | // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle |
| 10864 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
| 10865 | // This is not system caller which has been checked above |
| 10866 | throw new IllegalArgumentException( |
| 10867 | "Only system can set isSystemThresholdReportingRequestedWhileIdle"); |
| 10868 | } |
| 10869 | |
| 10870 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 10871 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 10872 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 10873 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 10874 | || info.isEnabled()) { |
| 10875 | throw new IllegalArgumentException( |
| 10876 | "Only system can set hide fields in SignalThresholdInfo"); |
| 10877 | } |
| 10878 | |
| 10879 | // Thresholds length for each RAN need in range. This has been validated in |
| 10880 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 10881 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 10882 | final int[] thresholds = info.getThresholds(); |
| 10883 | Objects.requireNonNull(thresholds); |
| 10884 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 10885 | || thresholds.length |
| 10886 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 10887 | throw new IllegalArgumentException( |
| 10888 | "thresholds length is out of range: " + thresholds.length); |
| 10889 | } |
| 10890 | } |
| 10891 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10892 | |
| 10893 | /** |
| 10894 | * Gets the current phone capability. |
| 10895 | * |
| 10896 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 10897 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 10898 | * It's used to evaluate possible phone config change, for example from single |
| 10899 | * SIM device to multi-SIM device. |
| 10900 | */ |
| 10901 | @Override |
| 10902 | public PhoneCapability getPhoneCapability() { |
| 10903 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 10904 | final long identity = Binder.clearCallingIdentity(); |
| 10905 | try { |
| 10906 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 10907 | } finally { |
| 10908 | Binder.restoreCallingIdentity(identity); |
| 10909 | } |
| 10910 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 10911 | |
| 10912 | /** |
| 10913 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 10914 | * required to be done shortly after the API is invoked. |
| 10915 | */ |
| 10916 | @Override |
| 10917 | @TelephonyManager.PrepareUnattendedRebootResult |
| 10918 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 10919 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 10920 | enforceRebootPermission(); |
| 10921 | |
| 10922 | final long identity = Binder.clearCallingIdentity(); |
| 10923 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 10924 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 10925 | } finally { |
| 10926 | Binder.restoreCallingIdentity(identity); |
| 10927 | } |
| 10928 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 10929 | |
| 10930 | /** |
| 10931 | * Request to get the current slicing configuration including URSP rules and |
| 10932 | * NSSAIs (configured, allowed and rejected). |
| 10933 | * |
| 10934 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 10935 | */ |
| 10936 | @Override |
| 10937 | public void getSlicingConfig(ResultReceiver callback) { |
| 10938 | enforceReadPrivilegedPermission("getSlicingConfig"); |
| 10939 | |
| 10940 | final long identity = Binder.clearCallingIdentity(); |
| 10941 | try { |
| 10942 | Phone phone = getDefaultPhone(); |
| 10943 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 10944 | } finally { |
| 10945 | Binder.restoreCallingIdentity(identity); |
| 10946 | } |
| 10947 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 10948 | } |