Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| 20 | |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 22 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 23 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 24 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 25 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 26 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 27 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 28 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 29 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 30 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 31 | import android.app.PendingIntent; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 32 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 33 | import android.app.role.RoleManager; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 34 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 35 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 36 | import android.content.Context; |
| 37 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 38 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 39 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 40 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 41 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.net.Uri; |
| 43 | import android.os.AsyncResult; |
| 44 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 45 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 46 | import android.os.Bundle; |
| 47 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 48 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 49 | import android.os.Looper; |
| 50 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 51 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 52 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 53 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 54 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 55 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 56 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 57 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 58 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 59 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 60 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 61 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 62 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 63 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 64 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 65 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 66 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 67 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 68 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 69 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 70 | import android.telecom.TelecomManager; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 71 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 72 | import android.telephony.Annotation.ThermalMitigationResult; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 73 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 74 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 75 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 76 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 77 | import android.telephony.CellIdentityCdma; |
| 78 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 79 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 80 | import android.telephony.CellInfoGsm; |
| 81 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 82 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 83 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 84 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 85 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 86 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 87 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 88 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 89 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 90 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 91 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 92 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 93 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 94 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 95 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 96 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 97 | import android.telephony.SignalStrengthUpdateRequest; |
| 98 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 99 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 100 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 101 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 102 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 103 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 104 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 105 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 106 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 107 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 108 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 109 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 110 | import android.telephony.data.ApnSetting; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 111 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 112 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 113 | import android.telephony.gba.GbaAuthRequest; |
| 114 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 115 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 116 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 117 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 118 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 119 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 120 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 121 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 122 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 123 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 124 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 125 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 126 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 127 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 128 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 129 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 130 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 131 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 132 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 133 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 134 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 135 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 136 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 137 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 138 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 139 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 140 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 141 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d457521 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.CallTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 145 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
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; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 192 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 193 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 194 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 195 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 196 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 197 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 198 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 199 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 200 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 201 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 202 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 203 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 204 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 205 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 206 | import com.android.services.telephony.TelecomAccountRegistry; |
| 207 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 208 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 209 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 210 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 211 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 212 | import java.io.IOException; |
| 213 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 214 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 215 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 216 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 217 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 218 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 219 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 220 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 221 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 222 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 223 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 224 | import java.util.Set; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 225 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 226 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 227 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 228 | |
| 229 | /** |
| 230 | * Implementation of the ITelephony interface. |
| 231 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 232 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 233 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 234 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 235 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 236 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 237 | |
| 238 | // Message codes used with mMainThreadHandler |
| 239 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 240 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 241 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 242 | private static final int CMD_OPEN_CHANNEL = 9; |
| 243 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 244 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 245 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 246 | private static final int CMD_NV_READ_ITEM = 13; |
| 247 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 248 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 249 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 250 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 251 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 252 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 253 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 254 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 255 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 256 | private static final int CMD_SEND_ENVELOPE = 25; |
| 257 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 258 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 259 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 260 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 261 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 262 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 263 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 264 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 265 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 266 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 267 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 268 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 269 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 270 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 271 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 272 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 273 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 274 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 275 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 276 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 277 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 278 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 279 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 280 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 281 | private static final int CMD_SWITCH_SLOTS = 50; |
| 282 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 283 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 284 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 285 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 286 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 287 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 288 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 289 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 290 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 291 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 292 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 293 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 294 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 295 | private static final int CMD_MODEM_REBOOT = 64; |
| 296 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 297 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 298 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 299 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 300 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 301 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 302 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 303 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 304 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 305 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 306 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 307 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 308 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 309 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 310 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 311 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 312 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 313 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 314 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 315 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 316 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 317 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 318 | private static final int CMD_GET_CALL_WAITING = 87; |
| 319 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 320 | private static final int CMD_SET_CALL_WAITING = 89; |
| 321 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 322 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 323 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 324 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 325 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 326 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 327 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 328 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 329 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 330 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 331 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 332 | private static final int CMD_SET_SIM_POWER = 101; |
| 333 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 334 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 335 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 336 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 337 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 338 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 339 | 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] | 340 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 341 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 342 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 343 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 344 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 345 | // Parameters of select command. |
| 346 | private static final int SELECT_COMMAND = 0xA4; |
| 347 | private static final int SELECT_P1 = 0x04; |
| 348 | private static final int SELECT_P2 = 0; |
| 349 | private static final int SELECT_P3 = 0x10; |
| 350 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 351 | /** The singleton instance. */ |
| 352 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 353 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 354 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 355 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 356 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 357 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 358 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 359 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 360 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 361 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 362 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 363 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 364 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 365 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 366 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 367 | /** User Activity */ |
| 368 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 369 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 370 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 371 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 372 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 373 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 374 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 375 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 376 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 377 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 378 | // String to store multi SIM allowed |
| 379 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 380 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 381 | // The AID of ISD-R. |
| 382 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 383 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 384 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 385 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 386 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 387 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 388 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 389 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 390 | 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] | 391 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 392 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 393 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 394 | */ |
| 395 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 396 | "reset_network_erase_modem_config_enabled"; |
| 397 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 398 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds |
| 399 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 400 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 401 | * A request object to use for transmitting data to an ICC. |
| 402 | */ |
| 403 | private static final class IccAPDUArgument { |
| 404 | public int channel, cla, command, p1, p2, p3; |
| 405 | public String data; |
| 406 | |
| 407 | public IccAPDUArgument(int channel, int cla, int command, |
| 408 | int p1, int p2, int p3, String data) { |
| 409 | this.channel = channel; |
| 410 | this.cla = cla; |
| 411 | this.command = command; |
| 412 | this.p1 = p1; |
| 413 | this.p2 = p2; |
| 414 | this.p3 = p3; |
| 415 | this.data = data; |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 420 | * A request object to use for transmitting data to an ICC. |
| 421 | */ |
| 422 | private static final class ManualNetworkSelectionArgument { |
| 423 | public OperatorInfo operatorInfo; |
| 424 | public boolean persistSelection; |
| 425 | |
| 426 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 427 | this.operatorInfo = operatorInfo; |
| 428 | this.persistSelection = persistSelection; |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 433 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 434 | * request after sending. The main thread will notify the request when it is complete. |
| 435 | */ |
| 436 | private static final class MainThreadRequest { |
| 437 | /** The argument to use for the request */ |
| 438 | public Object argument; |
| 439 | /** The result of the request that is run on the main thread */ |
| 440 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 441 | // The subscriber id that this request applies to. Defaults to |
| 442 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 443 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 444 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 445 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 446 | public Phone phone; |
| 447 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 448 | public WorkSource workSource; |
| 449 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 450 | public MainThreadRequest(Object argument) { |
| 451 | this.argument = argument; |
| 452 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 453 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 454 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 455 | this.argument = argument; |
| 456 | if (phone != null) { |
| 457 | this.phone = phone; |
| 458 | } |
| 459 | this.workSource = workSource; |
| 460 | } |
| 461 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 462 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 463 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 464 | if (subId != null) { |
| 465 | this.subId = subId; |
| 466 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 467 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 468 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 469 | } |
| 470 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 471 | private static final class IncomingThirdPartyCallArgs { |
| 472 | public final ComponentName component; |
| 473 | public final String callId; |
| 474 | public final String callerDisplayName; |
| 475 | |
| 476 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 477 | String callerDisplayName) { |
| 478 | this.component = component; |
| 479 | this.callId = callId; |
| 480 | this.callerDisplayName = callerDisplayName; |
| 481 | } |
| 482 | } |
| 483 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 484 | /** |
| 485 | * A handler that processes messages on the main thread in the phone process. Since many |
| 486 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 487 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 488 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 489 | * on, which will be notified when the operation completes and will contain the result of the |
| 490 | * request. |
| 491 | * |
| 492 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 493 | * note that request.result must be set to something non-null for the calling thread to |
| 494 | * unblock. |
| 495 | */ |
| 496 | private final class MainThreadHandler extends Handler { |
| 497 | @Override |
| 498 | public void handleMessage(Message msg) { |
| 499 | MainThreadRequest request; |
| 500 | Message onCompleted; |
| 501 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 502 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 503 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 504 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 505 | |
| 506 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 507 | case CMD_HANDLE_USSD_REQUEST: { |
| 508 | request = (MainThreadRequest) msg.obj; |
| 509 | final Phone phone = getPhoneFromRequest(request); |
| 510 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 511 | String ussdRequest = ussdObject.first; |
| 512 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 513 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 514 | if (!isUssdApiAllowed(request.subId)) { |
| 515 | // Carrier does not support use of this API, return failure. |
| 516 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 517 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 518 | Bundle returnData = new Bundle(); |
| 519 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 520 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 521 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 522 | request.result = true; |
| 523 | notifyRequester(request); |
| 524 | return; |
| 525 | } |
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 | try { |
| 528 | request.result = phone != null |
| 529 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 530 | } catch (CallStateException cse) { |
| 531 | request.result = false; |
| 532 | } |
| 533 | // Wake up the requesting thread |
| 534 | notifyRequester(request); |
| 535 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 538 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 539 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 540 | final Phone phone = getPhoneFromRequest(request); |
| 541 | request.result = phone != null ? |
| 542 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 543 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 544 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 545 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 546 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 547 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 548 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 549 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 550 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 551 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 552 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 553 | if (uiccCard == null) { |
| 554 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 555 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 556 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 557 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 558 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 559 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 560 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 561 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 562 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 563 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 564 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 565 | break; |
| 566 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 567 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 568 | ar = (AsyncResult) msg.obj; |
| 569 | request = (MainThreadRequest) ar.userObj; |
| 570 | if (ar.exception == null && ar.result != null) { |
| 571 | request.result = ar.result; |
| 572 | } else { |
| 573 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 574 | if (ar.result == null) { |
| 575 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 576 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 577 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 578 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 579 | } else { |
| 580 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 581 | } |
| 582 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 583 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 584 | break; |
| 585 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 586 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 587 | request = (MainThreadRequest) msg.obj; |
| 588 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 589 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 590 | if (uiccCard == null) { |
| 591 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 592 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 593 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 594 | } else { |
| 595 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 596 | request); |
| 597 | uiccCard.iccTransmitApduBasicChannel( |
| 598 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 599 | iccArgument.p3, iccArgument.data, onCompleted); |
| 600 | } |
| 601 | break; |
| 602 | |
| 603 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 604 | ar = (AsyncResult) msg.obj; |
| 605 | request = (MainThreadRequest) ar.userObj; |
| 606 | if (ar.exception == null && ar.result != null) { |
| 607 | request.result = ar.result; |
| 608 | } else { |
| 609 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 610 | if (ar.result == null) { |
| 611 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 612 | } else if (ar.exception instanceof CommandException) { |
| 613 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 614 | ar.exception); |
| 615 | } else { |
| 616 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 617 | } |
| 618 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 619 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 620 | break; |
| 621 | |
| 622 | case CMD_EXCHANGE_SIM_IO: |
| 623 | request = (MainThreadRequest) msg.obj; |
| 624 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 625 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 626 | if (uiccCard == null) { |
| 627 | loge("iccExchangeSimIO: No UICC"); |
| 628 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 629 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 630 | } else { |
| 631 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 632 | request); |
| 633 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 634 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 635 | iccArgument.data, onCompleted); |
| 636 | } |
| 637 | break; |
| 638 | |
| 639 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 640 | ar = (AsyncResult) msg.obj; |
| 641 | request = (MainThreadRequest) ar.userObj; |
| 642 | if (ar.exception == null && ar.result != null) { |
| 643 | request.result = ar.result; |
| 644 | } else { |
| 645 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 646 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 647 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 648 | break; |
| 649 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 650 | case CMD_SEND_ENVELOPE: |
| 651 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 652 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 653 | if (uiccCard == null) { |
| 654 | loge("sendEnvelopeWithStatus: No UICC"); |
| 655 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 656 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 657 | } else { |
| 658 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 659 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 660 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 661 | break; |
| 662 | |
| 663 | case EVENT_SEND_ENVELOPE_DONE: |
| 664 | ar = (AsyncResult) msg.obj; |
| 665 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 666 | if (ar.exception == null && ar.result != null) { |
| 667 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 668 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 669 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 670 | if (ar.result == null) { |
| 671 | loge("sendEnvelopeWithStatus: Empty response"); |
| 672 | } else if (ar.exception instanceof CommandException) { |
| 673 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 674 | ar.exception); |
| 675 | } else { |
| 676 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 677 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 678 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 679 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 680 | break; |
| 681 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 682 | case CMD_OPEN_CHANNEL: |
| 683 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 684 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 685 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 686 | if (uiccCard == null) { |
| 687 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 688 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 689 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 690 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 691 | } else { |
| 692 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 693 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 694 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 695 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 696 | break; |
| 697 | |
| 698 | case EVENT_OPEN_CHANNEL_DONE: |
| 699 | ar = (AsyncResult) msg.obj; |
| 700 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 701 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 702 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 703 | int[] result = (int[]) ar.result; |
| 704 | int channelId = result[0]; |
| 705 | byte[] selectResponse = null; |
| 706 | if (result.length > 1) { |
| 707 | selectResponse = new byte[result.length - 1]; |
| 708 | for (int i = 1; i < result.length; ++i) { |
| 709 | selectResponse[i - 1] = (byte) result[i]; |
| 710 | } |
| 711 | } |
| 712 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 713 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 714 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 715 | if (ar.result == null) { |
| 716 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 717 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 718 | if (ar.exception != null) { |
| 719 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 720 | } |
| 721 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 722 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 723 | if (ar.exception instanceof CommandException) { |
| 724 | CommandException.Error error = |
| 725 | ((CommandException) (ar.exception)).getCommandError(); |
| 726 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 727 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 728 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 729 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 730 | } |
| 731 | } |
| 732 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 733 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 734 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 735 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 736 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 737 | break; |
| 738 | |
| 739 | case CMD_CLOSE_CHANNEL: |
| 740 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 741 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 742 | if (uiccCard == null) { |
| 743 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 744 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 745 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 746 | } else { |
| 747 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 748 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 749 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 750 | break; |
| 751 | |
| 752 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 753 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 754 | break; |
| 755 | |
| 756 | case CMD_NV_READ_ITEM: |
| 757 | request = (MainThreadRequest) msg.obj; |
| 758 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 759 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 760 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 761 | break; |
| 762 | |
| 763 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 764 | ar = (AsyncResult) msg.obj; |
| 765 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 766 | if (ar.exception == null && ar.result != null) { |
| 767 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 768 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 769 | request.result = ""; |
| 770 | if (ar.result == null) { |
| 771 | loge("nvReadItem: Empty response"); |
| 772 | } else if (ar.exception instanceof CommandException) { |
| 773 | loge("nvReadItem: CommandException: " + |
| 774 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 775 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 776 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 777 | } |
| 778 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 779 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 780 | break; |
| 781 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 782 | case CMD_NV_WRITE_ITEM: |
| 783 | request = (MainThreadRequest) msg.obj; |
| 784 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 785 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 786 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 787 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 788 | break; |
| 789 | |
| 790 | case EVENT_NV_WRITE_ITEM_DONE: |
| 791 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 792 | break; |
| 793 | |
| 794 | case CMD_NV_WRITE_CDMA_PRL: |
| 795 | request = (MainThreadRequest) msg.obj; |
| 796 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 797 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 798 | break; |
| 799 | |
| 800 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 801 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 802 | break; |
| 803 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 804 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 805 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 806 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 807 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 808 | break; |
| 809 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 810 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 811 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 812 | break; |
| 813 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 814 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 815 | request = (MainThreadRequest) msg.obj; |
| 816 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 817 | request); |
| 818 | Phone phone = getPhoneFromRequest(request); |
| 819 | if (phone != null) { |
| 820 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 821 | } else { |
| 822 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 823 | request.result = false; |
| 824 | notifyRequester(request); |
| 825 | } |
| 826 | break; |
| 827 | } |
| 828 | |
| 829 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 830 | ar = (AsyncResult) msg.obj; |
| 831 | request = (MainThreadRequest) ar.userObj; |
| 832 | if (ar.exception == null && ar.result != null) { |
| 833 | request.result = ar.result; |
| 834 | } else { |
| 835 | // request.result must be set to something non-null |
| 836 | // for the calling thread to unblock |
| 837 | if (request.result != null) { |
| 838 | request.result = ar.result; |
| 839 | } else { |
| 840 | request.result = false; |
| 841 | } |
| 842 | if (ar.result == null) { |
| 843 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 844 | } else if (ar.exception instanceof CommandException) { |
| 845 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 846 | + ar.exception); |
| 847 | } else { |
| 848 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 849 | } |
| 850 | } |
| 851 | notifyRequester(request); |
| 852 | break; |
| 853 | |
| 854 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 855 | request = (MainThreadRequest) msg.obj; |
| 856 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 857 | Phone phone = getPhoneFromRequest(request); |
| 858 | if (phone != null) { |
| 859 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 860 | request.workSource); |
| 861 | } else { |
| 862 | loge("enableNrDualConnectivity: No phone object"); |
| 863 | request.result = |
| 864 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 865 | notifyRequester(request); |
| 866 | } |
| 867 | break; |
| 868 | } |
| 869 | |
| 870 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 871 | ar = (AsyncResult) msg.obj; |
| 872 | request = (MainThreadRequest) ar.userObj; |
| 873 | if (ar.exception == null) { |
| 874 | request.result = |
| 875 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 876 | } else { |
| 877 | request.result = |
| 878 | TelephonyManager |
| 879 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 880 | if (ar.exception instanceof CommandException) { |
| 881 | CommandException.Error error = |
| 882 | ((CommandException) (ar.exception)).getCommandError(); |
| 883 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 884 | request.result = |
| 885 | TelephonyManager |
| 886 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 887 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 888 | request.result = |
| 889 | TelephonyManager |
| 890 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 891 | } |
| 892 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 893 | + ar.exception); |
| 894 | } else { |
| 895 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 896 | } |
| 897 | } |
| 898 | notifyRequester(request); |
| 899 | break; |
| 900 | } |
| 901 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 902 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 903 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 904 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 905 | request); |
| 906 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 907 | break; |
| 908 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 909 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 910 | ar = (AsyncResult) msg.obj; |
| 911 | request = (MainThreadRequest) ar.userObj; |
| 912 | if (ar.exception == null && ar.result != null) { |
| 913 | request.result = ar.result; // Integer |
| 914 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 915 | // request.result must be set to something non-null |
| 916 | // for the calling thread to unblock |
| 917 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 918 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 919 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 920 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 921 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 922 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 923 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 924 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 925 | } |
| 926 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 927 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 928 | break; |
| 929 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 930 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 931 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 932 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 933 | request); |
| 934 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 935 | (Pair<Integer, Long>) request.argument; |
| 936 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 937 | reasonWithNetworkTypes.first, |
| 938 | reasonWithNetworkTypes.second, |
| 939 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 940 | break; |
| 941 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 942 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 943 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 944 | break; |
| 945 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 946 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 947 | request = (MainThreadRequest)msg.obj; |
| 948 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 949 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 950 | break; |
| 951 | |
| 952 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 953 | ar = (AsyncResult)msg.obj; |
| 954 | request = (MainThreadRequest)ar.userObj; |
| 955 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 956 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 957 | break; |
| 958 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 959 | case CMD_SET_VOICEMAIL_NUMBER: |
| 960 | request = (MainThreadRequest) msg.obj; |
| 961 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 962 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 963 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 964 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 965 | break; |
| 966 | |
| 967 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 968 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 969 | break; |
| 970 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 971 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 972 | request = (MainThreadRequest) msg.obj; |
| 973 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 974 | request); |
| 975 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 976 | break; |
| 977 | |
| 978 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 979 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 980 | break; |
| 981 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 982 | case CMD_PERFORM_NETWORK_SCAN: |
| 983 | request = (MainThreadRequest) msg.obj; |
| 984 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 985 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 986 | break; |
| 987 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 988 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 989 | request = (MainThreadRequest) msg.obj; |
| 990 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 991 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 992 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 993 | request.argument; |
| 994 | int callForwardingReason = args.first; |
| 995 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 996 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 997 | } |
| 998 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 999 | ar = (AsyncResult) msg.obj; |
| 1000 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1001 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1002 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1003 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1004 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1005 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1006 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1007 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1008 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1009 | // any service for voice call. |
| 1010 | if ((callForwardInfo.serviceClass |
| 1011 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1012 | callForwardingInfo = new CallForwardingInfo(true, |
| 1013 | callForwardInfo.reason, |
| 1014 | callForwardInfo.number, |
| 1015 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1016 | break; |
| 1017 | } |
| 1018 | } |
| 1019 | // Didn't find a call forward info for voice call. |
| 1020 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1021 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1022 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1023 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1024 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1025 | } else { |
| 1026 | if (ar.result == null) { |
| 1027 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1028 | } |
| 1029 | if (ar.exception != null) { |
| 1030 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1031 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1032 | int errorCode = TelephonyManager |
| 1033 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1034 | if (ar.exception instanceof CommandException) { |
| 1035 | CommandException.Error error = |
| 1036 | ((CommandException) (ar.exception)).getCommandError(); |
| 1037 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1038 | errorCode = TelephonyManager |
| 1039 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1040 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1041 | errorCode = TelephonyManager |
| 1042 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1043 | } |
| 1044 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1045 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1046 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1047 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1048 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1049 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1050 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1051 | request = (MainThreadRequest) msg.obj; |
| 1052 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1053 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1054 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1055 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1056 | request.argument).first; |
| 1057 | request.phone.setCallForwardingOption( |
| 1058 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1059 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1060 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1061 | callForwardingInfoToSet.getReason(), |
| 1062 | callForwardingInfoToSet.getNumber(), |
| 1063 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1064 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1065 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1066 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1067 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1068 | ar = (AsyncResult) msg.obj; |
| 1069 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1070 | Consumer<Integer> callback = |
| 1071 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1072 | request.argument).second; |
| 1073 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1074 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1075 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1076 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1077 | if (ar.exception instanceof CommandException) { |
| 1078 | CommandException.Error error = |
| 1079 | ((CommandException) (ar.exception)).getCommandError(); |
| 1080 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1081 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1082 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1083 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1084 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1085 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1086 | } |
| 1087 | } |
| 1088 | callback.accept(errorCode); |
| 1089 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1090 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1091 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1092 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1093 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1094 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1095 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1096 | request = (MainThreadRequest) msg.obj; |
| 1097 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1098 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1099 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1100 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1101 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1102 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1103 | ar = (AsyncResult) msg.obj; |
| 1104 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1105 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1106 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1107 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1108 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1109 | // Service Class is a bit mask per 3gpp 27.007. |
| 1110 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1111 | if (callForwardResults.length > 1 |
| 1112 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1113 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1114 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1115 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1116 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1117 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1118 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1119 | } |
| 1120 | } else { |
| 1121 | if (ar.result == null) { |
| 1122 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1123 | } |
| 1124 | if (ar.exception != null) { |
| 1125 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1126 | } |
| 1127 | if (ar.exception instanceof CommandException) { |
| 1128 | CommandException.Error error = |
| 1129 | ((CommandException) (ar.exception)).getCommandError(); |
| 1130 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1131 | callForwardingStatus = |
| 1132 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1133 | } |
| 1134 | } |
| 1135 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1136 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1137 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1138 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1139 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1140 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1141 | request = (MainThreadRequest) msg.obj; |
| 1142 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1143 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1144 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1145 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1146 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1147 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1148 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1149 | ar = (AsyncResult) msg.obj; |
| 1150 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1151 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1152 | Consumer<Integer> callback = |
| 1153 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1154 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1155 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1156 | if (ar.exception instanceof CommandException) { |
| 1157 | CommandException.Error error = |
| 1158 | ((CommandException) (ar.exception)).getCommandError(); |
| 1159 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1160 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1161 | } else { |
| 1162 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1163 | } |
| 1164 | } else { |
| 1165 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1166 | } |
| 1167 | } else { |
| 1168 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1169 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1170 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1171 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1172 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1173 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1174 | ar = (AsyncResult) msg.obj; |
| 1175 | request = (MainThreadRequest) ar.userObj; |
| 1176 | CellNetworkScanResult cellScanResult; |
| 1177 | if (ar.exception == null && ar.result != null) { |
| 1178 | cellScanResult = new CellNetworkScanResult( |
| 1179 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1180 | (List<OperatorInfo>) ar.result); |
| 1181 | } else { |
| 1182 | if (ar.result == null) { |
| 1183 | loge("getCellNetworkScanResults: Empty response"); |
| 1184 | } |
| 1185 | if (ar.exception != null) { |
| 1186 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1187 | } |
| 1188 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1189 | if (ar.exception instanceof CommandException) { |
| 1190 | CommandException.Error error = |
| 1191 | ((CommandException) (ar.exception)).getCommandError(); |
| 1192 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1193 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1194 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1195 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1196 | } |
| 1197 | } |
| 1198 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1199 | } |
| 1200 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1201 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1202 | break; |
| 1203 | |
| 1204 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1205 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1206 | ManualNetworkSelectionArgument selArg = |
| 1207 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1208 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1209 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1210 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1211 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1212 | break; |
| 1213 | |
| 1214 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1215 | ar = (AsyncResult) msg.obj; |
| 1216 | request = (MainThreadRequest) ar.userObj; |
| 1217 | if (ar.exception == null) { |
| 1218 | request.result = true; |
| 1219 | } else { |
| 1220 | request.result = false; |
| 1221 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1222 | } |
| 1223 | notifyRequester(request); |
| 1224 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1225 | break; |
| 1226 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1227 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1228 | request = (MainThreadRequest) msg.obj; |
| 1229 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1230 | if (defaultPhone != null) { |
| 1231 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1232 | } else { |
| 1233 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1234 | Bundle bundle = new Bundle(); |
| 1235 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1236 | new ModemActivityInfo(0, 0, 0, |
| 1237 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1238 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1239 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1240 | break; |
| 1241 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1242 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1243 | ar = (AsyncResult) msg.obj; |
| 1244 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1245 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1246 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1247 | ModemActivityInfo ret = null; |
| 1248 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1249 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1250 | // Update the last modem activity info and the result of the request. |
| 1251 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1252 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1253 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1254 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1255 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1256 | .getTransmitTimeMillis(); |
| 1257 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1258 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1259 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1260 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1261 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1262 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1263 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1264 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1265 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1266 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1267 | info.getReceiveTimeMillis() |
| 1268 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1269 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1270 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1271 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1272 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1273 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1274 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1275 | } else { |
| 1276 | if (ar.result == null) { |
| 1277 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1278 | error = TelephonyManager.ModemActivityInfoException |
| 1279 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1280 | } else if (ar.exception instanceof CommandException) { |
| 1281 | loge("queryModemActivityInfo: CommandException: " + |
| 1282 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1283 | error = TelephonyManager.ModemActivityInfoException |
| 1284 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1285 | } else { |
| 1286 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1287 | error = TelephonyManager.ModemActivityInfoException |
| 1288 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1289 | } |
| 1290 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1291 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1292 | if (ret != null) { |
| 1293 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1294 | } else { |
| 1295 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1296 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1297 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1298 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1299 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1300 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1301 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1302 | case CMD_SET_ALLOWED_CARRIERS: |
| 1303 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1304 | CarrierRestrictionRules argument = |
| 1305 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1306 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1307 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1308 | break; |
| 1309 | |
| 1310 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1311 | ar = (AsyncResult) msg.obj; |
| 1312 | request = (MainThreadRequest) ar.userObj; |
| 1313 | if (ar.exception == null && ar.result != null) { |
| 1314 | request.result = ar.result; |
| 1315 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1316 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1317 | if (ar.exception instanceof CommandException) { |
| 1318 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1319 | CommandException.Error error = |
| 1320 | ((CommandException) (ar.exception)).getCommandError(); |
| 1321 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1322 | request.result = |
| 1323 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1324 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1325 | } else { |
| 1326 | loge("setAllowedCarriers: Unknown exception"); |
| 1327 | } |
| 1328 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1329 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1330 | break; |
| 1331 | |
| 1332 | case CMD_GET_ALLOWED_CARRIERS: |
| 1333 | request = (MainThreadRequest) msg.obj; |
| 1334 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1335 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1336 | break; |
| 1337 | |
| 1338 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1339 | ar = (AsyncResult) msg.obj; |
| 1340 | request = (MainThreadRequest) ar.userObj; |
| 1341 | if (ar.exception == null && ar.result != null) { |
| 1342 | request.result = ar.result; |
| 1343 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1344 | request.result = new IllegalStateException( |
| 1345 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1346 | if (ar.result == null) { |
| 1347 | loge("getAllowedCarriers: Empty response"); |
| 1348 | } else if (ar.exception instanceof CommandException) { |
| 1349 | loge("getAllowedCarriers: CommandException: " + |
| 1350 | ar.exception); |
| 1351 | } else { |
| 1352 | loge("getAllowedCarriers: Unknown exception"); |
| 1353 | } |
| 1354 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1355 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1356 | break; |
| 1357 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1358 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1359 | ar = (AsyncResult) msg.obj; |
| 1360 | request = (MainThreadRequest) ar.userObj; |
| 1361 | if (ar.exception == null && ar.result != null) { |
| 1362 | request.result = ar.result; |
| 1363 | } else { |
| 1364 | request.result = new IllegalArgumentException( |
| 1365 | "Failed to retrieve Forbidden Plmns"); |
| 1366 | if (ar.result == null) { |
| 1367 | loge("getForbiddenPlmns: Empty response"); |
| 1368 | } else { |
| 1369 | loge("getForbiddenPlmns: Unknown exception"); |
| 1370 | } |
| 1371 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1372 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1373 | break; |
| 1374 | |
| 1375 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1376 | request = (MainThreadRequest) msg.obj; |
| 1377 | uiccCard = getUiccCardFromRequest(request); |
| 1378 | if (uiccCard == null) { |
| 1379 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1380 | request.result = new IllegalArgumentException( |
| 1381 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1382 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1383 | break; |
| 1384 | } |
| 1385 | Integer appType = (Integer) request.argument; |
| 1386 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1387 | if (uiccApp == null) { |
| 1388 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1389 | + appType); |
| 1390 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1391 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1392 | break; |
| 1393 | } else { |
| 1394 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1395 | + " specified type -- " + appType); |
| 1396 | } |
| 1397 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1398 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1399 | onCompleted); |
| 1400 | break; |
| 1401 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1402 | case CMD_SWITCH_SLOTS: |
| 1403 | request = (MainThreadRequest) msg.obj; |
| 1404 | int[] physicalSlots = (int[]) request.argument; |
| 1405 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1406 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1407 | break; |
| 1408 | |
| 1409 | case EVENT_SWITCH_SLOTS_DONE: |
| 1410 | ar = (AsyncResult) msg.obj; |
| 1411 | request = (MainThreadRequest) ar.userObj; |
| 1412 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1413 | notifyRequester(request); |
| 1414 | break; |
| 1415 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1416 | request = (MainThreadRequest) msg.obj; |
| 1417 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1418 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1419 | break; |
| 1420 | |
| 1421 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1422 | ar = (AsyncResult) msg.obj; |
| 1423 | request = (MainThreadRequest) ar.userObj; |
| 1424 | if (ar.exception != null) { |
| 1425 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1426 | } else { |
| 1427 | int mode = ((int[]) ar.result)[0]; |
| 1428 | if (mode == 0) { |
| 1429 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1430 | } else { |
| 1431 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1432 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1433 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1434 | notifyRequester(request); |
| 1435 | break; |
| 1436 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1437 | request = (MainThreadRequest) msg.obj; |
| 1438 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1439 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1440 | break; |
| 1441 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1442 | ar = (AsyncResult) msg.obj; |
| 1443 | request = (MainThreadRequest) ar.userObj; |
| 1444 | if (ar.exception != null) { |
| 1445 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1446 | } else { |
| 1447 | request.result = ((int[]) ar.result)[0]; |
| 1448 | } |
| 1449 | notifyRequester(request); |
| 1450 | break; |
| 1451 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1452 | request = (MainThreadRequest) msg.obj; |
| 1453 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1454 | int mode = (int) request.argument; |
| 1455 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1456 | break; |
| 1457 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1458 | ar = (AsyncResult) msg.obj; |
| 1459 | request = (MainThreadRequest) ar.userObj; |
| 1460 | request.result = ar.exception == null; |
| 1461 | notifyRequester(request); |
| 1462 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1463 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1464 | request = (MainThreadRequest) msg.obj; |
| 1465 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1466 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1467 | break; |
| 1468 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1469 | ar = (AsyncResult) msg.obj; |
| 1470 | request = (MainThreadRequest) ar.userObj; |
| 1471 | if (ar.exception != null) { |
| 1472 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1473 | } else { |
| 1474 | request.result = ((int[]) ar.result)[0]; |
| 1475 | } |
| 1476 | notifyRequester(request); |
| 1477 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1478 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1479 | request = (MainThreadRequest) msg.obj; |
| 1480 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1481 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1482 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1483 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1484 | break; |
| 1485 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1486 | ar = (AsyncResult) msg.obj; |
| 1487 | request = (MainThreadRequest) ar.userObj; |
| 1488 | request.result = ar.exception == null; |
| 1489 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1490 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1491 | case CMD_GET_ALL_CELL_INFO: |
| 1492 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1493 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1494 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1495 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1496 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1497 | ar = (AsyncResult) msg.obj; |
| 1498 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1499 | // If a timeout occurs, the response will be null |
| 1500 | request.result = (ar.exception == null && ar.result != null) |
| 1501 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1502 | synchronized (request) { |
| 1503 | request.notifyAll(); |
| 1504 | } |
| 1505 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1506 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1507 | request = (MainThreadRequest) msg.obj; |
| 1508 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1509 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1510 | break; |
| 1511 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1512 | ar = (AsyncResult) msg.obj; |
| 1513 | request = (MainThreadRequest) ar.userObj; |
| 1514 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1515 | try { |
| 1516 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1517 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1518 | cb.onError( |
| 1519 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1520 | ar.exception.getClass().getName(), |
| 1521 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1522 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1523 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1524 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1525 | } else { |
| 1526 | // use the result as returned |
| 1527 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1528 | } |
| 1529 | } catch (RemoteException re) { |
| 1530 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1531 | } |
| 1532 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1533 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1534 | request = (MainThreadRequest) msg.obj; |
| 1535 | WorkSource ws = (WorkSource) request.argument; |
| 1536 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1537 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1538 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1539 | } |
| 1540 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1541 | ar = (AsyncResult) msg.obj; |
| 1542 | request = (MainThreadRequest) ar.userObj; |
| 1543 | if (ar.exception == null) { |
| 1544 | request.result = ar.result; |
| 1545 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1546 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1547 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1548 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1549 | } |
| 1550 | |
| 1551 | synchronized (request) { |
| 1552 | request.notifyAll(); |
| 1553 | } |
| 1554 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1555 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1556 | case CMD_MODEM_REBOOT: |
| 1557 | request = (MainThreadRequest) msg.obj; |
| 1558 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1559 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1560 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1561 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1562 | handleNullReturnEvent(msg, "rebootModem"); |
| 1563 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1564 | case CMD_REQUEST_ENABLE_MODEM: |
| 1565 | request = (MainThreadRequest) msg.obj; |
| 1566 | boolean enable = (boolean) request.argument; |
| 1567 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1568 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1569 | PhoneConfigurationManager.getInstance() |
| 1570 | .enablePhone(request.phone, enable, onCompleted); |
| 1571 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1572 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1573 | ar = (AsyncResult) msg.obj; |
| 1574 | request = (MainThreadRequest) ar.userObj; |
| 1575 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1576 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1577 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1578 | if ((boolean) request.result) { |
| 1579 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1580 | updateModemStateMetrics(); |
| 1581 | } else { |
| 1582 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1583 | + ar.exception); |
| 1584 | } |
| 1585 | notifyRequester(request); |
| 1586 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1587 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1588 | case CMD_GET_MODEM_STATUS: |
| 1589 | request = (MainThreadRequest) msg.obj; |
| 1590 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1591 | PhoneConfigurationManager.getInstance() |
| 1592 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1593 | break; |
| 1594 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1595 | ar = (AsyncResult) msg.obj; |
| 1596 | request = (MainThreadRequest) ar.userObj; |
| 1597 | int id = request.phone.getPhoneId(); |
| 1598 | if (ar.exception == null && ar.result != null) { |
| 1599 | request.result = ar.result; |
| 1600 | //update the cache as modem status has changed |
| 1601 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1602 | (boolean) request.result); |
| 1603 | } else { |
| 1604 | // Return true if modem status cannot be retrieved. For most cases, |
| 1605 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1606 | // and disable modem are not supported. Modem is always on. |
| 1607 | // TODO: this should be fixed in R to support a third |
| 1608 | // status UNKNOWN b/131631629 |
| 1609 | request.result = true; |
| 1610 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1611 | + ar.exception); |
| 1612 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1613 | notifyRequester(request); |
| 1614 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1615 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1616 | request = (MainThreadRequest) msg.obj; |
| 1617 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1618 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1619 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1620 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1621 | break; |
| 1622 | } |
| 1623 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1624 | ar = (AsyncResult) msg.obj; |
| 1625 | request = (MainThreadRequest) ar.userObj; |
| 1626 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1627 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1628 | args.second.accept(ar.exception == null); |
| 1629 | notifyRequester(request); |
| 1630 | break; |
| 1631 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1632 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1633 | request = (MainThreadRequest) msg.obj; |
| 1634 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1635 | Phone phone = getPhoneFromRequest(request); |
| 1636 | if (phone != null) { |
| 1637 | phone.getSystemSelectionChannels(onCompleted); |
| 1638 | } else { |
| 1639 | loge("getSystemSelectionChannels: No phone object"); |
| 1640 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1641 | notifyRequester(request); |
| 1642 | } |
| 1643 | break; |
| 1644 | } |
| 1645 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1646 | ar = (AsyncResult) msg.obj; |
| 1647 | request = (MainThreadRequest) ar.userObj; |
| 1648 | if (ar.exception == null && ar.result != null) { |
| 1649 | request.result = ar.result; |
| 1650 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1651 | request.result = new IllegalStateException( |
| 1652 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1653 | if (ar.result == null) { |
| 1654 | loge("getSystemSelectionChannels: Empty response"); |
| 1655 | } else { |
| 1656 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1657 | } |
| 1658 | } |
| 1659 | notifyRequester(request); |
| 1660 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1661 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1662 | ar = (AsyncResult) msg.obj; |
| 1663 | request = (MainThreadRequest) ar.userObj; |
| 1664 | if (ar.exception == null && ar.result != null) { |
| 1665 | request.result = ar.result; |
| 1666 | } else { |
| 1667 | request.result = -1; |
| 1668 | loge("Failed to set Forbidden Plmns"); |
| 1669 | if (ar.result == null) { |
| 1670 | loge("setForbidenPlmns: Empty response"); |
| 1671 | } else if (ar.exception != null) { |
| 1672 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1673 | request.result = -1; |
| 1674 | } else { |
| 1675 | loge("setForbiddenPlmns: Unknown exception"); |
| 1676 | } |
| 1677 | } |
| 1678 | notifyRequester(request); |
| 1679 | break; |
| 1680 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1681 | request = (MainThreadRequest) msg.obj; |
| 1682 | uiccCard = getUiccCardFromRequest(request); |
| 1683 | if (uiccCard == null) { |
| 1684 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1685 | request.result = -1; |
| 1686 | notifyRequester(request); |
| 1687 | break; |
| 1688 | } |
| 1689 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1690 | (Pair<Integer, List<String>>) request.argument; |
| 1691 | appType = setFplmnsArgs.first; |
| 1692 | List<String> fplmns = setFplmnsArgs.second; |
| 1693 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1694 | if (uiccApp == null) { |
| 1695 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1696 | request.result = -1; |
| 1697 | loge("Failed to get UICC App"); |
| 1698 | notifyRequester(request); |
| 1699 | } else { |
| 1700 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1701 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1702 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1703 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1704 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1705 | case CMD_ERASE_MODEM_CONFIG: |
| 1706 | request = (MainThreadRequest) msg.obj; |
| 1707 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1708 | defaultPhone.eraseModemConfig(onCompleted); |
| 1709 | break; |
| 1710 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1711 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1712 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1713 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1714 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1715 | request = (MainThreadRequest) msg.obj; |
| 1716 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1717 | notifyRequester(request); |
| 1718 | break; |
| 1719 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1720 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1721 | request = (MainThreadRequest) msg.obj; |
| 1722 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1723 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1724 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1725 | changed.first, changed.second, onCompleted); |
| 1726 | break; |
| 1727 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1728 | ar = (AsyncResult) msg.obj; |
| 1729 | request = (MainThreadRequest) ar.userObj; |
| 1730 | if (ar.exception == null) { |
| 1731 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1732 | // If the operation is successful, update the PIN storage |
| 1733 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1734 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1735 | UiccController.getInstance().getPinStorage() |
| 1736 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1737 | } else { |
| 1738 | request.result = msg.arg1; |
| 1739 | } |
| 1740 | notifyRequester(request); |
| 1741 | break; |
| 1742 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1743 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1744 | request = (MainThreadRequest) msg.obj; |
| 1745 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1746 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1747 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1748 | enabled.first, enabled.second, onCompleted); |
| 1749 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1750 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1751 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1752 | ar = (AsyncResult) msg.obj; |
| 1753 | request = (MainThreadRequest) ar.userObj; |
| 1754 | if (ar.exception == null) { |
| 1755 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1756 | // If the operation is successful, update the PIN storage |
| 1757 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1758 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1759 | if (enabled.first) { |
| 1760 | UiccController.getInstance().getPinStorage() |
| 1761 | .storePin(enabled.second, phoneId); |
| 1762 | } else { |
| 1763 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1764 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1765 | } else { |
| 1766 | request.result = msg.arg1; |
| 1767 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1768 | |
| 1769 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1770 | notifyRequester(request); |
| 1771 | break; |
| 1772 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1773 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1774 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1775 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1776 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1777 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1778 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1779 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1780 | |
| 1781 | case CMD_SET_DATA_THROTTLING: { |
| 1782 | request = (MainThreadRequest) msg.obj; |
| 1783 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1784 | DataThrottlingRequest dataThrottlingRequest = |
| 1785 | (DataThrottlingRequest) request.argument; |
| 1786 | Phone phone = getPhoneFromRequest(request); |
| 1787 | if (phone != null) { |
| 1788 | phone.setDataThrottling(onCompleted, |
| 1789 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1790 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1791 | } else { |
| 1792 | loge("setDataThrottling: No phone object"); |
| 1793 | request.result = |
| 1794 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1795 | notifyRequester(request); |
| 1796 | } |
| 1797 | |
| 1798 | break; |
| 1799 | } |
| 1800 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1801 | ar = (AsyncResult) msg.obj; |
| 1802 | request = (MainThreadRequest) ar.userObj; |
| 1803 | |
| 1804 | if (ar.exception == null) { |
| 1805 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1806 | } else if (ar.exception instanceof CommandException) { |
| 1807 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1808 | CommandException.Error error = |
| 1809 | ((CommandException) (ar.exception)).getCommandError(); |
| 1810 | |
| 1811 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1812 | request.result = TelephonyManager |
| 1813 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1814 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1815 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 1816 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1817 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1818 | } else { |
| 1819 | request.result = |
| 1820 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1821 | } |
| 1822 | } else { |
| 1823 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1824 | } |
| 1825 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1826 | notifyRequester(request); |
| 1827 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1828 | |
| 1829 | case CMD_SET_SIM_POWER: { |
| 1830 | request = (MainThreadRequest) msg.obj; |
| 1831 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1832 | request = (MainThreadRequest) msg.obj; |
| 1833 | int stateToSet = |
| 1834 | ((Pair<Integer, IIntegerConsumer>) |
| 1835 | request.argument).first; |
| 1836 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1837 | break; |
| 1838 | } |
| 1839 | case EVENT_SET_SIM_POWER_DONE: { |
| 1840 | ar = (AsyncResult) msg.obj; |
| 1841 | request = (MainThreadRequest) ar.userObj; |
| 1842 | IIntegerConsumer callback = |
| 1843 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1844 | if (ar.exception != null) { |
| 1845 | loge("setSimPower exception: " + ar.exception); |
| 1846 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1847 | .RESULT_ERROR_UNKNOWN; |
| 1848 | if (ar.exception instanceof CommandException) { |
| 1849 | CommandException.Error error = |
| 1850 | ((CommandException) (ar.exception)).getCommandError(); |
| 1851 | if (error == CommandException.Error.SIM_ERR) { |
| 1852 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1853 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1854 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1855 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1856 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1857 | } else { |
| 1858 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1859 | } |
| 1860 | } |
| 1861 | try { |
| 1862 | callback.accept(errorCode); |
| 1863 | } catch (RemoteException e) { |
| 1864 | // Ignore if the remote process is no longer available to call back. |
| 1865 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1866 | } |
| 1867 | } else { |
| 1868 | try { |
| 1869 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1870 | } catch (RemoteException e) { |
| 1871 | // Ignore if the remote process is no longer available to call back. |
| 1872 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1873 | } |
| 1874 | } |
| 1875 | break; |
| 1876 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1877 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1878 | request = (MainThreadRequest) msg.obj; |
| 1879 | |
| 1880 | final Phone phone = getPhoneFromRequest(request); |
| 1881 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1882 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1883 | notifyRequester(request); |
| 1884 | break; |
| 1885 | } |
| 1886 | |
| 1887 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1888 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1889 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1890 | request); |
| 1891 | phone.getServiceStateTracker().setSignalStrengthUpdateRequest( |
| 1892 | request.subId, pair.first /*callingUid*/, |
| 1893 | pair.second /*request*/, onCompleted); |
| 1894 | break; |
| 1895 | } |
| 1896 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1897 | ar = (AsyncResult) msg.obj; |
| 1898 | request = (MainThreadRequest) ar.userObj; |
| 1899 | // request.result will be the exception of ar if present, true otherwise. |
| 1900 | // Be cautious not to leave result null which will wait() forever |
| 1901 | request.result = ar.exception != null ? ar.exception : true; |
| 1902 | notifyRequester(request); |
| 1903 | break; |
| 1904 | } |
| 1905 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1906 | request = (MainThreadRequest) msg.obj; |
| 1907 | |
| 1908 | Phone phone = getPhoneFromRequest(request); |
| 1909 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1910 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1911 | notifyRequester(request); |
| 1912 | break; |
| 1913 | } |
| 1914 | |
| 1915 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1916 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1917 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1918 | request); |
| 1919 | phone.getServiceStateTracker().clearSignalStrengthUpdateRequest( |
| 1920 | request.subId, pair.first /*callingUid*/, |
| 1921 | pair.second /*request*/, onCompleted); |
| 1922 | break; |
| 1923 | } |
| 1924 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1925 | ar = (AsyncResult) msg.obj; |
| 1926 | request = (MainThreadRequest) ar.userObj; |
| 1927 | request.result = ar.exception != null ? ar.exception : true; |
| 1928 | notifyRequester(request); |
| 1929 | break; |
| 1930 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1931 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 1932 | case CMD_GET_SLICING_CONFIG: { |
| 1933 | request = (MainThreadRequest) msg.obj; |
| 1934 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 1935 | request.phone.getSlicingConfig(onCompleted); |
| 1936 | break; |
| 1937 | } |
| 1938 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 1939 | ar = (AsyncResult) msg.obj; |
| 1940 | request = (MainThreadRequest) ar.userObj; |
| 1941 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1942 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 1943 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 1944 | Bundle bundle = new Bundle(); |
| 1945 | int resultCode = 0; |
| 1946 | if (ar.exception != null) { |
| 1947 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 1948 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 1949 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 1950 | } else if (ar.result == null) { |
| 1951 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 1952 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 1953 | } else { |
| 1954 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 1955 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 1956 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 1960 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 1961 | } |
| 1962 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 1963 | result.send(resultCode, bundle); |
| 1964 | notifyRequester(request); |
| 1965 | break; |
| 1966 | } |
| 1967 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1968 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 1969 | request = (MainThreadRequest) msg.obj; |
| 1970 | request.result = |
| 1971 | UiccController.getInstance().getPinStorage().prepareUnattendedReboot(); |
| 1972 | notifyRequester(request); |
| 1973 | break; |
| 1974 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1975 | default: |
| 1976 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1977 | break; |
| 1978 | } |
| 1979 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1980 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1981 | private void notifyRequester(MainThreadRequest request) { |
| 1982 | synchronized (request) { |
| 1983 | request.notifyAll(); |
| 1984 | } |
| 1985 | } |
| 1986 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1987 | private void handleNullReturnEvent(Message msg, String command) { |
| 1988 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1989 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1990 | if (ar.exception == null) { |
| 1991 | request.result = true; |
| 1992 | } else { |
| 1993 | request.result = false; |
| 1994 | if (ar.exception instanceof CommandException) { |
| 1995 | loge(command + ": CommandException: " + ar.exception); |
| 1996 | } else { |
| 1997 | loge(command + ": Unknown exception"); |
| 1998 | } |
| 1999 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2000 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2001 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2002 | } |
| 2003 | |
| 2004 | /** |
| 2005 | * Posts the specified command to be executed on the main thread, |
| 2006 | * waits for the request to complete, and returns the result. |
| 2007 | * @see #sendRequestAsync |
| 2008 | */ |
| 2009 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2010 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2011 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2012 | } |
| 2013 | |
| 2014 | /** |
| 2015 | * Posts the specified command to be executed on the main thread, |
| 2016 | * waits for the request to complete, and returns the result. |
| 2017 | * @see #sendRequestAsync |
| 2018 | */ |
| 2019 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2020 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2021 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2022 | } |
| 2023 | |
| 2024 | /** |
| 2025 | * Posts the specified command to be executed on the main thread, |
| 2026 | * waits for the request to complete, and returns the result. |
| 2027 | * @see #sendRequestAsync |
| 2028 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2029 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2030 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2031 | } |
| 2032 | |
| 2033 | /** |
| 2034 | * Posts the specified command to be executed on the main thread, |
| 2035 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2036 | * if not timeout or null otherwise. |
| 2037 | * @see #sendRequestAsync |
| 2038 | */ |
| 2039 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2040 | long timeoutInMs) { |
| 2041 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2042 | } |
| 2043 | |
| 2044 | /** |
| 2045 | * Posts the specified command to be executed on the main thread, |
| 2046 | * waits for the request to complete, and returns the result. |
| 2047 | * @see #sendRequestAsync |
| 2048 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2049 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2050 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2051 | } |
| 2052 | |
| 2053 | /** |
| 2054 | * Posts the specified command to be executed on the main thread, |
| 2055 | * waits for the request to complete, and returns the result. |
| 2056 | * @see #sendRequestAsync |
| 2057 | */ |
| 2058 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2059 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2060 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2061 | } |
| 2062 | |
| 2063 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2064 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2065 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2066 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2067 | * @see #sendRequestAsync |
| 2068 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2069 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2070 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2071 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2072 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2073 | } |
| 2074 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2075 | MainThreadRequest request = null; |
| 2076 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2077 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2078 | } else if (phone != null) { |
| 2079 | request = new MainThreadRequest(argument, phone, workSource); |
| 2080 | } else { |
| 2081 | request = new MainThreadRequest(argument, subId, workSource); |
| 2082 | } |
| 2083 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2084 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2085 | msg.sendToTarget(); |
| 2086 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2087 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2088 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2089 | if (timeoutInMs >= 0) { |
| 2090 | // Wait for at least timeoutInMs before returning null request result |
| 2091 | long now = SystemClock.elapsedRealtime(); |
| 2092 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2093 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2094 | try { |
| 2095 | request.wait(deadline - now); |
| 2096 | } catch (InterruptedException e) { |
| 2097 | // Do nothing, go back and check if request is completed or timeout |
| 2098 | } finally { |
| 2099 | now = SystemClock.elapsedRealtime(); |
| 2100 | } |
| 2101 | } |
| 2102 | } else { |
| 2103 | // Wait for the request to complete |
| 2104 | while (request.result == null) { |
| 2105 | try { |
| 2106 | request.wait(); |
| 2107 | } catch (InterruptedException e) { |
| 2108 | // Do nothing, go back and wait until the request is complete |
| 2109 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2110 | } |
| 2111 | } |
| 2112 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2113 | if (request.result == null) { |
| 2114 | Log.wtf(LOG_TAG, |
| 2115 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2116 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2117 | return request.result; |
| 2118 | } |
| 2119 | |
| 2120 | /** |
| 2121 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2122 | * Posts the specified command to be executed on the main thread, and |
| 2123 | * returns immediately. |
| 2124 | * @see #sendRequest |
| 2125 | */ |
| 2126 | private void sendRequestAsync(int command) { |
| 2127 | mMainThreadHandler.sendEmptyMessage(command); |
| 2128 | } |
| 2129 | |
| 2130 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2131 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2132 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2133 | */ |
| 2134 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2135 | sendRequestAsync(command, argument, null, null); |
| 2136 | } |
| 2137 | |
| 2138 | /** |
| 2139 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2140 | * @see {@link #sendRequest(int,Object)} |
| 2141 | */ |
| 2142 | private void sendRequestAsync( |
| 2143 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2144 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2145 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2146 | msg.sendToTarget(); |
| 2147 | } |
| 2148 | |
| 2149 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2150 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2151 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2152 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2153 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2154 | synchronized (PhoneInterfaceManager.class) { |
| 2155 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2156 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2157 | } else { |
| 2158 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2159 | } |
| 2160 | return sInstance; |
| 2161 | } |
| 2162 | } |
| 2163 | |
| 2164 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2165 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2166 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2167 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2168 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2169 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2170 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2171 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2172 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2173 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2174 | mTelephonySharedPreferences = |
| 2175 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2176 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2177 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2178 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2179 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2180 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2181 | publish(); |
| 2182 | } |
| 2183 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2184 | private Phone getDefaultPhone() { |
| 2185 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2186 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2187 | } |
| 2188 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2189 | private void publish() { |
| 2190 | if (DBG) log("publish: " + this); |
| 2191 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2192 | TelephonyFrameworkInitializer |
| 2193 | .getTelephonyServiceManager() |
| 2194 | .getTelephonyServiceRegisterer() |
| 2195 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2196 | } |
| 2197 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2198 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2199 | if (request.phone != null) { |
| 2200 | return request.phone; |
| 2201 | } else { |
| 2202 | return getPhoneFromSubId(request.subId); |
| 2203 | } |
| 2204 | } |
| 2205 | |
| 2206 | private Phone getPhoneFromSubId(int subId) { |
| 2207 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2208 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2209 | } |
| 2210 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2211 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 2212 | Phone phone = getPhoneFromRequest(request); |
| 2213 | return phone == null ? null : |
| 2214 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 2215 | } |
| 2216 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2217 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2218 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2219 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2220 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2221 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2222 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2223 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2224 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2225 | } |
| 2226 | |
| 2227 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2228 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2229 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2230 | } |
| 2231 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2232 | private boolean isImsAvailableOnDevice() { |
| 2233 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2234 | if (pm == null) { |
| 2235 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2236 | // so do not throw error and allow. |
| 2237 | return true; |
| 2238 | } |
| 2239 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2240 | } |
| 2241 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2242 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2243 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2244 | } |
| 2245 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2246 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2247 | if (DBG) log("dial: " + number); |
| 2248 | // No permission check needed here: This is just a wrapper around the |
| 2249 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2250 | // the UI before it does anything. |
| 2251 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2252 | final long identity = Binder.clearCallingIdentity(); |
| 2253 | try { |
| 2254 | String url = createTelUrl(number); |
| 2255 | if (url == null) { |
| 2256 | return; |
| 2257 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2258 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2259 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2260 | PhoneConstants.State state = mCM.getState(subId); |
| 2261 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2262 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2263 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2264 | mApp.startActivity(intent); |
| 2265 | } |
| 2266 | } finally { |
| 2267 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2268 | } |
| 2269 | } |
| 2270 | |
| 2271 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2272 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2273 | } |
| 2274 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2275 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2276 | if (DBG) log("call: " + number); |
| 2277 | |
| 2278 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2279 | // need to do a permission check since we're calling startActivity() |
| 2280 | // from the context of the phone app. |
| 2281 | enforceCallPermission(); |
| 2282 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2283 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2284 | != AppOpsManager.MODE_ALLOWED) { |
| 2285 | return; |
| 2286 | } |
| 2287 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2288 | final long identity = Binder.clearCallingIdentity(); |
| 2289 | try { |
| 2290 | String url = createTelUrl(number); |
| 2291 | if (url == null) { |
| 2292 | return; |
| 2293 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2294 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2295 | boolean isValid = false; |
| 2296 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2297 | if (slist != null) { |
| 2298 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2299 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2300 | isValid = true; |
| 2301 | break; |
| 2302 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2303 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2304 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2305 | if (!isValid) { |
| 2306 | return; |
| 2307 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2308 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2309 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2310 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2311 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2312 | mApp.startActivity(intent); |
| 2313 | } finally { |
| 2314 | Binder.restoreCallingIdentity(identity); |
| 2315 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2316 | } |
| 2317 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2318 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2319 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2320 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2321 | } |
| 2322 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2323 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2324 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2325 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2326 | } |
| 2327 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2328 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2329 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2330 | |
| 2331 | final long identity = Binder.clearCallingIdentity(); |
| 2332 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2333 | Phone phone = getPhone(subId); |
| 2334 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2335 | checkSimPin.start(); |
| 2336 | return checkSimPin.unlockSim(null, pin); |
| 2337 | } finally { |
| 2338 | Binder.restoreCallingIdentity(identity); |
| 2339 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2340 | } |
| 2341 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2342 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2343 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2344 | |
| 2345 | final long identity = Binder.clearCallingIdentity(); |
| 2346 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2347 | Phone phone = getPhone(subId); |
| 2348 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2349 | checkSimPuk.start(); |
| 2350 | return checkSimPuk.unlockSim(puk, pin); |
| 2351 | } finally { |
| 2352 | Binder.restoreCallingIdentity(identity); |
| 2353 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2354 | } |
| 2355 | |
| 2356 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2357 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2358 | * a synchronous one. |
| 2359 | */ |
| 2360 | private static class UnlockSim extends Thread { |
| 2361 | |
| 2362 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2363 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2364 | |
| 2365 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2366 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2367 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2368 | |
| 2369 | // For replies from SimCard interface |
| 2370 | private Handler mHandler; |
| 2371 | |
| 2372 | // For async handler to identify request type |
| 2373 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2374 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2375 | UnlockSim(int phoneId, IccCard simCard) { |
| 2376 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2377 | mSimCard = simCard; |
| 2378 | } |
| 2379 | |
| 2380 | @Override |
| 2381 | public void run() { |
| 2382 | Looper.prepare(); |
| 2383 | synchronized (UnlockSim.this) { |
| 2384 | mHandler = new Handler() { |
| 2385 | @Override |
| 2386 | public void handleMessage(Message msg) { |
| 2387 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2388 | switch (msg.what) { |
| 2389 | case SUPPLY_PIN_COMPLETE: |
| 2390 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2391 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2392 | mRetryCount = msg.arg1; |
| 2393 | if (ar.exception != null) { |
| 2394 | if (ar.exception instanceof CommandException && |
| 2395 | ((CommandException)(ar.exception)).getCommandError() |
| 2396 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2397 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2398 | } //When UiccCardApp dispose,handle message and return exception |
| 2399 | else if (ar.exception instanceof CommandException && |
| 2400 | ((CommandException) (ar.exception)).getCommandError() |
| 2401 | == CommandException.Error.ABORTED) { |
| 2402 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2403 | } else { |
| 2404 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2405 | } |
| 2406 | } else { |
| 2407 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2408 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2409 | mDone = true; |
| 2410 | UnlockSim.this.notifyAll(); |
| 2411 | } |
| 2412 | break; |
| 2413 | } |
| 2414 | } |
| 2415 | }; |
| 2416 | UnlockSim.this.notifyAll(); |
| 2417 | } |
| 2418 | Looper.loop(); |
| 2419 | } |
| 2420 | |
| 2421 | /* |
| 2422 | * Use PIN or PUK to unlock SIM card |
| 2423 | * |
| 2424 | * If PUK is null, unlock SIM card with PIN |
| 2425 | * |
| 2426 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2427 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2428 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2429 | |
| 2430 | while (mHandler == null) { |
| 2431 | try { |
| 2432 | wait(); |
| 2433 | } catch (InterruptedException e) { |
| 2434 | Thread.currentThread().interrupt(); |
| 2435 | } |
| 2436 | } |
| 2437 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2438 | |
| 2439 | if (puk == null) { |
| 2440 | mSimCard.supplyPin(pin, callback); |
| 2441 | } else { |
| 2442 | mSimCard.supplyPuk(puk, pin, callback); |
| 2443 | } |
| 2444 | |
| 2445 | while (!mDone) { |
| 2446 | try { |
| 2447 | Log.d(LOG_TAG, "wait for done"); |
| 2448 | wait(); |
| 2449 | } catch (InterruptedException e) { |
| 2450 | // Restore the interrupted status |
| 2451 | Thread.currentThread().interrupt(); |
| 2452 | } |
| 2453 | } |
| 2454 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2455 | int[] resultArray = new int[2]; |
| 2456 | resultArray[0] = mResult; |
| 2457 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2458 | |
| 2459 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
| 2460 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
| 2461 | } |
| 2462 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2463 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2464 | } |
| 2465 | } |
| 2466 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2467 | /** |
| 2468 | * This method has been removed due to privacy and stability concerns. |
| 2469 | */ |
| 2470 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2471 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2472 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2473 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2474 | } |
| 2475 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2476 | @Override |
| 2477 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2478 | mApp.getSystemService(AppOpsManager.class) |
| 2479 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2480 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2481 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2482 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2483 | // Callers targeting S have no business invoking this method. |
| 2484 | return; |
| 2485 | } |
| 2486 | |
| 2487 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2488 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2489 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2490 | .setCallingPackage(callingPackage) |
| 2491 | .setCallingFeatureId(null) |
| 2492 | .setCallingPid(Binder.getCallingPid()) |
| 2493 | .setCallingUid(Binder.getCallingUid()) |
| 2494 | .setMethod("updateServiceLocation") |
| 2495 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2496 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2497 | .build()); |
| 2498 | // Apps that lack location permission have no business calling this method; |
| 2499 | // however, because no permission was declared in the public API, denials must |
| 2500 | // all be "soft". |
| 2501 | switch (locationResult) { |
| 2502 | case DENIED_HARD: /* fall through */ |
| 2503 | case DENIED_SOFT: |
| 2504 | return; |
| 2505 | } |
| 2506 | |
| 2507 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2508 | final long identity = Binder.clearCallingIdentity(); |
| 2509 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2510 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2511 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2512 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2513 | } |
| 2514 | } finally { |
| 2515 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2516 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2517 | } |
| 2518 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2519 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2520 | @Override |
| 2521 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2522 | return isRadioOnWithFeature(callingPackage, null); |
| 2523 | } |
| 2524 | |
| 2525 | |
| 2526 | @Override |
| 2527 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2528 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2529 | callingFeatureId); |
| 2530 | } |
| 2531 | |
| 2532 | @Deprecated |
| 2533 | @Override |
| 2534 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2535 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2536 | } |
| 2537 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2538 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2539 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2540 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2541 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2542 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2543 | return false; |
| 2544 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2545 | |
| 2546 | final long identity = Binder.clearCallingIdentity(); |
| 2547 | try { |
| 2548 | return isRadioOnForSubscriber(subId); |
| 2549 | } finally { |
| 2550 | Binder.restoreCallingIdentity(identity); |
| 2551 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2552 | } |
| 2553 | |
| 2554 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2555 | final long identity = Binder.clearCallingIdentity(); |
| 2556 | try { |
| 2557 | final Phone phone = getPhone(subId); |
| 2558 | if (phone != null) { |
| 2559 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2560 | } else { |
| 2561 | return false; |
| 2562 | } |
| 2563 | } finally { |
| 2564 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2565 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2566 | } |
| 2567 | |
| 2568 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2569 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2570 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2571 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2572 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2573 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2574 | |
| 2575 | final long identity = Binder.clearCallingIdentity(); |
| 2576 | try { |
| 2577 | final Phone phone = getPhone(subId); |
| 2578 | if (phone != null) { |
| 2579 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2580 | } |
| 2581 | } finally { |
| 2582 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2583 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2584 | } |
| 2585 | |
| 2586 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2587 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2588 | } |
| 2589 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2590 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2591 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2592 | |
| 2593 | final long identity = Binder.clearCallingIdentity(); |
| 2594 | try { |
| 2595 | final Phone phone = getPhone(subId); |
| 2596 | if (phone == null) { |
| 2597 | return false; |
| 2598 | } |
| 2599 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2600 | toggleRadioOnOffForSubscriber(subId); |
| 2601 | } |
| 2602 | return true; |
| 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 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2607 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2608 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2609 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2610 | /* |
| 2611 | * If any of the Radios are available, it will need to be |
| 2612 | * shutdown. So return true if any Radio is available. |
| 2613 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2614 | final long identity = Binder.clearCallingIdentity(); |
| 2615 | try { |
| 2616 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2617 | Phone phone = PhoneFactory.getPhone(i); |
| 2618 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2619 | } |
| 2620 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2621 | return false; |
| 2622 | } finally { |
| 2623 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2624 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2625 | } |
| 2626 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2627 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2628 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2629 | enforceModifyPermission(); |
| 2630 | |
| 2631 | final long identity = Binder.clearCallingIdentity(); |
| 2632 | try { |
| 2633 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2634 | logv("Shutting down Phone " + i); |
| 2635 | shutdownRadioUsingPhoneId(i); |
| 2636 | } |
| 2637 | } finally { |
| 2638 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2639 | } |
| 2640 | } |
| 2641 | |
| 2642 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2643 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2644 | if (phone != null && phone.isRadioAvailable()) { |
| 2645 | phone.shutdownRadio(); |
| 2646 | } |
| 2647 | } |
| 2648 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2649 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2650 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2651 | |
| 2652 | final long identity = Binder.clearCallingIdentity(); |
| 2653 | try { |
| 2654 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2655 | if (defaultPhone != null) { |
| 2656 | defaultPhone.setRadioPower(turnOn); |
| 2657 | return true; |
| 2658 | } else { |
| 2659 | loge("There's no default phone."); |
| 2660 | return false; |
| 2661 | } |
| 2662 | } finally { |
| 2663 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2664 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2665 | } |
| 2666 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2667 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2668 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2669 | |
| 2670 | final long identity = Binder.clearCallingIdentity(); |
| 2671 | try { |
| 2672 | final Phone phone = getPhone(subId); |
| 2673 | if (phone != null) { |
| 2674 | phone.setRadioPower(turnOn); |
| 2675 | return true; |
| 2676 | } else { |
| 2677 | return false; |
| 2678 | } |
| 2679 | } finally { |
| 2680 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2681 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2682 | } |
| 2683 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2684 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2685 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2686 | public boolean enableDataConnectivity() { |
| 2687 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2688 | |
| 2689 | final long identity = Binder.clearCallingIdentity(); |
| 2690 | try { |
| 2691 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2692 | final Phone phone = getPhone(subId); |
| 2693 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2694 | phone.getDataEnabledSettings().setDataEnabled( |
| 2695 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2696 | return true; |
| 2697 | } else { |
| 2698 | return false; |
| 2699 | } |
| 2700 | } finally { |
| 2701 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2702 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2703 | } |
| 2704 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2705 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2706 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2707 | public boolean disableDataConnectivity() { |
| 2708 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2709 | |
| 2710 | final long identity = Binder.clearCallingIdentity(); |
| 2711 | try { |
| 2712 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2713 | final Phone phone = getPhone(subId); |
| 2714 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2715 | phone.getDataEnabledSettings().setDataEnabled( |
| 2716 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2717 | return true; |
| 2718 | } else { |
| 2719 | return false; |
| 2720 | } |
| 2721 | } finally { |
| 2722 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2723 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2724 | } |
| 2725 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2726 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2727 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2728 | final long identity = Binder.clearCallingIdentity(); |
| 2729 | try { |
| 2730 | final Phone phone = getPhone(subId); |
| 2731 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2732 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2733 | } else { |
| 2734 | return false; |
| 2735 | } |
| 2736 | } finally { |
| 2737 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2738 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2739 | } |
| 2740 | |
| 2741 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2742 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2743 | } |
| 2744 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2745 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2746 | enforceCallPermission(); |
| 2747 | |
| 2748 | final long identity = Binder.clearCallingIdentity(); |
| 2749 | try { |
| 2750 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2751 | return; |
| 2752 | } |
| 2753 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2754 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2755 | } finally { |
| 2756 | Binder.restoreCallingIdentity(identity); |
| 2757 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2758 | }; |
| 2759 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2760 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2761 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2762 | |
| 2763 | final long identity = Binder.clearCallingIdentity(); |
| 2764 | try { |
| 2765 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2766 | return false; |
| 2767 | } |
| 2768 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2769 | } finally { |
| 2770 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2771 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2772 | } |
| 2773 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2774 | /** |
| 2775 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 2776 | * tag on getCallState Binder call. |
| 2777 | */ |
| 2778 | @Deprecated |
| 2779 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2780 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2781 | if (CompatChanges.isChangeEnabled( |
| 2782 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2783 | Binder.getCallingUid())) { |
| 2784 | // Do not allow this API to be called on API version 31+, it should only be |
| 2785 | // called on old apps using this Binder call directly. |
| 2786 | throw new SecurityException("This method can only be used for applications " |
| 2787 | + "targeting API version 30 or less."); |
| 2788 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2789 | final long identity = Binder.clearCallingIdentity(); |
| 2790 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2791 | Phone phone = getPhone(getDefaultSubscription()); |
| 2792 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2793 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2794 | } finally { |
| 2795 | Binder.restoreCallingIdentity(identity); |
| 2796 | } |
| 2797 | } |
| 2798 | |
| 2799 | @Override |
| 2800 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 2801 | if (CompatChanges.isChangeEnabled( |
| 2802 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2803 | Binder.getCallingUid())) { |
| 2804 | // Check READ_PHONE_STATE for API version 31+ |
| 2805 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2806 | featureId, "getCallStateForSubscription")) { |
| 2807 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 2808 | + "targeting API level 31+."); |
| 2809 | } |
| 2810 | } |
| 2811 | final long identity = Binder.clearCallingIdentity(); |
| 2812 | try { |
| 2813 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2814 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2815 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2816 | } finally { |
| 2817 | Binder.restoreCallingIdentity(identity); |
| 2818 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2819 | } |
| 2820 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2821 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2822 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2823 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2824 | } |
| 2825 | |
| 2826 | @Override |
| 2827 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2828 | final long identity = Binder.clearCallingIdentity(); |
| 2829 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2830 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2831 | if (phone != null) { |
| 2832 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2833 | } else { |
| 2834 | return PhoneConstantConversions.convertDataState( |
| 2835 | PhoneConstants.DataState.DISCONNECTED); |
| 2836 | } |
| 2837 | } finally { |
| 2838 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2839 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2840 | } |
| 2841 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2842 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2843 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2844 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2845 | } |
| 2846 | |
| 2847 | @Override |
| 2848 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2849 | final long identity = Binder.clearCallingIdentity(); |
| 2850 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2851 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2852 | if (phone != null) { |
| 2853 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2854 | } else { |
| 2855 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2856 | } |
| 2857 | } finally { |
| 2858 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2859 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2860 | } |
| 2861 | |
| 2862 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2863 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2864 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2865 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2866 | |
| 2867 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2868 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2869 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2870 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2871 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2872 | .setCallingPid(Binder.getCallingPid()) |
| 2873 | .setCallingUid(Binder.getCallingUid()) |
| 2874 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2875 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2876 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2877 | .build()); |
| 2878 | switch (locationResult) { |
| 2879 | case DENIED_HARD: |
| 2880 | throw new SecurityException("Not allowed to access cell location"); |
| 2881 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2882 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2883 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2884 | } |
| 2885 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2886 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2887 | final long identity = Binder.clearCallingIdentity(); |
| 2888 | try { |
| 2889 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2890 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2891 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2892 | } finally { |
| 2893 | Binder.restoreCallingIdentity(identity); |
| 2894 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2895 | } |
| 2896 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2897 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2898 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2899 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2900 | // registered cell info, so return a NULL country instead. |
| 2901 | final long identity = Binder.clearCallingIdentity(); |
| 2902 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2903 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2904 | // Get default phone in this case. |
| 2905 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2906 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2907 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2908 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2909 | if (phone == null) return ""; |
| 2910 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2911 | if (sst == null) return ""; |
| 2912 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2913 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 2914 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2915 | } finally { |
| 2916 | Binder.restoreCallingIdentity(identity); |
| 2917 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2918 | } |
| 2919 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2920 | /** |
| 2921 | * This method was removed due to potential issues caused by performing partial |
| 2922 | * updates of service state, and lack of a credible use case. |
| 2923 | * |
| 2924 | * This has the ability to break the telephony implementation by disabling notification of |
| 2925 | * changes in device connectivity. DO NOT USE THIS! |
| 2926 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2927 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2928 | public void enableLocationUpdates() { |
| 2929 | mApp.enforceCallingOrSelfPermission( |
| 2930 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2931 | } |
| 2932 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2933 | /** |
| 2934 | * This method was removed due to potential issues caused by performing partial |
| 2935 | * updates of service state, and lack of a credible use case. |
| 2936 | * |
| 2937 | * This has the ability to break the telephony implementation by disabling notification of |
| 2938 | * changes in device connectivity. DO NOT USE THIS! |
| 2939 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2940 | @Override |
| 2941 | public void disableLocationUpdates() { |
| 2942 | mApp.enforceCallingOrSelfPermission( |
| 2943 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2944 | } |
| 2945 | |
| 2946 | @Override |
| 2947 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2948 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2949 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2950 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2951 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2952 | throw new SecurityException( |
| 2953 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2954 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2955 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2956 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2957 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2958 | return null; |
| 2959 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2960 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2961 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2962 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2963 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2964 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2965 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2966 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2967 | for (CellInfo ci : info) { |
| 2968 | if (ci instanceof CellInfoGsm) { |
| 2969 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2970 | } else if (ci instanceof CellInfoWcdma) { |
| 2971 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2972 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2973 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2974 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2975 | } |
| 2976 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2977 | private List<CellInfo> getCachedCellInfo() { |
| 2978 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2979 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2980 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2981 | if (info != null) cellInfos.addAll(info); |
| 2982 | } |
| 2983 | return cellInfos; |
| 2984 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2985 | |
| 2986 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2987 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2988 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2989 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2990 | |
| 2991 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2992 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2993 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2994 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2995 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2996 | .setCallingPid(Binder.getCallingPid()) |
| 2997 | .setCallingUid(Binder.getCallingUid()) |
| 2998 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2999 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3000 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3001 | .build()); |
| 3002 | switch (locationResult) { |
| 3003 | case DENIED_HARD: |
| 3004 | throw new SecurityException("Not allowed to access cell info"); |
| 3005 | case DENIED_SOFT: |
| 3006 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3007 | } |
| 3008 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3009 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3010 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3011 | return getCachedCellInfo(); |
| 3012 | } |
| 3013 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3014 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3015 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3016 | final long identity = Binder.clearCallingIdentity(); |
| 3017 | try { |
| 3018 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3019 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3020 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3021 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3022 | if (info != null) cellInfos.addAll(info); |
| 3023 | } |
| 3024 | return cellInfos; |
| 3025 | } finally { |
| 3026 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3027 | } |
| 3028 | } |
| 3029 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3030 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3031 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3032 | String callingFeatureId) { |
| 3033 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3034 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3035 | } |
| 3036 | |
| 3037 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3038 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3039 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3040 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3041 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3042 | } |
| 3043 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3044 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3045 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3046 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3047 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3048 | |
| 3049 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3050 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3051 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3052 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3053 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3054 | .setCallingPid(Binder.getCallingPid()) |
| 3055 | .setCallingUid(Binder.getCallingUid()) |
| 3056 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3057 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3058 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3059 | .build()); |
| 3060 | switch (locationResult) { |
| 3061 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3062 | if (TelephonyPermissions |
| 3063 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3064 | // Safetynet logging for b/154934934 |
| 3065 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3066 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3067 | throw new SecurityException("Not allowed to access cell info"); |
| 3068 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3069 | if (TelephonyPermissions |
| 3070 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3071 | // Safetynet logging for b/154934934 |
| 3072 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3073 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3074 | try { |
| 3075 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3076 | } catch (RemoteException re) { |
| 3077 | // Drop without consequences |
| 3078 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3079 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3080 | } |
| 3081 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3082 | |
| 3083 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3084 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3085 | |
| 3086 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3087 | } |
| 3088 | |
| 3089 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3090 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3091 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3092 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3093 | |
| 3094 | final long identity = Binder.clearCallingIdentity(); |
| 3095 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3096 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3097 | } finally { |
| 3098 | Binder.restoreCallingIdentity(identity); |
| 3099 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3100 | } |
| 3101 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3102 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3103 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3104 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3105 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3106 | return null; |
| 3107 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3108 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3109 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3110 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3111 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3112 | return null; |
| 3113 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3114 | |
| 3115 | final long identity = Binder.clearCallingIdentity(); |
| 3116 | try { |
| 3117 | return phone.getImei(); |
| 3118 | } finally { |
| 3119 | Binder.restoreCallingIdentity(identity); |
| 3120 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3121 | } |
| 3122 | |
| 3123 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3124 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3125 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3126 | String tac = null; |
| 3127 | if (phone != null) { |
| 3128 | String imei = phone.getImei(); |
| 3129 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3130 | } |
| 3131 | return tac; |
| 3132 | } |
| 3133 | |
| 3134 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3135 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3136 | try { |
| 3137 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3138 | } catch (SecurityException se) { |
| 3139 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3140 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3141 | + Binder.getCallingUid()); |
| 3142 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3143 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3144 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3145 | return null; |
| 3146 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3147 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3148 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3149 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3150 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3151 | return null; |
| 3152 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3153 | |
| 3154 | final long identity = Binder.clearCallingIdentity(); |
| 3155 | try { |
| 3156 | return phone.getMeid(); |
| 3157 | } finally { |
| 3158 | Binder.restoreCallingIdentity(identity); |
| 3159 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3160 | } |
| 3161 | |
| 3162 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3163 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3164 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3165 | String manufacturerCode = null; |
| 3166 | if (phone != null) { |
| 3167 | String meid = phone.getMeid(); |
| 3168 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3169 | } |
| 3170 | return manufacturerCode; |
| 3171 | } |
| 3172 | |
| 3173 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3174 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3175 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3176 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3177 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3178 | return null; |
| 3179 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3180 | int subId = phone.getSubId(); |
| 3181 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3182 | mApp, subId, callingPackage, callingFeatureId, |
| 3183 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3184 | return null; |
| 3185 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3186 | |
| 3187 | final long identity = Binder.clearCallingIdentity(); |
| 3188 | try { |
| 3189 | return phone.getDeviceSvn(); |
| 3190 | } finally { |
| 3191 | Binder.restoreCallingIdentity(identity); |
| 3192 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3193 | } |
| 3194 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3195 | @Override |
| 3196 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3197 | final long identity = Binder.clearCallingIdentity(); |
| 3198 | try { |
| 3199 | final Phone phone = getPhone(subId); |
| 3200 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3201 | } finally { |
| 3202 | Binder.restoreCallingIdentity(identity); |
| 3203 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3204 | } |
| 3205 | |
| 3206 | @Override |
| 3207 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3208 | final long identity = Binder.clearCallingIdentity(); |
| 3209 | try { |
| 3210 | final Phone phone = getPhone(subId); |
| 3211 | return phone == null ? null : phone.getCarrierName(); |
| 3212 | } finally { |
| 3213 | Binder.restoreCallingIdentity(identity); |
| 3214 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3215 | } |
| 3216 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3217 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3218 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3219 | final long identity = Binder.clearCallingIdentity(); |
| 3220 | try { |
| 3221 | final Phone phone = getPhone(subId); |
| 3222 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3223 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3224 | } finally { |
| 3225 | Binder.restoreCallingIdentity(identity); |
| 3226 | } |
| 3227 | } |
| 3228 | |
| 3229 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3230 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3231 | final long identity = Binder.clearCallingIdentity(); |
| 3232 | try { |
| 3233 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3234 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3235 | } finally { |
| 3236 | Binder.restoreCallingIdentity(identity); |
| 3237 | } |
| 3238 | } |
| 3239 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3240 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3241 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3242 | if (!isSubscriptionMccMnc) { |
| 3243 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3244 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3245 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3246 | if (phone == null) { |
| 3247 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3248 | } |
| 3249 | final long identity = Binder.clearCallingIdentity(); |
| 3250 | try { |
| 3251 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3252 | } finally { |
| 3253 | Binder.restoreCallingIdentity(identity); |
| 3254 | } |
| 3255 | } |
| 3256 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3257 | // |
| 3258 | // Internal helper methods. |
| 3259 | // |
| 3260 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3261 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3262 | * Make sure the caller is the calling package itself |
| 3263 | * |
| 3264 | * @throws SecurityException if the caller is not the calling package |
| 3265 | */ |
| 3266 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3267 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3268 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3269 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3270 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3271 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3272 | } catch (PackageManager.NameNotFoundException e) { |
| 3273 | // packageUid is -1 |
| 3274 | } |
| 3275 | if (packageUid != callingUid) { |
| 3276 | throw new SecurityException(message + ": Package " + callingPackage |
| 3277 | + " does not belong to " + callingUid); |
| 3278 | } |
| 3279 | } |
| 3280 | |
| 3281 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3282 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3283 | * |
| 3284 | * @throws SecurityException if the caller does not have the required permission |
| 3285 | */ |
| 3286 | private void enforceModifyPermission() { |
| 3287 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3288 | } |
| 3289 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3290 | /** |
| 3291 | * Make sure the caller is system. |
| 3292 | * |
| 3293 | * @throws SecurityException if the caller is not system. |
| 3294 | */ |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 3295 | private static void enforceSystemCaller() { |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3296 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3297 | throw new SecurityException("Caller must be system"); |
| 3298 | } |
| 3299 | } |
| 3300 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3301 | private void enforceActiveEmergencySessionPermission() { |
| 3302 | mApp.enforceCallingOrSelfPermission( |
| 3303 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3304 | } |
| 3305 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3306 | /** |
| 3307 | * Make sure the caller has the CALL_PHONE permission. |
| 3308 | * |
| 3309 | * @throws SecurityException if the caller does not have the required permission |
| 3310 | */ |
| 3311 | private void enforceCallPermission() { |
| 3312 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3313 | } |
| 3314 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3315 | private void enforceSettingsPermission() { |
| 3316 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3317 | } |
| 3318 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3319 | private void enforceRebootPermission() { |
| 3320 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3321 | } |
| 3322 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3323 | private String createTelUrl(String number) { |
| 3324 | if (TextUtils.isEmpty(number)) { |
| 3325 | return null; |
| 3326 | } |
| 3327 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3328 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3329 | } |
| 3330 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3331 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3332 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3333 | } |
| 3334 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3335 | private static void logv(String msg) { |
| 3336 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3337 | } |
| 3338 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3339 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3340 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3341 | } |
| 3342 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3343 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3344 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3345 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3346 | } |
| 3347 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3348 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3349 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3350 | final long identity = Binder.clearCallingIdentity(); |
| 3351 | try { |
| 3352 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3353 | if (phone == null) { |
| 3354 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3355 | } else { |
| 3356 | return phone.getPhoneType(); |
| 3357 | } |
| 3358 | } finally { |
| 3359 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3360 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3361 | } |
| 3362 | |
| 3363 | /** |
| 3364 | * Returns the CDMA ERI icon index to display |
| 3365 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3366 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3367 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3368 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3369 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3370 | } |
| 3371 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3372 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3373 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3374 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3375 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3376 | mApp, subId, callingPackage, callingFeatureId, |
| 3377 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3378 | return -1; |
| 3379 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3380 | |
| 3381 | final long identity = Binder.clearCallingIdentity(); |
| 3382 | try { |
| 3383 | final Phone phone = getPhone(subId); |
| 3384 | if (phone != null) { |
| 3385 | return phone.getCdmaEriIconIndex(); |
| 3386 | } else { |
| 3387 | return -1; |
| 3388 | } |
| 3389 | } finally { |
| 3390 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3391 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3392 | } |
| 3393 | |
| 3394 | /** |
| 3395 | * Returns the CDMA ERI icon mode, |
| 3396 | * 0 - ON |
| 3397 | * 1 - FLASHING |
| 3398 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3399 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3400 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3401 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3402 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3403 | } |
| 3404 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3405 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3406 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3407 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3408 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3409 | mApp, subId, callingPackage, callingFeatureId, |
| 3410 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3411 | return -1; |
| 3412 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3413 | |
| 3414 | final long identity = Binder.clearCallingIdentity(); |
| 3415 | try { |
| 3416 | final Phone phone = getPhone(subId); |
| 3417 | if (phone != null) { |
| 3418 | return phone.getCdmaEriIconMode(); |
| 3419 | } else { |
| 3420 | return -1; |
| 3421 | } |
| 3422 | } finally { |
| 3423 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3424 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3425 | } |
| 3426 | |
| 3427 | /** |
| 3428 | * Returns the CDMA ERI text, |
| 3429 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3430 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3431 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3432 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3433 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3434 | } |
| 3435 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3436 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3437 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3438 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3439 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3440 | mApp, subId, callingPackage, callingFeatureId, |
| 3441 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3442 | return null; |
| 3443 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3444 | |
| 3445 | final long identity = Binder.clearCallingIdentity(); |
| 3446 | try { |
| 3447 | final Phone phone = getPhone(subId); |
| 3448 | if (phone != null) { |
| 3449 | return phone.getCdmaEriText(); |
| 3450 | } else { |
| 3451 | return null; |
| 3452 | } |
| 3453 | } finally { |
| 3454 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3455 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3456 | } |
| 3457 | |
| 3458 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3459 | * Returns the CDMA MDN. |
| 3460 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3461 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3462 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3463 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3464 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3465 | |
| 3466 | final long identity = Binder.clearCallingIdentity(); |
| 3467 | try { |
| 3468 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3469 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3470 | return phone.getLine1Number(); |
| 3471 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3472 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3473 | return null; |
| 3474 | } |
| 3475 | } finally { |
| 3476 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3477 | } |
| 3478 | } |
| 3479 | |
| 3480 | /** |
| 3481 | * Returns the CDMA MIN. |
| 3482 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3483 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3484 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3485 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3486 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3487 | |
| 3488 | final long identity = Binder.clearCallingIdentity(); |
| 3489 | try { |
| 3490 | final Phone phone = getPhone(subId); |
| 3491 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3492 | return phone.getCdmaMin(); |
| 3493 | } else { |
| 3494 | return null; |
| 3495 | } |
| 3496 | } finally { |
| 3497 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3498 | } |
| 3499 | } |
| 3500 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3501 | @Override |
| 3502 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3503 | INumberVerificationCallback callback, String callingPackage) { |
| 3504 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3505 | != PERMISSION_GRANTED) { |
| 3506 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3507 | } |
| 3508 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3509 | |
| 3510 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3511 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3512 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3513 | + "calling package: " + callingPackage |
| 3514 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3515 | } |
| 3516 | |
| 3517 | if (range == null) { |
| 3518 | throw new NullPointerException("Range must be non-null"); |
| 3519 | } |
| 3520 | |
| 3521 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3522 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3523 | |
| 3524 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3525 | } |
| 3526 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3527 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3528 | * Returns true if CDMA provisioning needs to run. |
| 3529 | */ |
| 3530 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3531 | final long identity = Binder.clearCallingIdentity(); |
| 3532 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3533 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3534 | } finally { |
| 3535 | Binder.restoreCallingIdentity(identity); |
| 3536 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3537 | } |
| 3538 | |
| 3539 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3540 | * Sets the voice mail number of a given subId. |
| 3541 | */ |
| 3542 | @Override |
| 3543 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3544 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3545 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3546 | |
| 3547 | final long identity = Binder.clearCallingIdentity(); |
| 3548 | try { |
| 3549 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3550 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3551 | return success; |
| 3552 | } finally { |
| 3553 | Binder.restoreCallingIdentity(identity); |
| 3554 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3555 | } |
| 3556 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3557 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3558 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3559 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3560 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3561 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3562 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3563 | throw new SecurityException("caller must be system dialer"); |
| 3564 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3565 | |
| 3566 | final long identity = Binder.clearCallingIdentity(); |
| 3567 | try { |
| 3568 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3569 | if (phoneAccountHandle == null) { |
| 3570 | return null; |
| 3571 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3572 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3573 | } finally { |
| 3574 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3575 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3576 | } |
| 3577 | |
| 3578 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3579 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3580 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3581 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3582 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3583 | mApp, subId, callingPackage, callingFeatureId, |
| 3584 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3585 | return null; |
| 3586 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3587 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3588 | final long identity = Binder.clearCallingIdentity(); |
| 3589 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3590 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3591 | } finally { |
| 3592 | Binder.restoreCallingIdentity(identity); |
| 3593 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3594 | } |
| 3595 | |
| 3596 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3597 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3598 | VisualVoicemailSmsFilterSettings settings) { |
| 3599 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3600 | |
| 3601 | final long identity = Binder.clearCallingIdentity(); |
| 3602 | try { |
| 3603 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3604 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3605 | } finally { |
| 3606 | Binder.restoreCallingIdentity(identity); |
| 3607 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3608 | } |
| 3609 | |
| 3610 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3611 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3612 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3613 | |
| 3614 | final long identity = Binder.clearCallingIdentity(); |
| 3615 | try { |
| 3616 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3617 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3618 | } finally { |
| 3619 | Binder.restoreCallingIdentity(identity); |
| 3620 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3621 | } |
| 3622 | |
| 3623 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3624 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3625 | String callingPackage, int subId) { |
| 3626 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3627 | |
| 3628 | final long identity = Binder.clearCallingIdentity(); |
| 3629 | try { |
| 3630 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3631 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3632 | } finally { |
| 3633 | Binder.restoreCallingIdentity(identity); |
| 3634 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3635 | } |
| 3636 | |
| 3637 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3638 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3639 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3640 | |
| 3641 | final long identity = Binder.clearCallingIdentity(); |
| 3642 | try { |
| 3643 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3644 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3645 | } finally { |
| 3646 | Binder.restoreCallingIdentity(identity); |
| 3647 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3648 | } |
| 3649 | |
| 3650 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3651 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3652 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3653 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3654 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3655 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3656 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3657 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3658 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3659 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3660 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3661 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3662 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3663 | * Sets the voice activation state of a given subId. |
| 3664 | */ |
| 3665 | @Override |
| 3666 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3667 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3668 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3669 | |
| 3670 | final long identity = Binder.clearCallingIdentity(); |
| 3671 | try { |
| 3672 | final Phone phone = getPhone(subId); |
| 3673 | if (phone != null) { |
| 3674 | phone.setVoiceActivationState(activationState); |
| 3675 | } else { |
| 3676 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3677 | } |
| 3678 | } finally { |
| 3679 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3680 | } |
| 3681 | } |
| 3682 | |
| 3683 | /** |
| 3684 | * Sets the data activation state of a given subId. |
| 3685 | */ |
| 3686 | @Override |
| 3687 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3688 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3689 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3690 | |
| 3691 | final long identity = Binder.clearCallingIdentity(); |
| 3692 | try { |
| 3693 | final Phone phone = getPhone(subId); |
| 3694 | if (phone != null) { |
| 3695 | phone.setDataActivationState(activationState); |
| 3696 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3697 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3698 | } |
| 3699 | } finally { |
| 3700 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3701 | } |
| 3702 | } |
| 3703 | |
| 3704 | /** |
| 3705 | * Returns the voice activation state of a given subId. |
| 3706 | */ |
| 3707 | @Override |
| 3708 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3709 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3710 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3711 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3712 | final long identity = Binder.clearCallingIdentity(); |
| 3713 | try { |
| 3714 | if (phone != null) { |
| 3715 | return phone.getVoiceActivationState(); |
| 3716 | } else { |
| 3717 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3718 | } |
| 3719 | } finally { |
| 3720 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3721 | } |
| 3722 | } |
| 3723 | |
| 3724 | /** |
| 3725 | * Returns the data activation state of a given subId. |
| 3726 | */ |
| 3727 | @Override |
| 3728 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3729 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3730 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3731 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3732 | final long identity = Binder.clearCallingIdentity(); |
| 3733 | try { |
| 3734 | if (phone != null) { |
| 3735 | return phone.getDataActivationState(); |
| 3736 | } else { |
| 3737 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3738 | } |
| 3739 | } finally { |
| 3740 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3741 | } |
| 3742 | } |
| 3743 | |
| 3744 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3745 | * Returns the unread count of voicemails for a subId |
| 3746 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3747 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3748 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3749 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3750 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3751 | mApp, subId, callingPackage, callingFeatureId, |
| 3752 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3753 | return 0; |
| 3754 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3755 | final long identity = Binder.clearCallingIdentity(); |
| 3756 | try { |
| 3757 | final Phone phone = getPhone(subId); |
| 3758 | if (phone != null) { |
| 3759 | return phone.getVoiceMessageCount(); |
| 3760 | } else { |
| 3761 | return 0; |
| 3762 | } |
| 3763 | } finally { |
| 3764 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3765 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3766 | } |
| 3767 | |
| 3768 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3769 | * returns true, if the device is in a state where both voice and data |
| 3770 | * are supported simultaneously. This can change based on location or network condition. |
| 3771 | */ |
| 3772 | @Override |
| 3773 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3774 | final long identity = Binder.clearCallingIdentity(); |
| 3775 | try { |
| 3776 | final Phone phone = getPhone(subId); |
| 3777 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3778 | } finally { |
| 3779 | Binder.restoreCallingIdentity(identity); |
| 3780 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3781 | } |
| 3782 | |
| 3783 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3784 | * Send the dialer code if called from the current default dialer or the caller has |
| 3785 | * carrier privilege. |
| 3786 | * @param inputCode The dialer code to send |
| 3787 | */ |
| 3788 | @Override |
| 3789 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3790 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3791 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3792 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3793 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3794 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3795 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3796 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3797 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3798 | |
| 3799 | final long identity = Binder.clearCallingIdentity(); |
| 3800 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3801 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3802 | } finally { |
| 3803 | Binder.restoreCallingIdentity(identity); |
| 3804 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3805 | } |
| 3806 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3807 | @Override |
| 3808 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3809 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3810 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3811 | mApp, subId, "getNetworkSelectionMode"); |
| 3812 | final long identity = Binder.clearCallingIdentity(); |
| 3813 | try { |
| 3814 | if (!isActiveSubscription(subId)) { |
| 3815 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3816 | } |
| 3817 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3818 | } finally { |
| 3819 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3820 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3821 | } |
| 3822 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3823 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3824 | public boolean isInEmergencySmsMode() { |
| 3825 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3826 | final long identity = Binder.clearCallingIdentity(); |
| 3827 | try { |
| 3828 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3829 | if (phone.isInEmergencySmsMode()) { |
| 3830 | return true; |
| 3831 | } |
| 3832 | } |
| 3833 | } finally { |
| 3834 | Binder.restoreCallingIdentity(identity); |
| 3835 | } |
| 3836 | return false; |
| 3837 | } |
| 3838 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3839 | /** |
| 3840 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3841 | * @param subId The subscription to use to check the configuration. |
| 3842 | * @param c The callback that will be used to send the result. |
| 3843 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3844 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3845 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3846 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3847 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3848 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3849 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3850 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3851 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3852 | "IMS not available on device."); |
| 3853 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3854 | final long token = Binder.clearCallingIdentity(); |
| 3855 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 3856 | int slotId = getSlotIndexOrException(subId); |
| 3857 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 3858 | ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3859 | } catch (ImsException e) { |
| 3860 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3861 | } finally { |
| 3862 | Binder.restoreCallingIdentity(token); |
| 3863 | } |
| 3864 | } |
| 3865 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3866 | /** |
| 3867 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3868 | * @param subId The subscription to use to check the configuration. |
| 3869 | * @param c The callback that will be used to send the result. |
| 3870 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3871 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3872 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3873 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3874 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3875 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3876 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3877 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3878 | final long token = Binder.clearCallingIdentity(); |
| 3879 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3880 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3881 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3882 | } catch (ImsException e) { |
| 3883 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3884 | + "is inactive, ignoring unregister."); |
| 3885 | // If the subscription is no longer active, just return, since the callback |
| 3886 | // will already have been removed internally. |
| 3887 | } finally { |
| 3888 | Binder.restoreCallingIdentity(token); |
| 3889 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3890 | } |
| 3891 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3892 | /** |
| 3893 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3894 | */ |
| 3895 | @Override |
| 3896 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3897 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3898 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3899 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3900 | "IMS not available on device."); |
| 3901 | } |
| 3902 | final long token = Binder.clearCallingIdentity(); |
| 3903 | try { |
| 3904 | Phone phone = getPhone(subId); |
| 3905 | if (phone == null) { |
| 3906 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3907 | + subId + "'"); |
| 3908 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3909 | } |
| 3910 | phone.getImsRegistrationState(regState -> { |
| 3911 | try { |
| 3912 | consumer.accept((regState == null) |
| 3913 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3914 | } catch (RemoteException e) { |
| 3915 | // Ignore if the remote process is no longer available to call back. |
| 3916 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3917 | } |
| 3918 | }); |
| 3919 | } finally { |
| 3920 | Binder.restoreCallingIdentity(token); |
| 3921 | } |
| 3922 | } |
| 3923 | |
| 3924 | /** |
| 3925 | * Get the transport type for the IMS service registration state. |
| 3926 | */ |
| 3927 | @Override |
| 3928 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3929 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3930 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3931 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3932 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3933 | "IMS not available on device."); |
| 3934 | } |
| 3935 | final long token = Binder.clearCallingIdentity(); |
| 3936 | try { |
| 3937 | Phone phone = getPhone(subId); |
| 3938 | if (phone == null) { |
| 3939 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3940 | + subId + "'"); |
| 3941 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3942 | } |
| 3943 | phone.getImsRegistrationTech(regTech -> { |
| 3944 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3945 | int regTechConverted = (regTech == null) |
| 3946 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3947 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3948 | regTechConverted); |
| 3949 | try { |
| 3950 | consumer.accept(regTechConverted); |
| 3951 | } catch (RemoteException e) { |
| 3952 | // Ignore if the remote process is no longer available to call back. |
| 3953 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3954 | } |
| 3955 | }); |
| 3956 | } finally { |
| 3957 | Binder.restoreCallingIdentity(token); |
| 3958 | } |
| 3959 | } |
| 3960 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3961 | /** |
| 3962 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3963 | * @param subId The subscription to use to check the configuration. |
| 3964 | * @param c The callback that will be used to send the result. |
| 3965 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3966 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3967 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3968 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3969 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3970 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3971 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3972 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3973 | "IMS not available on device."); |
| 3974 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3975 | final long token = Binder.clearCallingIdentity(); |
| 3976 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 3977 | int slotId = getSlotIndexOrException(subId); |
| 3978 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 3979 | ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3980 | } catch (ImsException e) { |
| 3981 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3982 | } finally { |
| 3983 | Binder.restoreCallingIdentity(token); |
| 3984 | } |
| 3985 | } |
| 3986 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3987 | /** |
| 3988 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3989 | * @param subId The subscription to use to check the configuration. |
| 3990 | * @param c The callback that will be used to send the result. |
| 3991 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3992 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3993 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3994 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3995 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3996 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3997 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3998 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3999 | |
| 4000 | final long token = Binder.clearCallingIdentity(); |
| 4001 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4002 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4003 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4004 | } catch (ImsException e) { |
| 4005 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4006 | + "is inactive, ignoring unregister."); |
| 4007 | // If the subscription is no longer active, just return, since the callback |
| 4008 | // will already have been removed internally. |
| 4009 | } finally { |
| 4010 | Binder.restoreCallingIdentity(token); |
| 4011 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4012 | } |
| 4013 | |
| 4014 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4015 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4016 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4017 | final long token = Binder.clearCallingIdentity(); |
| 4018 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4019 | int slotId = getSlotIndexOrException(subId); |
| 4020 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4021 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4022 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4023 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4024 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4025 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4026 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4027 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4028 | } finally { |
| 4029 | Binder.restoreCallingIdentity(token); |
| 4030 | } |
| 4031 | } |
| 4032 | |
| 4033 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4034 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4035 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4036 | final long token = Binder.clearCallingIdentity(); |
| 4037 | try { |
| 4038 | Phone phone = getPhone(subId); |
| 4039 | if (phone == null) return false; |
| 4040 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4041 | } catch (com.android.ims.ImsException e) { |
| 4042 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4043 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4044 | } finally { |
| 4045 | Binder.restoreCallingIdentity(token); |
| 4046 | } |
| 4047 | } |
| 4048 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4049 | /** |
| 4050 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4051 | * subscription. |
| 4052 | * @param subId The subscription to use to check the configuration. |
| 4053 | * @param callback The callback that will be used to send the result. |
| 4054 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4055 | * @param transportType The transport type of the MmTelFeature capability. |
| 4056 | */ |
| 4057 | @Override |
| 4058 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4059 | int transportType) { |
| 4060 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 4061 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4062 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4063 | "IMS not available on device."); |
| 4064 | } |
| 4065 | final long token = Binder.clearCallingIdentity(); |
| 4066 | try { |
| 4067 | int slotId = getSlotIndex(subId); |
| 4068 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4069 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4070 | + subId + "'"); |
| 4071 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4072 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4073 | verifyImsMmTelConfiguredOrThrow(slotId); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4074 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4075 | transportType, aBoolean -> { |
| 4076 | try { |
| 4077 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4078 | } catch (RemoteException e) { |
| 4079 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4080 | + "running. Ignore"); |
| 4081 | } |
| 4082 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4083 | } catch (ImsException e) { |
| 4084 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4085 | } finally { |
| 4086 | Binder.restoreCallingIdentity(token); |
| 4087 | } |
| 4088 | } |
| 4089 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4090 | /** |
| 4091 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4092 | * @param subId The subscription to use to check the configuration. |
| 4093 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4094 | @Override |
| 4095 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4096 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4097 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4098 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4099 | final long token = Binder.clearCallingIdentity(); |
| 4100 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4101 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4102 | // 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] | 4103 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4104 | } catch (ImsException e) { |
| 4105 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4106 | } finally { |
| 4107 | Binder.restoreCallingIdentity(token); |
| 4108 | } |
| 4109 | } |
| 4110 | |
| 4111 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4112 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4113 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4114 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4115 | final long identity = Binder.clearCallingIdentity(); |
| 4116 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4117 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4118 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4119 | // 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] | 4120 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4121 | } catch (ImsException e) { |
| 4122 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4123 | } finally { |
| 4124 | Binder.restoreCallingIdentity(identity); |
| 4125 | } |
| 4126 | } |
| 4127 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4128 | /** |
| 4129 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4130 | * @param subId The subscription to use to check the configuration. |
| 4131 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4132 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4133 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4134 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4135 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4136 | final long identity = Binder.clearCallingIdentity(); |
| 4137 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4138 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4139 | // 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] | 4140 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4141 | } catch (ImsException e) { |
| 4142 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4143 | } finally { |
| 4144 | Binder.restoreCallingIdentity(identity); |
| 4145 | } |
| 4146 | } |
| 4147 | |
| 4148 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4149 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4150 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4151 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4152 | final long identity = Binder.clearCallingIdentity(); |
| 4153 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4154 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4155 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4156 | // 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] | 4157 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4158 | } catch (ImsException e) { |
| 4159 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4160 | } finally { |
| 4161 | Binder.restoreCallingIdentity(identity); |
| 4162 | } |
| 4163 | } |
| 4164 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4165 | /** |
| 4166 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4167 | * @param subId The subscription to use to check the configuration. |
| 4168 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4169 | @Override |
| 4170 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4171 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4172 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4173 | final long identity = Binder.clearCallingIdentity(); |
| 4174 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4175 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4176 | // 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] | 4177 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4178 | } catch (ImsException e) { |
| 4179 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4180 | } finally { |
| 4181 | Binder.restoreCallingIdentity(identity); |
| 4182 | } |
| 4183 | } |
| 4184 | |
| 4185 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4186 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4187 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4188 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4189 | final long identity = Binder.clearCallingIdentity(); |
| 4190 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4191 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4192 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4193 | // 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] | 4194 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4195 | } catch (ImsException e) { |
| 4196 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4197 | } finally { |
| 4198 | Binder.restoreCallingIdentity(identity); |
| 4199 | } |
| 4200 | } |
| 4201 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4202 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4203 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4204 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4205 | * @param subId The subscription to use to check the configuration. |
| 4206 | */ |
| 4207 | @Override |
| 4208 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4209 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4210 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4211 | final long identity = Binder.clearCallingIdentity(); |
| 4212 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4213 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4214 | // 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] | 4215 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4216 | } catch (ImsException e) { |
| 4217 | throw new ServiceSpecificException(e.getCode()); |
| 4218 | } finally { |
| 4219 | Binder.restoreCallingIdentity(identity); |
| 4220 | } |
| 4221 | } |
| 4222 | |
| 4223 | /** |
| 4224 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4225 | * Requires MODIFY_PHONE_STATE permission. |
| 4226 | * @param subId The subscription to use to check the configuration. |
| 4227 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4228 | * false otherwise |
| 4229 | */ |
| 4230 | @Override |
| 4231 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4232 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4233 | "setCrossSimCallingEnabled"); |
| 4234 | final long identity = Binder.clearCallingIdentity(); |
| 4235 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4236 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4237 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4238 | // 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] | 4239 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4240 | } catch (ImsException e) { |
| 4241 | throw new ServiceSpecificException(e.getCode()); |
| 4242 | } finally { |
| 4243 | Binder.restoreCallingIdentity(identity); |
| 4244 | } |
| 4245 | } |
| 4246 | |
| 4247 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4248 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4249 | * @param subId The subscription to use to check the configuration. |
| 4250 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4251 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4252 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4253 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4254 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4255 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4256 | final long identity = Binder.clearCallingIdentity(); |
| 4257 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4258 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4259 | // 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] | 4260 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4261 | } catch (ImsException e) { |
| 4262 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4263 | } finally { |
| 4264 | Binder.restoreCallingIdentity(identity); |
| 4265 | } |
| 4266 | } |
| 4267 | |
| 4268 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4269 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4270 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4271 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4272 | final long identity = Binder.clearCallingIdentity(); |
| 4273 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4274 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4275 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4276 | // 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] | 4277 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4278 | } catch (ImsException e) { |
| 4279 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4280 | } finally { |
| 4281 | Binder.restoreCallingIdentity(identity); |
| 4282 | } |
| 4283 | } |
| 4284 | |
| 4285 | @Override |
| 4286 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4287 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4288 | "setVoWiFiNonPersistent"); |
| 4289 | final long identity = Binder.clearCallingIdentity(); |
| 4290 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4291 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4292 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4293 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4294 | } catch (ImsException e) { |
| 4295 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4296 | } finally { |
| 4297 | Binder.restoreCallingIdentity(identity); |
| 4298 | } |
| 4299 | } |
| 4300 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4301 | /** |
| 4302 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4303 | * @param subId The subscription to use to check the configuration. |
| 4304 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4305 | @Override |
| 4306 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4307 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4308 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4309 | final long identity = Binder.clearCallingIdentity(); |
| 4310 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4311 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4312 | // 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] | 4313 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4314 | } catch (ImsException e) { |
| 4315 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4316 | } finally { |
| 4317 | Binder.restoreCallingIdentity(identity); |
| 4318 | } |
| 4319 | } |
| 4320 | |
| 4321 | @Override |
| 4322 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4323 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4324 | "setVoWiFiModeSetting"); |
| 4325 | final long identity = Binder.clearCallingIdentity(); |
| 4326 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4327 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4328 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4329 | // 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] | 4330 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4331 | } catch (ImsException e) { |
| 4332 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4333 | } finally { |
| 4334 | Binder.restoreCallingIdentity(identity); |
| 4335 | } |
| 4336 | } |
| 4337 | |
| 4338 | @Override |
| 4339 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4340 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4341 | final long identity = Binder.clearCallingIdentity(); |
| 4342 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4343 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4344 | // 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] | 4345 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4346 | } catch (ImsException e) { |
| 4347 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4348 | } finally { |
| 4349 | Binder.restoreCallingIdentity(identity); |
| 4350 | } |
| 4351 | } |
| 4352 | |
| 4353 | @Override |
| 4354 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4355 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4356 | "setVoWiFiRoamingModeSetting"); |
| 4357 | final long identity = Binder.clearCallingIdentity(); |
| 4358 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4359 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4360 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4361 | // new setting will be picked up when the ImsService comes up next if it isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4362 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4363 | } catch (ImsException e) { |
| 4364 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4365 | } finally { |
| 4366 | Binder.restoreCallingIdentity(identity); |
| 4367 | } |
| 4368 | } |
| 4369 | |
| 4370 | @Override |
| 4371 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4372 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4373 | "setRttCapabilityEnabled"); |
| 4374 | final long identity = Binder.clearCallingIdentity(); |
| 4375 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4376 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4377 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4378 | // new setting will be picked up when the ImsService comes up next if it isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4379 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4380 | } catch (ImsException e) { |
| 4381 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4382 | } finally { |
| 4383 | Binder.restoreCallingIdentity(identity); |
| 4384 | } |
| 4385 | } |
| 4386 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4387 | /** |
| 4388 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4389 | * @param subId The subscription to use to check the configuration. |
| 4390 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4391 | @Override |
| 4392 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4393 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4394 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4395 | final long identity = Binder.clearCallingIdentity(); |
| 4396 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4397 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4398 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4399 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4400 | } catch (ImsException e) { |
| 4401 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4402 | } finally { |
| 4403 | Binder.restoreCallingIdentity(identity); |
| 4404 | } |
| 4405 | } |
| 4406 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4407 | @Override |
| 4408 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4409 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4410 | final long identity = Binder.clearCallingIdentity(); |
| 4411 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4412 | if (!isImsAvailableOnDevice()) { |
| 4413 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4414 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4415 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4416 | int slotId = getSlotIndexOrException(subId); |
| 4417 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4418 | ImsManager.getInstance(mApp, slotId) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4419 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4420 | } catch (ImsException e) { |
| 4421 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4422 | } finally { |
| 4423 | Binder.restoreCallingIdentity(identity); |
| 4424 | } |
| 4425 | } |
| 4426 | |
| 4427 | @Override |
| 4428 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4429 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4430 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4431 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4432 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4433 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4434 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4435 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4436 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4437 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4438 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4439 | + "is inactive, ignoring unregister."); |
| 4440 | // If the subscription is no longer active, just return, since the callback will already |
| 4441 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4442 | } finally { |
| 4443 | Binder.restoreCallingIdentity(identity); |
| 4444 | } |
| 4445 | } |
| 4446 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4447 | |
| 4448 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4449 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4450 | message); |
| 4451 | } |
| 4452 | |
| 4453 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4454 | boolean isMmtelCapability) { |
| 4455 | Phone phone = getPhone(subId); |
| 4456 | if (phone == null) { |
| 4457 | loge("phone instance null for subid " + subId); |
| 4458 | return false; |
| 4459 | } |
| 4460 | if (isMmtelCapability) { |
| 4461 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4462 | return false; |
| 4463 | } |
| 4464 | } else { |
| 4465 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4466 | return false; |
| 4467 | } |
| 4468 | } |
| 4469 | return true; |
| 4470 | } |
| 4471 | |
| 4472 | @Override |
| 4473 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4474 | boolean isProvisioned) { |
| 4475 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4476 | |
| 4477 | final long identity = Binder.clearCallingIdentity(); |
| 4478 | try { |
| 4479 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4480 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4481 | return; |
| 4482 | } |
| 4483 | |
| 4484 | // this capability requires provisioning, route to the correct API. |
| 4485 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4486 | switch (capability) { |
| 4487 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4488 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4489 | ims.setEabProvisioned(isProvisioned); |
| 4490 | break; |
| 4491 | default: { |
| 4492 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4493 | + "rcs capability '" + capability + "', which does not require " |
| 4494 | + "provisioning."); |
| 4495 | } |
| 4496 | } |
| 4497 | } finally { |
| 4498 | Binder.restoreCallingIdentity(identity); |
| 4499 | } |
| 4500 | |
| 4501 | } |
| 4502 | |
| 4503 | |
| 4504 | @Override |
| 4505 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4506 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4507 | final long identity = Binder.clearCallingIdentity(); |
| 4508 | try { |
| 4509 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4510 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4511 | return true; |
| 4512 | } |
| 4513 | |
| 4514 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4515 | switch (capability) { |
| 4516 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4517 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4518 | return ims.isEabProvisionedOnDevice(); |
| 4519 | |
| 4520 | default: { |
| 4521 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4522 | + "capability '" + capability + "', which does not require " |
| 4523 | + "provisioning."); |
| 4524 | } |
| 4525 | } |
| 4526 | |
| 4527 | } finally { |
| 4528 | Binder.restoreCallingIdentity(identity); |
| 4529 | } |
| 4530 | } |
| 4531 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4532 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4533 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4534 | boolean isProvisioned) { |
| 4535 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4536 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE |
| 4537 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4538 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4539 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4540 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4541 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4542 | final long identity = Binder.clearCallingIdentity(); |
| 4543 | try { |
| 4544 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4545 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4546 | return; |
| 4547 | } |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4548 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4549 | || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
| 4550 | loge("setImsProvisioningStatusForCapability: called for technology that does " |
| 4551 | + "not support provisioning - " + tech); |
| 4552 | return; |
| 4553 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4554 | |
| 4555 | // this capability requires provisioning, route to the correct API. |
| 4556 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4557 | switch (capability) { |
| 4558 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4559 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4560 | ims.setVolteProvisioned(isProvisioned); |
| 4561 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4562 | ims.setWfcProvisioned(isProvisioned); |
| 4563 | } |
| 4564 | break; |
| 4565 | } |
| 4566 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4567 | // There is currently no difference in VT provisioning type. |
| 4568 | ims.setVtProvisioned(isProvisioned); |
| 4569 | break; |
| 4570 | } |
| 4571 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4572 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4573 | // change the capability of the feature instead if needed. |
| 4574 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4575 | == isProvisioned) { |
| 4576 | // No change in provisioning. |
| 4577 | return; |
| 4578 | } |
| 4579 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4580 | try { |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4581 | ims.changeMmTelCapability(isProvisioned, capability, tech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4582 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4583 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4584 | + ", Exception" + e.getMessage()); |
| 4585 | } |
| 4586 | break; |
| 4587 | } |
| 4588 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4589 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4590 | + "MmTel capability '" + capability + "', which does not require " |
| 4591 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4592 | } |
| 4593 | } |
| 4594 | |
| 4595 | } finally { |
| 4596 | Binder.restoreCallingIdentity(identity); |
| 4597 | } |
| 4598 | } |
| 4599 | |
| 4600 | @Override |
| 4601 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4602 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4603 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE |
| 4604 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4605 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4606 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4607 | } |
| 4608 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4609 | final long identity = Binder.clearCallingIdentity(); |
| 4610 | try { |
| 4611 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4612 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4613 | return true; |
| 4614 | } |
| 4615 | |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4616 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4617 | || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
| 4618 | loge("getImsProvisioningStatusForCapability: called for technology that does " |
| 4619 | + "not support provisioning - " + tech); |
| 4620 | return true; |
| 4621 | } |
| 4622 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4623 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4624 | switch (capability) { |
| 4625 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4626 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4627 | return ims.isVolteProvisionedOnDevice(); |
| 4628 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4629 | return ims.isWfcProvisionedOnDevice(); |
| 4630 | } |
| 4631 | // This should never happen, since we are checking tech above to make sure it |
| 4632 | // is either LTE or IWLAN. |
| 4633 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4634 | + "capability."); |
| 4635 | } |
| 4636 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4637 | // There is currently no difference in VT provisioning type. |
| 4638 | return ims.isVtProvisionedOnDevice(); |
| 4639 | } |
| 4640 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4641 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4642 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4643 | } |
| 4644 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4645 | throw new IllegalArgumentException( |
| 4646 | "Tried to get provisioning for MmTel capability '" + capability |
| 4647 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4648 | } |
| 4649 | } |
| 4650 | |
| 4651 | } finally { |
| 4652 | Binder.restoreCallingIdentity(identity); |
| 4653 | } |
| 4654 | } |
| 4655 | |
| 4656 | @Override |
| 4657 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4658 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4659 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4660 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4661 | } |
| 4662 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4663 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4664 | return (provisionedBits & capability) > 0; |
| 4665 | } |
| 4666 | |
| 4667 | @Override |
| 4668 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4669 | boolean isProvisioned) { |
| 4670 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4671 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4672 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4673 | } |
| 4674 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4675 | "setProvisioningStatusForCapability"); |
| 4676 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4677 | // If the current provisioning status for capability already matches isProvisioned, |
| 4678 | // do nothing. |
| 4679 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4680 | return; |
| 4681 | } |
| 4682 | if (isProvisioned) { |
| 4683 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4684 | } else { |
| 4685 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4686 | } |
| 4687 | } |
| 4688 | |
| 4689 | /** |
| 4690 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4691 | * technology. The bitfield should mirror the bitfield defined by |
| 4692 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4693 | */ |
| 4694 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4695 | String key = getMmTelProvisioningKey(subId, tech); |
| 4696 | // Default is no capabilities are provisioned. |
| 4697 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4698 | } |
| 4699 | |
| 4700 | /** |
| 4701 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4702 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4703 | * technology specified. |
| 4704 | * |
| 4705 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4706 | */ |
| 4707 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4708 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4709 | String key = getMmTelProvisioningKey(subId, tech); |
| 4710 | editor.putInt(key, newField); |
| 4711 | editor.commit(); |
| 4712 | } |
| 4713 | |
| 4714 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4715 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4716 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4717 | } |
| 4718 | |
| 4719 | /** |
| 4720 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4721 | * carrier associated with the subscription id. |
| 4722 | */ |
| 4723 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4724 | int capability) { |
| 4725 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4726 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4727 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4728 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4729 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4730 | false); |
| 4731 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4732 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4733 | |
| 4734 | // First check to make sure that the capability requires provisioning. |
| 4735 | switch (capability) { |
| 4736 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4737 | // intentional fallthrough |
| 4738 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4739 | if (requireVoiceVtProvisioning) { |
| 4740 | // Voice and Video requires provisioning |
| 4741 | return true; |
| 4742 | } |
| 4743 | break; |
| 4744 | } |
| 4745 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4746 | if (requireUtProvisioning) { |
| 4747 | // UT requires provisioning |
| 4748 | return true; |
| 4749 | } |
| 4750 | break; |
| 4751 | } |
| 4752 | } |
| 4753 | return false; |
| 4754 | } |
| 4755 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4756 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4757 | int capability) { |
| 4758 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4759 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4760 | |
| 4761 | boolean requireRcsProvisioning = c.getBoolean( |
| 4762 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4763 | |
| 4764 | // First check to make sure that the capability requires provisioning. |
| 4765 | switch (capability) { |
| 4766 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4767 | // intentional fallthrough |
| 4768 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4769 | if (requireRcsProvisioning) { |
| 4770 | // OPTION or PRESENCE requires provisioning |
| 4771 | return true; |
| 4772 | } |
| 4773 | break; |
| 4774 | } |
| 4775 | } |
| 4776 | return false; |
| 4777 | } |
| 4778 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4779 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4780 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4781 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4782 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4783 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4784 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4785 | final long identity = Binder.clearCallingIdentity(); |
| 4786 | try { |
| 4787 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4788 | int slotId = getSlotIndex(subId); |
| 4789 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4790 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4791 | + subId + "' for key:" + key); |
| 4792 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4793 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4794 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4795 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4796 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4797 | + subId + "' for key:" + key); |
| 4798 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4799 | } finally { |
| 4800 | Binder.restoreCallingIdentity(identity); |
| 4801 | } |
| 4802 | } |
| 4803 | |
| 4804 | @Override |
| 4805 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4806 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4807 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4808 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4809 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4810 | final long identity = Binder.clearCallingIdentity(); |
| 4811 | try { |
| 4812 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4813 | int slotId = getSlotIndex(subId); |
| 4814 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4815 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4816 | + subId + "' for key:" + key); |
| 4817 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4818 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4819 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4820 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4821 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4822 | + subId + "' for key:" + key); |
| 4823 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4824 | } finally { |
| 4825 | Binder.restoreCallingIdentity(identity); |
| 4826 | } |
| 4827 | } |
| 4828 | |
| 4829 | @Override |
| 4830 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4831 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4832 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4833 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4834 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4835 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4836 | final long identity = Binder.clearCallingIdentity(); |
| 4837 | try { |
| 4838 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4839 | int slotId = getSlotIndex(subId); |
| 4840 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4841 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4842 | + subId + "' for key:" + key); |
| 4843 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4844 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4845 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4846 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4847 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4848 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4849 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4850 | } finally { |
| 4851 | Binder.restoreCallingIdentity(identity); |
| 4852 | } |
| 4853 | } |
| 4854 | |
| 4855 | @Override |
| 4856 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4857 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4858 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4859 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4860 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4861 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4862 | final long identity = Binder.clearCallingIdentity(); |
| 4863 | try { |
| 4864 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4865 | int slotId = getSlotIndex(subId); |
| 4866 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4867 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4868 | + subId + "' for key:" + key); |
| 4869 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4870 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4871 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4872 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4873 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4874 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4875 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4876 | } finally { |
| 4877 | Binder.restoreCallingIdentity(identity); |
| 4878 | } |
| 4879 | } |
| 4880 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4881 | /** |
| 4882 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 4883 | * for the given slot ID or no ImsResolver instance has been created. |
| 4884 | * @param slotId The slot ID that the IMS service is created for. |
| 4885 | * @throws ImsException If there is no ImsService configured for this slot. |
| 4886 | */ |
| 4887 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 4888 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 4889 | ImsFeature.FEATURE_MMTEL)) { |
| 4890 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 4891 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4892 | } |
| 4893 | } |
| 4894 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4895 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4896 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4897 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4898 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4899 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4900 | } |
| 4901 | return slotId; |
| 4902 | } |
| 4903 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4904 | private int getSlotIndex(int subId) { |
| 4905 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4906 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4907 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4908 | } |
| 4909 | return slotId; |
| 4910 | } |
| 4911 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4912 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4913 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4914 | */ |
| 4915 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4916 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4917 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 4918 | try { |
| 4919 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4920 | } catch (SecurityException se) { |
| 4921 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 4922 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 4923 | + Binder.getCallingUid()); |
| 4924 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4925 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4926 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4927 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4928 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4929 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4930 | mApp, subId, callingPackage, callingFeatureId, |
| 4931 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4932 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4933 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4934 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4935 | final long identity = Binder.clearCallingIdentity(); |
| 4936 | try { |
| 4937 | final Phone phone = getPhone(subId); |
| 4938 | if (phone != null) { |
| 4939 | return phone.getServiceState().getDataNetworkType(); |
| 4940 | } else { |
| 4941 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4942 | } |
| 4943 | } finally { |
| 4944 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4945 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4946 | } |
| 4947 | |
| 4948 | /** |
| 4949 | * Returns the data network type |
| 4950 | */ |
| 4951 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4952 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 4953 | return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(), |
| 4954 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4955 | } |
| 4956 | |
| 4957 | /** |
| 4958 | * Returns the data network type for a subId |
| 4959 | */ |
| 4960 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4961 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4962 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4963 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4964 | mApp, subId, callingPackage, callingFeatureId, |
| 4965 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4966 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4967 | } |
| 4968 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4969 | final long identity = Binder.clearCallingIdentity(); |
| 4970 | try { |
| 4971 | final Phone phone = getPhone(subId); |
| 4972 | if (phone != null) { |
| 4973 | return phone.getServiceState().getDataNetworkType(); |
| 4974 | } else { |
| 4975 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4976 | } |
| 4977 | } finally { |
| 4978 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4979 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4980 | } |
| 4981 | |
| 4982 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4983 | * Returns the Voice network type for a subId |
| 4984 | */ |
| 4985 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4986 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4987 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4988 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4989 | mApp, subId, callingPackage, callingFeatureId, |
| 4990 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4991 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4992 | } |
| 4993 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4994 | final long identity = Binder.clearCallingIdentity(); |
| 4995 | try { |
| 4996 | final Phone phone = getPhone(subId); |
| 4997 | if (phone != null) { |
| 4998 | return phone.getServiceState().getVoiceNetworkType(); |
| 4999 | } else { |
| 5000 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5001 | } |
| 5002 | } finally { |
| 5003 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5004 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5005 | } |
| 5006 | |
| 5007 | /** |
| 5008 | * @return true if a ICC card is present |
| 5009 | */ |
| 5010 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5011 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5012 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 5013 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5014 | } |
| 5015 | |
| 5016 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5017 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5018 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5019 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5020 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5021 | final long identity = Binder.clearCallingIdentity(); |
| 5022 | try { |
| 5023 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5024 | if (phone != null) { |
| 5025 | return phone.getIccCard().hasIccCard(); |
| 5026 | } else { |
| 5027 | return false; |
| 5028 | } |
| 5029 | } finally { |
| 5030 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5031 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5032 | } |
| 5033 | |
| 5034 | /** |
| 5035 | * Return if the current radio is LTE on CDMA. This |
| 5036 | * is a tri-state return value as for a period of time |
| 5037 | * the mode may be unknown. |
| 5038 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5039 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5040 | * @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] | 5041 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5042 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5043 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5044 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5045 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5046 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5047 | } |
| 5048 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5049 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5050 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5051 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5052 | try { |
| 5053 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5054 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5055 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5056 | } |
| 5057 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5058 | final long identity = Binder.clearCallingIdentity(); |
| 5059 | try { |
| 5060 | final Phone phone = getPhone(subId); |
| 5061 | if (phone == null) { |
| 5062 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5063 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5064 | return TelephonyProperties.lte_on_cdma_device() |
| 5065 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5066 | } |
| 5067 | } finally { |
| 5068 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5069 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5070 | } |
| 5071 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5072 | /** |
| 5073 | * {@hide} |
| 5074 | * Returns Default subId, 0 in the case of single standby. |
| 5075 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5076 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5077 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5078 | } |
| 5079 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5080 | private int getSlotForDefaultSubscription() { |
| 5081 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 5082 | } |
| 5083 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5084 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5085 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5086 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5087 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5088 | private boolean isActiveSubscription(int subId) { |
| 5089 | return mSubscriptionController.isActiveSubId(subId); |
| 5090 | } |
| 5091 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5092 | /** |
| 5093 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5094 | */ |
| 5095 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5096 | final long identity = Binder.clearCallingIdentity(); |
| 5097 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5098 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5099 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5100 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5101 | } finally { |
| 5102 | Binder.restoreCallingIdentity(identity); |
| 5103 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5104 | } |
| 5105 | |
| 5106 | /** |
| 5107 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5108 | */ |
| 5109 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5110 | final long identity = Binder.clearCallingIdentity(); |
| 5111 | try { |
| 5112 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5113 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5114 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5115 | } finally { |
| 5116 | Binder.restoreCallingIdentity(identity); |
| 5117 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5118 | } |
| 5119 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5120 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5121 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5122 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5123 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5124 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5125 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 5126 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 5127 | if (phoneId == -1) { |
| 5128 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 5129 | + " does not correspond to an active phone"); |
| 5130 | } |
| 5131 | return PhoneFactory.getPhone(phoneId); |
| 5132 | } |
| 5133 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5134 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5135 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 5136 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5137 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5138 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5139 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5140 | if (DBG) { |
| 5141 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 5142 | } |
| 5143 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 5144 | p2); |
| 5145 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5146 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5147 | |
| 5148 | @Override |
| 5149 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 5150 | int slotIndex, String callingPackage, String aid, int p2) { |
| 5151 | enforceModifyPermission(); |
| 5152 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5153 | if (DBG) { |
| 5154 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 5155 | } |
| 5156 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 5157 | callingPackage, aid, p2); |
| 5158 | } |
| 5159 | |
| 5160 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 5161 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5162 | final long identity = Binder.clearCallingIdentity(); |
| 5163 | try { |
| 5164 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 5165 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5166 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5167 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5168 | if (bestComponent == null |
| 5169 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5170 | loge("The calling package is not allowed to access ISD-R."); |
| 5171 | throw new SecurityException( |
| 5172 | "The calling package is not allowed to access ISD-R."); |
| 5173 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5174 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5175 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5176 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5177 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 5178 | null /* workSource */); |
| 5179 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5180 | return response; |
| 5181 | } finally { |
| 5182 | Binder.restoreCallingIdentity(identity); |
| 5183 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5184 | } |
| 5185 | |
| 5186 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5187 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5188 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5189 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5190 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 5191 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 5192 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5193 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5194 | @Override |
| 5195 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 5196 | enforceModifyPermission(); |
| 5197 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 5198 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 5199 | channel); |
| 5200 | } |
| 5201 | |
| 5202 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5203 | final long identity = Binder.clearCallingIdentity(); |
| 5204 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5205 | if (channel < 0) { |
| 5206 | return false; |
| 5207 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5208 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 5209 | null /* workSource */); |
| 5210 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5211 | return success; |
| 5212 | } finally { |
| 5213 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5214 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5215 | } |
| 5216 | |
| 5217 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5218 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5219 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5220 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5221 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5222 | if (DBG) { |
| 5223 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5224 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5225 | + p3 + " data=" + data); |
| 5226 | } |
| 5227 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5228 | command, p1, p2, p3, data); |
| 5229 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5230 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5231 | @Override |
| 5232 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 5233 | int command, int p1, int p2, int p3, String data) { |
| 5234 | enforceModifyPermission(); |
| 5235 | if (DBG) { |
| 5236 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 5237 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5238 | + p3 + " data=" + data); |
| 5239 | } |
| 5240 | return iccTransmitApduLogicalChannelWithPermission( |
| 5241 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 5242 | data); |
| 5243 | } |
| 5244 | |
| 5245 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5246 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5247 | final long identity = Binder.clearCallingIdentity(); |
| 5248 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5249 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5250 | return ""; |
| 5251 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5252 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5253 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5254 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5255 | null /* workSource */); |
| 5256 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5257 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5258 | // Append the returned status code to the end of the response payload. |
| 5259 | String s = Integer.toHexString( |
| 5260 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5261 | if (response.payload != null) { |
| 5262 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5263 | } |
| 5264 | return s; |
| 5265 | } finally { |
| 5266 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5267 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5268 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5269 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5270 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5271 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5272 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5273 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5274 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5275 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5276 | if (DBG) { |
| 5277 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5278 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5279 | } |
| 5280 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5281 | cla, command, p1, p2, p3, data); |
| 5282 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5283 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5284 | @Override |
| 5285 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 5286 | int command, int p1, int p2, int p3, String data) { |
| 5287 | enforceModifyPermission(); |
| 5288 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5289 | if (DBG) { |
| 5290 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 5291 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 5292 | + " data=" + data); |
| 5293 | } |
| 5294 | |
| 5295 | return iccTransmitApduBasicChannelWithPermission( |
| 5296 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 5297 | p2, p3, data); |
| 5298 | } |
| 5299 | |
| 5300 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5301 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5302 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5303 | final long identity = Binder.clearCallingIdentity(); |
| 5304 | try { |
| 5305 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5306 | && TextUtils.equals(ISDR_AID, data)) { |
| 5307 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5308 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5309 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5310 | if (bestComponent == null |
| 5311 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5312 | loge("The calling package is not allowed to select ISD-R."); |
| 5313 | throw new SecurityException( |
| 5314 | "The calling package is not allowed to select ISD-R."); |
| 5315 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5316 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5317 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5318 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5319 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5320 | null /* workSource */); |
| 5321 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5322 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5323 | // Append the returned status code to the end of the response payload. |
| 5324 | String s = Integer.toHexString( |
| 5325 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5326 | if (response.payload != null) { |
| 5327 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5328 | } |
| 5329 | return s; |
| 5330 | } finally { |
| 5331 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5332 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5333 | } |
| 5334 | |
| 5335 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5336 | 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] | 5337 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5338 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5339 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5340 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5341 | final long identity = Binder.clearCallingIdentity(); |
| 5342 | try { |
| 5343 | if (DBG) { |
| 5344 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5345 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5346 | } |
| 5347 | |
| 5348 | IccIoResult response = |
| 5349 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5350 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5351 | subId); |
| 5352 | |
| 5353 | if (DBG) { |
| 5354 | log("Exchange SIM_IO [R]" + response); |
| 5355 | } |
| 5356 | |
| 5357 | byte[] result = null; |
| 5358 | int length = 2; |
| 5359 | if (response.payload != null) { |
| 5360 | length = 2 + response.payload.length; |
| 5361 | result = new byte[length]; |
| 5362 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5363 | } else { |
| 5364 | result = new byte[length]; |
| 5365 | } |
| 5366 | |
| 5367 | result[length - 1] = (byte) response.sw2; |
| 5368 | result[length - 2] = (byte) response.sw1; |
| 5369 | return result; |
| 5370 | } finally { |
| 5371 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5372 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5373 | } |
| 5374 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5375 | /** |
| 5376 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5377 | * on a particular subscription |
| 5378 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5379 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5380 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5381 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5382 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5383 | return null; |
| 5384 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5385 | |
| 5386 | final long identity = Binder.clearCallingIdentity(); |
| 5387 | try { |
| 5388 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5389 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5390 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5391 | return null; |
| 5392 | } |
| 5393 | Object response = sendRequest( |
| 5394 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5395 | if (response instanceof String[]) { |
| 5396 | return (String[]) response; |
| 5397 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5398 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5399 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5400 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5401 | } finally { |
| 5402 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5403 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5404 | } |
| 5405 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5406 | /** |
| 5407 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5408 | * subscription. |
| 5409 | * |
| 5410 | * @param subId the id of the subscription. |
| 5411 | * @param appType the uicc app type, must be USIM or SIM. |
| 5412 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5413 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5414 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5415 | * @return number of fplmns that is successfully written to the SIM. |
| 5416 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5417 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5418 | String callingFeatureId) { |
| 5419 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5420 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5421 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5422 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5423 | } |
| 5424 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5425 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5426 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5427 | } |
| 5428 | if (fplmns == null) { |
| 5429 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5430 | } |
| 5431 | for (String fplmn : fplmns) { |
| 5432 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5433 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5434 | } |
| 5435 | } |
| 5436 | final long identity = Binder.clearCallingIdentity(); |
| 5437 | try { |
| 5438 | Object response = sendRequest( |
| 5439 | CMD_SET_FORBIDDEN_PLMNS, |
| 5440 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5441 | subId); |
| 5442 | return (int) response; |
| 5443 | } finally { |
| 5444 | Binder.restoreCallingIdentity(identity); |
| 5445 | } |
| 5446 | } |
| 5447 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5448 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5449 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5450 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5451 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5452 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5453 | final long identity = Binder.clearCallingIdentity(); |
| 5454 | try { |
| 5455 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5456 | if (response.payload == null) { |
| 5457 | return ""; |
| 5458 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5459 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5460 | // Append the returned status code to the end of the response payload. |
| 5461 | String s = Integer.toHexString( |
| 5462 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5463 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5464 | return s; |
| 5465 | } finally { |
| 5466 | Binder.restoreCallingIdentity(identity); |
| 5467 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5468 | } |
| 5469 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5470 | /** |
| 5471 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5472 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5473 | * |
| 5474 | * @param itemID the ID of the item to read |
| 5475 | * @return the NV item as a String, or null on error. |
| 5476 | */ |
| 5477 | @Override |
| 5478 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5479 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5480 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5481 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5482 | |
| 5483 | final long identity = Binder.clearCallingIdentity(); |
| 5484 | try { |
| 5485 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5486 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5487 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5488 | return value; |
| 5489 | } finally { |
| 5490 | Binder.restoreCallingIdentity(identity); |
| 5491 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5492 | } |
| 5493 | |
| 5494 | /** |
| 5495 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5496 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5497 | * |
| 5498 | * @param itemID the ID of the item to read |
| 5499 | * @param itemValue the value to write, as a String |
| 5500 | * @return true on success; false on any failure |
| 5501 | */ |
| 5502 | @Override |
| 5503 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5504 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5505 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5506 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5507 | |
| 5508 | final long identity = Binder.clearCallingIdentity(); |
| 5509 | try { |
| 5510 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5511 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5512 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5513 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5514 | return success; |
| 5515 | } finally { |
| 5516 | Binder.restoreCallingIdentity(identity); |
| 5517 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5518 | } |
| 5519 | |
| 5520 | /** |
| 5521 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5522 | * Used for device configuration by some CDMA operators. |
| 5523 | * |
| 5524 | * @param preferredRoamingList byte array containing the new PRL |
| 5525 | * @return true on success; false on any failure |
| 5526 | */ |
| 5527 | @Override |
| 5528 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5529 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5530 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5531 | |
| 5532 | final long identity = Binder.clearCallingIdentity(); |
| 5533 | try { |
| 5534 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5535 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5536 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5537 | return success; |
| 5538 | } finally { |
| 5539 | Binder.restoreCallingIdentity(identity); |
| 5540 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5541 | } |
| 5542 | |
| 5543 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5544 | * 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] | 5545 | * Used for device configuration by some CDMA operators. |
| 5546 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5547 | * @param slotIndex - device slot. |
| 5548 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5549 | * @return true on success; false on any failure |
| 5550 | */ |
| 5551 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5552 | public boolean resetModemConfig(int slotIndex) { |
| 5553 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5554 | if (phone != null) { |
| 5555 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5556 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5557 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5558 | final long identity = Binder.clearCallingIdentity(); |
| 5559 | try { |
| 5560 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5561 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5562 | return success; |
| 5563 | } finally { |
| 5564 | Binder.restoreCallingIdentity(identity); |
| 5565 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5566 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5567 | return false; |
| 5568 | } |
| 5569 | |
| 5570 | /** |
| 5571 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5572 | * |
| 5573 | * @param slotIndex - device slot. |
| 5574 | * |
| 5575 | * @return true on success; false on any failure |
| 5576 | */ |
| 5577 | @Override |
| 5578 | public boolean rebootModem(int slotIndex) { |
| 5579 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5580 | if (phone != null) { |
| 5581 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5582 | mApp, phone.getSubId(), "rebootModem"); |
| 5583 | |
| 5584 | final long identity = Binder.clearCallingIdentity(); |
| 5585 | try { |
| 5586 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5587 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5588 | return success; |
| 5589 | } finally { |
| 5590 | Binder.restoreCallingIdentity(identity); |
| 5591 | } |
| 5592 | } |
| 5593 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5594 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5595 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5596 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5597 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5598 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5599 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5600 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5601 | return new String[0]; |
| 5602 | } |
| 5603 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5604 | final long identity = Binder.clearCallingIdentity(); |
| 5605 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5606 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5607 | } finally { |
| 5608 | Binder.restoreCallingIdentity(identity); |
| 5609 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5610 | } |
| 5611 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5612 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5613 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5614 | * {@link #disableIms(int)}. |
| 5615 | * @param slotIndex device slot. |
| 5616 | */ |
| 5617 | public void resetIms(int slotIndex) { |
| 5618 | enforceModifyPermission(); |
| 5619 | |
| 5620 | final long identity = Binder.clearCallingIdentity(); |
| 5621 | try { |
| 5622 | if (mImsResolver == null) { |
| 5623 | // may happen if the does not support IMS. |
| 5624 | return; |
| 5625 | } |
| 5626 | mImsResolver.disableIms(slotIndex); |
| 5627 | mImsResolver.enableIms(slotIndex); |
| 5628 | } finally { |
| 5629 | Binder.restoreCallingIdentity(identity); |
| 5630 | } |
| 5631 | } |
| 5632 | |
| 5633 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5634 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5635 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5636 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5637 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5638 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5639 | |
| 5640 | final long identity = Binder.clearCallingIdentity(); |
| 5641 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5642 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5643 | // may happen if the device does not support IMS. |
| 5644 | return; |
| 5645 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5646 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5647 | } finally { |
| 5648 | Binder.restoreCallingIdentity(identity); |
| 5649 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5650 | } |
| 5651 | |
| 5652 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5653 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5654 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5655 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5656 | public void disableIms(int slotId) { |
| 5657 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5658 | |
| 5659 | final long identity = Binder.clearCallingIdentity(); |
| 5660 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5661 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5662 | // may happen if the device does not support IMS. |
| 5663 | return; |
| 5664 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5665 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5666 | } finally { |
| 5667 | Binder.restoreCallingIdentity(identity); |
| 5668 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5669 | } |
| 5670 | |
| 5671 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5672 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5673 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5674 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5675 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5676 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5677 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5678 | |
| 5679 | final long identity = Binder.clearCallingIdentity(); |
| 5680 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5681 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5682 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5683 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5684 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5685 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5686 | } finally { |
| 5687 | Binder.restoreCallingIdentity(identity); |
| 5688 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5689 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5690 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5691 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5692 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5693 | @Override |
| 5694 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5695 | enforceModifyPermission(); |
| 5696 | |
| 5697 | final long identity = Binder.clearCallingIdentity(); |
| 5698 | try { |
| 5699 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5700 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5701 | } finally { |
| 5702 | Binder.restoreCallingIdentity(identity); |
| 5703 | } |
| 5704 | } |
| 5705 | |
| 5706 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5707 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5708 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5709 | */ |
| 5710 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5711 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5712 | |
| 5713 | final long identity = Binder.clearCallingIdentity(); |
| 5714 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5715 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5716 | // may happen if the device does not support IMS. |
| 5717 | return null; |
| 5718 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5719 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5720 | } finally { |
| 5721 | Binder.restoreCallingIdentity(identity); |
| 5722 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5723 | } |
| 5724 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5725 | /** |
| 5726 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5727 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5728 | */ |
| 5729 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5730 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5731 | |
| 5732 | final long identity = Binder.clearCallingIdentity(); |
| 5733 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5734 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5735 | // may happen if the device does not support IMS. |
| 5736 | return null; |
| 5737 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5738 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5739 | } finally { |
| 5740 | Binder.restoreCallingIdentity(identity); |
| 5741 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5742 | } |
| 5743 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5744 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5745 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5746 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5747 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5748 | * @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] | 5749 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5750 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5751 | * @param packageName The name of the package that the current configuration will be replaced |
| 5752 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5753 | * @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] | 5754 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5755 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5756 | int[] featureTypes, String packageName) { |
| 5757 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5758 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5759 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5760 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5761 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5762 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5763 | final long identity = Binder.clearCallingIdentity(); |
| 5764 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5765 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5766 | // may happen if the device does not support IMS. |
| 5767 | return false; |
| 5768 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5769 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5770 | for (int featureType : featureTypes) { |
| 5771 | featureConfig.put(featureType, packageName); |
| 5772 | } |
| 5773 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5774 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5775 | } finally { |
| 5776 | Binder.restoreCallingIdentity(identity); |
| 5777 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5778 | } |
| 5779 | |
| 5780 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5781 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5782 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5783 | * |
| 5784 | * This should only be used for testing. |
| 5785 | * |
| 5786 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5787 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5788 | */ |
| 5789 | @Override |
| 5790 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5791 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5792 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5793 | "clearCarrierImsServiceOverride"); |
| 5794 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5795 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5796 | "clearCarrierImsServiceOverride"); |
| 5797 | |
| 5798 | final long identity = Binder.clearCallingIdentity(); |
| 5799 | try { |
| 5800 | if (mImsResolver == null) { |
| 5801 | // may happen if the device does not support IMS. |
| 5802 | return false; |
| 5803 | } |
| 5804 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5805 | } finally { |
| 5806 | Binder.restoreCallingIdentity(identity); |
| 5807 | } |
| 5808 | } |
| 5809 | |
| 5810 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5811 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5812 | * |
| 5813 | * @param slotId The slot that the ImsService is associated with. |
| 5814 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5815 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5816 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5817 | * @return the package name of the ImsService configuration. |
| 5818 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5819 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5820 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5821 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5822 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5823 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5824 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5825 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5826 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5827 | final long identity = Binder.clearCallingIdentity(); |
| 5828 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5829 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5830 | // may happen if the device does not support IMS. |
| 5831 | return ""; |
| 5832 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5833 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5834 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5835 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5836 | } finally { |
| 5837 | Binder.restoreCallingIdentity(identity); |
| 5838 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5839 | } |
| 5840 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5841 | /** |
| 5842 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5843 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5844 | * @param callback A callback with an integer containing the |
| 5845 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5846 | */ |
| 5847 | @Override |
| 5848 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5849 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5850 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5851 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5852 | "IMS not available on device."); |
| 5853 | } |
| 5854 | final long token = Binder.clearCallingIdentity(); |
| 5855 | try { |
| 5856 | int slotId = getSlotIndex(subId); |
| 5857 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5858 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5859 | + subId + "'"); |
| 5860 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5861 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5862 | verifyImsMmTelConfiguredOrThrow(slotId); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5863 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5864 | try { |
| 5865 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5866 | } catch (RemoteException e) { |
| 5867 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5868 | + "Ignore"); |
| 5869 | } |
| 5870 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5871 | } catch (ImsException e) { |
| 5872 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5873 | } finally { |
| 5874 | Binder.restoreCallingIdentity(token); |
| 5875 | } |
| 5876 | } |
| 5877 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5878 | /** |
| 5879 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5880 | */ |
| 5881 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5882 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5883 | |
| 5884 | final long identity = Binder.clearCallingIdentity(); |
| 5885 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5886 | // NOTE: Before S, this method only set the default phone. |
| 5887 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5888 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5889 | phone.setImsRegistrationState(registered); |
| 5890 | } |
| 5891 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5892 | } finally { |
| 5893 | Binder.restoreCallingIdentity(identity); |
| 5894 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5895 | } |
| 5896 | |
| 5897 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5898 | * Set the network selection mode to automatic. |
| 5899 | * |
| 5900 | */ |
| 5901 | @Override |
| 5902 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5903 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5904 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5905 | |
| 5906 | final long identity = Binder.clearCallingIdentity(); |
| 5907 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5908 | if (!isActiveSubscription(subId)) { |
| 5909 | return; |
| 5910 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5911 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 5912 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 5913 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5914 | } finally { |
| 5915 | Binder.restoreCallingIdentity(identity); |
| 5916 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5917 | } |
| 5918 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5919 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5920 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5921 | * |
| 5922 | * @param subId the id of the subscription. |
| 5923 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5924 | * the operator to attach to. |
| 5925 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5926 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5927 | * normal network selection next time. |
| 5928 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5929 | */ |
| 5930 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5931 | public boolean setNetworkSelectionModeManual( |
| 5932 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5933 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5934 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5935 | |
| 5936 | if (!isActiveSubscription(subId)) { |
| 5937 | return false; |
| 5938 | } |
| 5939 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5940 | final long identity = Binder.clearCallingIdentity(); |
| 5941 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5942 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5943 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5944 | if (DBG) { |
| 5945 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5946 | + " operator: " + operatorInfo); |
| 5947 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5948 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5949 | } finally { |
| 5950 | Binder.restoreCallingIdentity(identity); |
| 5951 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5952 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5953 | /** |
| 5954 | * Get the manual network selection |
| 5955 | * |
| 5956 | * @param subId the id of the subscription. |
| 5957 | * |
| 5958 | * @return the previously saved user selected PLMN |
| 5959 | */ |
| 5960 | @Override |
| 5961 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5962 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5963 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5964 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5965 | |
| 5966 | final long identity = Binder.clearCallingIdentity(); |
| 5967 | try { |
| 5968 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5969 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5970 | } |
| 5971 | |
| 5972 | final Phone phone = getPhone(subId); |
| 5973 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5974 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5975 | } |
| 5976 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5977 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5978 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5979 | } finally { |
| 5980 | Binder.restoreCallingIdentity(identity); |
| 5981 | } |
| 5982 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5983 | |
| 5984 | /** |
| 5985 | * Scans for available networks. |
| 5986 | */ |
| 5987 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5988 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5989 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5990 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5991 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5992 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5993 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5994 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5995 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5996 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5997 | .setCallingPid(Binder.getCallingPid()) |
| 5998 | .setCallingUid(Binder.getCallingUid()) |
| 5999 | .setMethod("getCellNetworkScanResults") |
| 6000 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6001 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6002 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6003 | .build()); |
| 6004 | switch (locationResult) { |
| 6005 | case DENIED_HARD: |
| 6006 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6007 | case DENIED_SOFT: |
| 6008 | return null; |
| 6009 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6010 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6011 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6012 | try { |
| 6013 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6014 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6015 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6016 | } finally { |
| 6017 | Binder.restoreCallingIdentity(identity); |
| 6018 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6019 | } |
| 6020 | |
| 6021 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6022 | * Get the call forwarding info, given the call forwarding reason. |
| 6023 | */ |
| 6024 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6025 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6026 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6027 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6028 | long identity = Binder.clearCallingIdentity(); |
| 6029 | try { |
| 6030 | if (DBG) { |
| 6031 | log("getCallForwarding: subId " + subId |
| 6032 | + " callForwardingReason" + callForwardingReason); |
| 6033 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6034 | |
| 6035 | Phone phone = getPhone(subId); |
| 6036 | if (phone == null) { |
| 6037 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6038 | callback.onError( |
| 6039 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6040 | } catch (RemoteException e) { |
| 6041 | // ignore |
| 6042 | } |
| 6043 | return; |
| 6044 | } |
| 6045 | |
| 6046 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6047 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6048 | @Override |
| 6049 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6050 | try { |
| 6051 | callback.onCallForwardingInfoAvailable(info); |
| 6052 | } catch (RemoteException e) { |
| 6053 | // ignore |
| 6054 | } |
| 6055 | } |
| 6056 | |
| 6057 | @Override |
| 6058 | public void onError(int error) { |
| 6059 | try { |
| 6060 | callback.onError(error); |
| 6061 | } catch (RemoteException e) { |
| 6062 | // ignore |
| 6063 | } |
| 6064 | } |
| 6065 | }); |
| 6066 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6067 | } finally { |
| 6068 | Binder.restoreCallingIdentity(identity); |
| 6069 | } |
| 6070 | } |
| 6071 | |
| 6072 | /** |
| 6073 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6074 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6075 | */ |
| 6076 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6077 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6078 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6079 | enforceModifyPermission(); |
| 6080 | long identity = Binder.clearCallingIdentity(); |
| 6081 | try { |
| 6082 | if (DBG) { |
| 6083 | log("setCallForwarding: subId " + subId |
| 6084 | + " callForwardingInfo" + callForwardingInfo); |
| 6085 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6086 | |
| 6087 | Phone phone = getPhone(subId); |
| 6088 | if (phone == null) { |
| 6089 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6090 | callback.accept( |
| 6091 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6092 | } catch (RemoteException e) { |
| 6093 | // ignore |
| 6094 | } |
| 6095 | return; |
| 6096 | } |
| 6097 | |
| 6098 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6099 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6100 | |
| 6101 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6102 | } finally { |
| 6103 | Binder.restoreCallingIdentity(identity); |
| 6104 | } |
| 6105 | } |
| 6106 | |
| 6107 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6108 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6109 | */ |
| 6110 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6111 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6112 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6113 | long identity = Binder.clearCallingIdentity(); |
| 6114 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6115 | Phone phone = getPhone(subId); |
| 6116 | if (phone == null) { |
| 6117 | try { |
| 6118 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6119 | } catch (RemoteException e) { |
| 6120 | // ignore |
| 6121 | } |
| 6122 | return; |
| 6123 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6124 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6125 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6126 | boolean requireUssd = c.getBoolean( |
| 6127 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6128 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6129 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6130 | if (requireUssd) { |
| 6131 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6132 | getSubscriptionCarrierId(subId)); |
| 6133 | String newUssdCommand = ""; |
| 6134 | try { |
| 6135 | newUssdCommand = carrierXmlParser.getFeature( |
| 6136 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6137 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6138 | } catch (NullPointerException e) { |
| 6139 | loge("Failed to generate USSD number" + e); |
| 6140 | } |
| 6141 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6142 | mMainThreadHandler, callback, carrierXmlParser, |
| 6143 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6144 | final String ussdCommand = newUssdCommand; |
| 6145 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6146 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6147 | }); |
| 6148 | } else { |
| 6149 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6150 | callback::accept); |
| 6151 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6152 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6153 | } finally { |
| 6154 | Binder.restoreCallingIdentity(identity); |
| 6155 | } |
| 6156 | } |
| 6157 | |
| 6158 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6159 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6160 | */ |
| 6161 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6162 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6163 | enforceModifyPermission(); |
| 6164 | long identity = Binder.clearCallingIdentity(); |
| 6165 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6166 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6167 | |
| 6168 | Phone phone = getPhone(subId); |
| 6169 | if (phone == null) { |
| 6170 | try { |
| 6171 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6172 | } catch (RemoteException e) { |
| 6173 | // ignore |
| 6174 | } |
| 6175 | return; |
| 6176 | } |
| 6177 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6178 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6179 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6180 | boolean requireUssd = c.getBoolean( |
| 6181 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6182 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6183 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6184 | if (requireUssd) { |
| 6185 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6186 | getSubscriptionCarrierId(subId)); |
| 6187 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6188 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6189 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6190 | String newUssdCommand = ""; |
| 6191 | try { |
| 6192 | newUssdCommand = carrierXmlParser.getFeature( |
| 6193 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6194 | .makeCommand(ssAction, null); |
| 6195 | } catch (NullPointerException e) { |
| 6196 | loge("Failed to generate USSD number" + e); |
| 6197 | } |
| 6198 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6199 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6200 | final String ussdCommand = newUssdCommand; |
| 6201 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6202 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6203 | }); |
| 6204 | } else { |
| 6205 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6206 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6207 | |
| 6208 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6209 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6210 | } finally { |
| 6211 | Binder.restoreCallingIdentity(identity); |
| 6212 | } |
| 6213 | } |
| 6214 | |
| 6215 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6216 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6217 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6218 | * @param subId id of the subscription |
| 6219 | * @param request contains the radio access networks with bands/channels to scan |
| 6220 | * @param messenger callback messenger for scan results or errors |
| 6221 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6222 | * @return the id of the requested scan which can be used to stop the scan. |
| 6223 | */ |
| 6224 | @Override |
| 6225 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6226 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6227 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6228 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6229 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6230 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6231 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6232 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6233 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6234 | .setCallingPid(Binder.getCallingPid()) |
| 6235 | .setCallingUid(Binder.getCallingUid()) |
| 6236 | .setMethod("requestNetworkScan") |
| 6237 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
James.cf Lin | 1d4d739 | 2020-07-03 18:22:53 +0800 | [diff] [blame] | 6238 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6239 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6240 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6241 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6242 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6243 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6244 | if (e != null) { |
| 6245 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6246 | throw e; |
| 6247 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6248 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6249 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6250 | } |
| 6251 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6252 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6253 | int callingUid = Binder.getCallingUid(); |
| 6254 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6255 | final long identity = Binder.clearCallingIdentity(); |
| 6256 | try { |
| 6257 | return mNetworkScanRequestTracker.startNetworkScan( |
| 6258 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6259 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6260 | } finally { |
| 6261 | Binder.restoreCallingIdentity(identity); |
| 6262 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6263 | } |
| 6264 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6265 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6266 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6267 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6268 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6269 | boolean hasNetworkScanPermission = |
| 6270 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6271 | == PERMISSION_GRANTED; |
| 6272 | |
| 6273 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6274 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6275 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6276 | } |
| 6277 | |
| 6278 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6279 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6280 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6281 | return new SecurityException("Specific channels must not be" |
| 6282 | + " scanned without location access."); |
| 6283 | } |
| 6284 | } |
| 6285 | } |
| 6286 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6287 | return null; |
| 6288 | } |
| 6289 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6290 | /** |
| 6291 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6292 | * |
| 6293 | * @param subId id of the subscription |
| 6294 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6295 | */ |
| 6296 | @Override |
| 6297 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6298 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6299 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6300 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6301 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6302 | final long identity = Binder.clearCallingIdentity(); |
| 6303 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6304 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6305 | } finally { |
| 6306 | Binder.restoreCallingIdentity(identity); |
| 6307 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6308 | } |
| 6309 | |
| 6310 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6311 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6312 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6313 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6314 | */ |
| 6315 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6316 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6317 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6318 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6319 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6320 | |
| 6321 | final long identity = Binder.clearCallingIdentity(); |
| 6322 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6323 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6324 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6325 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6326 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6327 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6328 | } finally { |
| 6329 | Binder.restoreCallingIdentity(identity); |
| 6330 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6331 | } |
| 6332 | |
| 6333 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6334 | * Get the allowed network types for certain reason. |
| 6335 | * |
| 6336 | * @param subId the id of the subscription. |
| 6337 | * @param reason the reason the allowed network type change is taking place |
| 6338 | * @return the allowed network types. |
| 6339 | */ |
| 6340 | @Override |
| 6341 | public long getAllowedNetworkTypesForReason(int subId, |
| 6342 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6343 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6344 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6345 | final long identity = Binder.clearCallingIdentity(); |
| 6346 | try { |
| 6347 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6348 | } finally { |
| 6349 | Binder.restoreCallingIdentity(identity); |
| 6350 | } |
| 6351 | } |
| 6352 | |
| 6353 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6354 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6355 | * @param subId subscription id of the sim card |
| 6356 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6357 | * This can be passed following states |
| 6358 | * <ol> |
| 6359 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6360 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6361 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6362 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6363 | * </ol> |
| 6364 | * @return operation result. |
| 6365 | */ |
| 6366 | @Override |
| 6367 | public int setNrDualConnectivityState(int subId, |
| 6368 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6369 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6370 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6371 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6372 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6373 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6374 | } |
| 6375 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6376 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6377 | final long identity = Binder.clearCallingIdentity(); |
| 6378 | try { |
| 6379 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6380 | nrDualConnectivityState, subId, |
| 6381 | workSource); |
| 6382 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6383 | return result; |
| 6384 | } finally { |
| 6385 | Binder.restoreCallingIdentity(identity); |
| 6386 | } |
| 6387 | } |
| 6388 | |
| 6389 | /** |
| 6390 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6391 | * @return true if dual connectivity is enabled else false |
| 6392 | */ |
| 6393 | @Override |
| 6394 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6395 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6396 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6397 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6398 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6399 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6400 | return false; |
| 6401 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6402 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6403 | final long identity = Binder.clearCallingIdentity(); |
| 6404 | try { |
| 6405 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6406 | null, subId, workSource); |
| 6407 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6408 | return isEnabled; |
| 6409 | } finally { |
| 6410 | Binder.restoreCallingIdentity(identity); |
| 6411 | } |
| 6412 | } |
| 6413 | |
| 6414 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6415 | * Set the allowed network types of the device and |
| 6416 | * provide the reason triggering the allowed network change. |
| 6417 | * |
| 6418 | * @param subId the id of the subscription. |
| 6419 | * @param reason the reason the allowed network type change is taking place |
| 6420 | * @param allowedNetworkTypes the allowed network types. |
| 6421 | * @return true on success; false on any failure. |
| 6422 | */ |
| 6423 | @Override |
| 6424 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6425 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6426 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6427 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6428 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6429 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6430 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6431 | return false; |
| 6432 | } |
| 6433 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6434 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6435 | return false; |
| 6436 | } |
| 6437 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6438 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6439 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6440 | |
| 6441 | |
| 6442 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6443 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6444 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6445 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6446 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6447 | final long identity = Binder.clearCallingIdentity(); |
| 6448 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6449 | Boolean success = (Boolean) sendRequest( |
| 6450 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6451 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6452 | |
| 6453 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6454 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6455 | } finally { |
| 6456 | Binder.restoreCallingIdentity(identity); |
| 6457 | } |
| 6458 | } |
| 6459 | |
| 6460 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6461 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6462 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6463 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6464 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6465 | * @hide |
| 6466 | */ |
| 6467 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6468 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6469 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6470 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6471 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6472 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6473 | if (phone != null) { |
| 6474 | return phone.hasMatchedTetherApnSetting(); |
| 6475 | } else { |
| 6476 | return false; |
| 6477 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6478 | } finally { |
| 6479 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6480 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6481 | } |
| 6482 | |
| 6483 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6484 | * Enable or disable always reporting signal strength changes from radio. |
| 6485 | * |
| 6486 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6487 | */ |
| 6488 | @Override |
| 6489 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6490 | enforceModifyPermission(); |
| 6491 | enforceSystemCaller(); |
| 6492 | |
| 6493 | final long identity = Binder.clearCallingIdentity(); |
| 6494 | final Phone phone = getPhone(subId); |
| 6495 | try { |
| 6496 | if (phone != null) { |
| 6497 | if (DBG) { |
| 6498 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6499 | + " isEnable=" + isEnable); |
| 6500 | } |
| 6501 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6502 | } else { |
| 6503 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6504 | + subId); |
| 6505 | } |
| 6506 | } finally { |
| 6507 | Binder.restoreCallingIdentity(identity); |
| 6508 | } |
| 6509 | } |
| 6510 | |
| 6511 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6512 | * Get the user enabled state of Mobile Data. |
| 6513 | * |
| 6514 | * TODO: remove and use isUserDataEnabled. |
| 6515 | * This can't be removed now because some vendor codes |
| 6516 | * calls through ITelephony directly while they should |
| 6517 | * use TelephonyManager. |
| 6518 | * |
| 6519 | * @return true on enabled |
| 6520 | */ |
| 6521 | @Override |
| 6522 | public boolean getDataEnabled(int subId) { |
| 6523 | return isUserDataEnabled(subId); |
| 6524 | } |
| 6525 | |
| 6526 | /** |
| 6527 | * Get whether mobile data is enabled per user setting. |
| 6528 | * |
| 6529 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6530 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6531 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6532 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6533 | * |
| 6534 | * @return {@code true} if data is enabled else {@code false} |
| 6535 | */ |
| 6536 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6537 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6538 | try { |
| 6539 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6540 | null); |
| 6541 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6542 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6543 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6544 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6545 | |
| 6546 | final long identity = Binder.clearCallingIdentity(); |
| 6547 | try { |
| 6548 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6549 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6550 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6551 | if (phone != null) { |
| 6552 | boolean retVal = phone.isUserDataEnabled(); |
| 6553 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6554 | return retVal; |
| 6555 | } else { |
| 6556 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6557 | return false; |
| 6558 | } |
| 6559 | } finally { |
| 6560 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6561 | } |
| 6562 | } |
| 6563 | |
| 6564 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6565 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6566 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6567 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6568 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6569 | * @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] | 6570 | */ |
| 6571 | @Override |
| 6572 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6573 | try { |
| 6574 | try { |
| 6575 | mApp.enforceCallingOrSelfPermission( |
| 6576 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6577 | null); |
| 6578 | } catch (Exception e) { |
| 6579 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6580 | "isDataEnabled"); |
| 6581 | } |
| 6582 | } catch (Exception e) { |
| 6583 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6584 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6585 | |
| 6586 | final long identity = Binder.clearCallingIdentity(); |
| 6587 | try { |
| 6588 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6589 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6590 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6591 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6592 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6593 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6594 | return retVal; |
| 6595 | } else { |
| 6596 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6597 | return false; |
| 6598 | } |
| 6599 | } finally { |
| 6600 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6601 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6602 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6603 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6604 | /** |
| 6605 | * Check if data is enabled for a specific reason |
| 6606 | * @param subId Subscription index |
| 6607 | * @param reason the reason the data enable change is taking place |
| 6608 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6609 | */ |
| 6610 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6611 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6612 | @TelephonyManager.DataEnabledReason int reason) { |
| 6613 | try { |
| 6614 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6615 | null); |
| 6616 | } catch (Exception e) { |
| 6617 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6618 | "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6619 | } |
| 6620 | |
| 6621 | |
| 6622 | final long identity = Binder.clearCallingIdentity(); |
| 6623 | try { |
| 6624 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6625 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6626 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6627 | + " reason=" + reason); |
| 6628 | } |
| 6629 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6630 | if (phone != null) { |
| 6631 | boolean retVal; |
| 6632 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6633 | retVal = phone.isUserDataEnabled(); |
| 6634 | } else { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6635 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6636 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6637 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6638 | return retVal; |
| 6639 | } else { |
| 6640 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6641 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6642 | + subId + " retVal=false"); |
| 6643 | } |
| 6644 | return false; |
| 6645 | } |
| 6646 | } finally { |
| 6647 | Binder.restoreCallingIdentity(identity); |
| 6648 | } |
| 6649 | } |
| 6650 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6651 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6652 | Phone phone) { |
Sarah Chin | 3394efe | 2021-04-09 10:37:15 -0700 | [diff] [blame] | 6653 | if (uid == Process.PHONE_UID) { |
| 6654 | // Skip the check if it's the phone UID (system UID removed in b/184713596) |
| 6655 | // 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] | 6656 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6657 | } |
| 6658 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6659 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6660 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6661 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6662 | || subController == null) return privilegeFromSim; |
| 6663 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6664 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6665 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6666 | |
| 6667 | final long identity = Binder.clearCallingIdentity(); |
| 6668 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6669 | int subId = phone.getSubId(); |
| 6670 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6671 | // A test override is in place for the privileges for this subId, so don't try to |
| 6672 | // read the subscription privileges. |
| 6673 | return privilegeFromSim; |
| 6674 | } |
| 6675 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6676 | SubscriptionManager subManager = (SubscriptionManager) |
| 6677 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6678 | for (String pkg : packages) { |
| 6679 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6680 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6681 | } |
| 6682 | } |
| 6683 | return privilegeFromSim; |
| 6684 | } finally { |
| 6685 | Binder.restoreCallingIdentity(identity); |
| 6686 | } |
| 6687 | } |
| 6688 | |
| 6689 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6690 | String pkgName) { |
| 6691 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6692 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6693 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6694 | || subController == null) return privilegeFromSim; |
| 6695 | |
| 6696 | final long identity = Binder.clearCallingIdentity(); |
| 6697 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6698 | int subId = phone.getSubId(); |
| 6699 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6700 | // A test override is in place for the privileges for this subId, so don't try to |
| 6701 | // read the subscription privileges. |
| 6702 | return privilegeFromSim; |
| 6703 | } |
| 6704 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6705 | SubscriptionManager subManager = (SubscriptionManager) |
| 6706 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6707 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6708 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6709 | } finally { |
| 6710 | Binder.restoreCallingIdentity(identity); |
| 6711 | } |
| 6712 | } |
| 6713 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6714 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6715 | public int getCarrierPrivilegeStatus(int subId) { |
| 6716 | final Phone phone = getPhone(subId); |
| 6717 | if (phone == null) { |
| 6718 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6719 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6720 | } |
| 6721 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6722 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6723 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6724 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6725 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6726 | |
| 6727 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6728 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6729 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6730 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6731 | |
| 6732 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6733 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6734 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6735 | final Phone phone = getPhone(subId); |
| 6736 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6737 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6738 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6739 | } |
| 6740 | UiccProfile profile = |
| 6741 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6742 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6743 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6744 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6745 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6746 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6747 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6748 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6749 | } |
| 6750 | |
| 6751 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6752 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6753 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6754 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6755 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6756 | } |
| 6757 | |
| 6758 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6759 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6760 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6761 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6762 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6763 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6764 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6765 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6766 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6767 | } |
| 6768 | |
| 6769 | @Override |
| 6770 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Sarah Chin | fc3169b | 2021-04-28 20:21:03 -0700 | [diff] [blame] | 6771 | // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6772 | if (TextUtils.isEmpty(pkgName)) |
| 6773 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6774 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6775 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6776 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6777 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6778 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6779 | continue; |
| 6780 | } |
| 6781 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6782 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6783 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6784 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6785 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6786 | break; |
| 6787 | } |
| 6788 | } |
| 6789 | |
| 6790 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6791 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6792 | |
| 6793 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6794 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6795 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6796 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6797 | loge("phoneId " + phoneId + " is not valid."); |
| 6798 | return null; |
| 6799 | } |
| 6800 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6801 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6802 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6803 | return null ; |
| 6804 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6805 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6806 | } |
| 6807 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6808 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6809 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6810 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6811 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6812 | List<String> privilegedPackages = new ArrayList<>(); |
| 6813 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6814 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6815 | // has UICC in that slot. |
| 6816 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6817 | if (card.hasCarrierPrivilegeRules()) { |
| 6818 | if (packages == null) { |
| 6819 | // Only check packages in user 0 for now |
| 6820 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6821 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6822 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6823 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6824 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6825 | } |
| 6826 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6827 | PackageInfo pkgInfo = packages.get(p); |
| 6828 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6829 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6830 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6831 | privilegedPackages.add(pkgInfo.packageName); |
| 6832 | } |
| 6833 | } |
| 6834 | } |
| 6835 | } |
| 6836 | return privilegedPackages; |
| 6837 | } |
| 6838 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6839 | @Override |
| 6840 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6841 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6842 | |
| 6843 | final long identity = Binder.clearCallingIdentity(); |
| 6844 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6845 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6846 | try { |
| 6847 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6848 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6849 | } |
| 6850 | } finally { |
| 6851 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6852 | } |
| 6853 | return privilegedPackages; |
| 6854 | } |
| 6855 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6856 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6857 | final Phone phone = getPhone(subId); |
| 6858 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6859 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6860 | return null; |
| 6861 | } |
| 6862 | String iccId = card.getIccId(); |
| 6863 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6864 | return null; |
| 6865 | } |
| 6866 | return iccId; |
| 6867 | } |
| 6868 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6869 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6870 | public void setCallComposerStatus(int subId, int status) { |
| 6871 | enforceModifyPermission(); |
| 6872 | |
| 6873 | final long identity = Binder.clearCallingIdentity(); |
| 6874 | try { |
| 6875 | Phone phone = getPhone(subId); |
| 6876 | if (phone != null) { |
| 6877 | Phone defaultPhone = phone.getImsPhone(); |
| 6878 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6879 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6880 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6881 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6882 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6883 | } |
| 6884 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6885 | } catch (ImsException e) { |
| 6886 | throw new ServiceSpecificException(e.getCode()); |
| 6887 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6888 | Binder.restoreCallingIdentity(identity); |
| 6889 | } |
| 6890 | } |
| 6891 | |
| 6892 | @Override |
| 6893 | public int getCallComposerStatus(int subId) { |
| 6894 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6895 | |
| 6896 | final long identity = Binder.clearCallingIdentity(); |
| 6897 | try { |
| 6898 | Phone phone = getPhone(subId); |
| 6899 | if (phone != null) { |
| 6900 | Phone defaultPhone = phone.getImsPhone(); |
| 6901 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6902 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6903 | return imsPhone.getCallComposerStatus(); |
| 6904 | } |
| 6905 | } |
| 6906 | } finally { |
| 6907 | Binder.restoreCallingIdentity(identity); |
| 6908 | } |
| 6909 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6910 | } |
| 6911 | |
| 6912 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6913 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6914 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6915 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6916 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6917 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6918 | final long identity = Binder.clearCallingIdentity(); |
| 6919 | try { |
| 6920 | final String iccId = getIccId(subId); |
| 6921 | final Phone phone = getPhone(subId); |
| 6922 | if (phone == null) { |
| 6923 | return false; |
| 6924 | } |
| 6925 | final String subscriberId = phone.getSubscriberId(); |
| 6926 | |
| 6927 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6928 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6929 | + subscriberId + " to " + number); |
| 6930 | } |
| 6931 | |
| 6932 | if (TextUtils.isEmpty(iccId)) { |
| 6933 | return false; |
| 6934 | } |
| 6935 | |
| 6936 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6937 | |
| 6938 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6939 | if (alphaTag == null) { |
| 6940 | editor.remove(alphaTagPrefKey); |
| 6941 | } else { |
| 6942 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6943 | } |
| 6944 | |
| 6945 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6946 | // track all merged IMSIs based on line number |
| 6947 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6948 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6949 | if (number == null) { |
| 6950 | editor.remove(numberPrefKey); |
| 6951 | editor.remove(subscriberPrefKey); |
| 6952 | } else { |
| 6953 | editor.putString(numberPrefKey, number); |
| 6954 | editor.putString(subscriberPrefKey, subscriberId); |
| 6955 | } |
| 6956 | |
| 6957 | editor.commit(); |
| 6958 | return true; |
| 6959 | } finally { |
| 6960 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6961 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6962 | } |
| 6963 | |
| 6964 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6965 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6966 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6967 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6968 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6969 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6970 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6971 | return null; |
| 6972 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6973 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6974 | final long identity = Binder.clearCallingIdentity(); |
| 6975 | try { |
| 6976 | String iccId = getIccId(subId); |
| 6977 | if (iccId != null) { |
| 6978 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6979 | if (DBG_MERGE) { |
| 6980 | log("getLine1NumberForDisplay returning " |
| 6981 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6982 | } |
| 6983 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6984 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6985 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6986 | return null; |
| 6987 | } finally { |
| 6988 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6989 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6990 | } |
| 6991 | |
| 6992 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6993 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6994 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6995 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6996 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6997 | return null; |
| 6998 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6999 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7000 | final long identity = Binder.clearCallingIdentity(); |
| 7001 | try { |
| 7002 | String iccId = getIccId(subId); |
| 7003 | if (iccId != null) { |
| 7004 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7005 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7006 | } |
| 7007 | return null; |
| 7008 | } finally { |
| 7009 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7010 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7011 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7012 | |
| 7013 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7014 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7015 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7016 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7017 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7018 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7019 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7020 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7021 | return null; |
| 7022 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7023 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7024 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7025 | // the process, where TelephonyManager was instantiated. |
| 7026 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7027 | final long identity = Binder.clearCallingIdentity(); |
| 7028 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7029 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7030 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7031 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7032 | |
| 7033 | // Figure out what subscribers are currently active |
| 7034 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7035 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7036 | // Only consider subs which match the current subId |
| 7037 | // This logic can be simplified. See b/131189269 for progress. |
| 7038 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7039 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7040 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7041 | |
| 7042 | // First pass, find a number override for an active subscriber |
| 7043 | String mergeNumber = null; |
| 7044 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7045 | for (String key : prefs.keySet()) { |
| 7046 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7047 | final String subscriberId = (String) prefs.get(key); |
| 7048 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7049 | final String iccId = key.substring( |
| 7050 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7051 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7052 | mergeNumber = (String) prefs.get(numberKey); |
| 7053 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7054 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7055 | + " for active subscriber " + subscriberId); |
| 7056 | } |
| 7057 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7058 | break; |
| 7059 | } |
| 7060 | } |
| 7061 | } |
| 7062 | } |
| 7063 | |
| 7064 | // Shortcut when no active merged subscribers |
| 7065 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7066 | return null; |
| 7067 | } |
| 7068 | |
| 7069 | // Second pass, find all subscribers under that line override |
| 7070 | final ArraySet<String> result = new ArraySet<>(); |
| 7071 | for (String key : prefs.keySet()) { |
| 7072 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7073 | final String number = (String) prefs.get(key); |
| 7074 | if (mergeNumber.equals(number)) { |
| 7075 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7076 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7077 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7078 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7079 | result.add(subscriberId); |
| 7080 | } |
| 7081 | } |
| 7082 | } |
| 7083 | } |
| 7084 | |
| 7085 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7086 | Arrays.sort(resultArray); |
| 7087 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7088 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7089 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7090 | } |
| 7091 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7092 | } finally { |
| 7093 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7094 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7095 | } |
| 7096 | |
| 7097 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7098 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7099 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7100 | |
| 7101 | final long identity = Binder.clearCallingIdentity(); |
| 7102 | try { |
| 7103 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7104 | TelephonyManager.class); |
| 7105 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7106 | if (subscriberId == null) { |
| 7107 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7108 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7109 | + subId); |
| 7110 | } |
| 7111 | return null; |
| 7112 | } |
| 7113 | |
| 7114 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 7115 | .getSubscriptionInfo(subId); |
| 7116 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 7117 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7118 | if (groupUuid == null) { |
| 7119 | return new String[]{subscriberId}; |
| 7120 | } |
| 7121 | |
| 7122 | // Get all subscriberIds from the group. |
| 7123 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 7124 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7125 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7126 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7127 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7128 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7129 | if (subscriberId != null) { |
| 7130 | mergedSubscriberIds.add(subscriberId); |
| 7131 | } |
| 7132 | } |
| 7133 | |
| 7134 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7135 | } finally { |
| 7136 | Binder.restoreCallingIdentity(identity); |
| 7137 | |
| 7138 | } |
| 7139 | } |
| 7140 | |
| 7141 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7142 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7143 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7144 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7145 | |
| 7146 | final long identity = Binder.clearCallingIdentity(); |
| 7147 | try { |
| 7148 | final Phone phone = getPhone(subId); |
| 7149 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7150 | } finally { |
| 7151 | Binder.restoreCallingIdentity(identity); |
| 7152 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7153 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7154 | |
| 7155 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7156 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7157 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7158 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7159 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7160 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7161 | |
| 7162 | final long identity = Binder.clearCallingIdentity(); |
| 7163 | try { |
| 7164 | final Phone phone = getPhone(subId); |
| 7165 | if (phone == null) { |
| 7166 | return false; |
| 7167 | } |
| 7168 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7169 | cdmaNonRoamingList); |
| 7170 | } finally { |
| 7171 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7172 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7173 | } |
| 7174 | |
| 7175 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7176 | @Deprecated |
| 7177 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7178 | enforceModifyPermission(); |
| 7179 | |
| 7180 | int returnValue = 0; |
| 7181 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7182 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7183 | if(result.exception == null) { |
| 7184 | if (result.result != null) { |
| 7185 | byte[] responseData = (byte[])(result.result); |
| 7186 | if(responseData.length > oemResp.length) { |
| 7187 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7188 | responseData.length + "bytes. Buffer Size is " + |
| 7189 | oemResp.length + "bytes."); |
| 7190 | } |
| 7191 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7192 | returnValue = responseData.length; |
| 7193 | } |
| 7194 | } else { |
| 7195 | CommandException ex = (CommandException) result.exception; |
| 7196 | returnValue = ex.getCommandError().ordinal(); |
| 7197 | if(returnValue > 0) returnValue *= -1; |
| 7198 | } |
| 7199 | } catch (RuntimeException e) { |
| 7200 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7201 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7202 | if(returnValue > 0) returnValue *= -1; |
| 7203 | } |
| 7204 | |
| 7205 | return returnValue; |
| 7206 | } |
| 7207 | |
| 7208 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7209 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7210 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7211 | try { |
| 7212 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7213 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7214 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7215 | } catch (SecurityException e) { |
| 7216 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7217 | throw e; |
| 7218 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7219 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7220 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7221 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7222 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7223 | final long identity = Binder.clearCallingIdentity(); |
| 7224 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7225 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7226 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7227 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7228 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7229 | } finally { |
| 7230 | Binder.restoreCallingIdentity(identity); |
| 7231 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7232 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7233 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7234 | |
| 7235 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7236 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7237 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7238 | try { |
| 7239 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7240 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7241 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7242 | } |
| 7243 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7244 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7245 | } |
| 7246 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7247 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7248 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7249 | throw new SecurityException("App must be the dialer role holder to" |
| 7250 | + " upload a call composer pic"); |
| 7251 | } |
| 7252 | |
| 7253 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7254 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7255 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7256 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7257 | boolean readUntilEnd = false; |
| 7258 | int totalBytesRead = 0; |
| 7259 | byte[] buffer = new byte[16 * 1024]; |
| 7260 | while (true) { |
| 7261 | int numRead; |
| 7262 | try { |
| 7263 | numRead = input.read(buffer); |
| 7264 | } catch (IOException e) { |
| 7265 | try { |
| 7266 | fd.checkError(); |
| 7267 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7268 | null); |
| 7269 | } catch (IOException e1) { |
| 7270 | // This means that the other side closed explicitly with an error. If this |
| 7271 | // happens, log and ignore. |
| 7272 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7273 | } |
| 7274 | break; |
| 7275 | } |
| 7276 | if (numRead == -1) { |
| 7277 | readUntilEnd = true; |
| 7278 | break; |
| 7279 | } |
| 7280 | totalBytesRead += numRead; |
| 7281 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7282 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7283 | try { |
| 7284 | input.close(); |
| 7285 | } catch (IOException e) { |
| 7286 | // ignore |
| 7287 | } |
| 7288 | break; |
| 7289 | } |
| 7290 | output.write(buffer, 0, numRead); |
| 7291 | } |
| 7292 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7293 | // close is above, where the picture size is too big. |
| 7294 | |
| 7295 | try { |
| 7296 | fd.checkError(); |
| 7297 | } catch (IOException e) { |
| 7298 | loge("Remote end for call composer closed with an error: " + e); |
| 7299 | return; |
| 7300 | } |
| 7301 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7302 | if (!readUntilEnd) { |
| 7303 | loge("Did not finish reading entire image; aborting"); |
| 7304 | return; |
| 7305 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7306 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7307 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7308 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7309 | new CallComposerPictureTransfer.Factory() {}, |
| 7310 | imageData, |
| 7311 | (result) -> { |
| 7312 | if (result.first != null) { |
| 7313 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7314 | Bundle outputResult = new Bundle(); |
| 7315 | outputResult.putParcelable( |
| 7316 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7317 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7318 | outputResult); |
| 7319 | } else { |
| 7320 | callback.send(result.second, null); |
| 7321 | } |
| 7322 | } |
| 7323 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7324 | }); |
| 7325 | } |
| 7326 | |
| 7327 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7328 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7329 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7330 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7331 | |
| 7332 | final long identity = Binder.clearCallingIdentity(); |
| 7333 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7334 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7335 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7336 | } finally { |
| 7337 | Binder.restoreCallingIdentity(identity); |
| 7338 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7339 | } |
| 7340 | |
| 7341 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7342 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7343 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7344 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7345 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7346 | return false; |
| 7347 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7348 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7349 | final long identity = Binder.clearCallingIdentity(); |
| 7350 | try { |
| 7351 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7352 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7353 | // In the long run, we may instead need to check if there exists a connection service |
| 7354 | // which can support video calling. |
| 7355 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7356 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7357 | return imsManager.isVtEnabledByPlatform() |
| 7358 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7359 | && imsManager.isVtEnabledByUser(); |
| 7360 | } finally { |
| 7361 | Binder.restoreCallingIdentity(identity); |
| 7362 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7363 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7364 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7365 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7366 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7367 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7368 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7369 | mApp, subId, callingPackage, callingFeatureId, |
| 7370 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7371 | return false; |
| 7372 | } |
| 7373 | |
| 7374 | final long identity = Binder.clearCallingIdentity(); |
| 7375 | try { |
| 7376 | CarrierConfigManager configManager = |
| 7377 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7378 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7379 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7380 | } finally { |
| 7381 | Binder.restoreCallingIdentity(identity); |
| 7382 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7383 | } |
| 7384 | |
| 7385 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7386 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7387 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7388 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7389 | return false; |
| 7390 | } |
| 7391 | |
| 7392 | final long identity = Binder.clearCallingIdentity(); |
| 7393 | try { |
| 7394 | CarrierConfigManager configManager = |
| 7395 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7396 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7397 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7398 | } finally { |
| 7399 | Binder.restoreCallingIdentity(identity); |
| 7400 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7401 | } |
| 7402 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7403 | @Override |
| 7404 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7405 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7406 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7407 | } |
| 7408 | |
| 7409 | @Override |
| 7410 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7411 | final long identity = Binder.clearCallingIdentity(); |
| 7412 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7413 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7414 | } finally { |
| 7415 | Binder.restoreCallingIdentity(identity); |
| 7416 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7417 | } |
| 7418 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7419 | /** |
| 7420 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7421 | * support for the feature and device firmware support. |
| 7422 | * |
| 7423 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7424 | */ |
| 7425 | @Override |
| 7426 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7427 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7428 | final Phone phone = getPhone(subscriptionId); |
| 7429 | if (phone == null) { |
| 7430 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7431 | return false; |
| 7432 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7433 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7434 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7435 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7436 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7437 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7438 | return isCarrierSupported && isDeviceSupported; |
| 7439 | } finally { |
| 7440 | Binder.restoreCallingIdentity(identity); |
| 7441 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7442 | } |
| 7443 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7444 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7445 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7446 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7447 | * 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] | 7448 | */ |
| 7449 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7450 | final long identity = Binder.clearCallingIdentity(); |
| 7451 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7452 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7453 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7454 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7455 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7456 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7457 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7458 | } finally { |
| 7459 | Binder.restoreCallingIdentity(identity); |
| 7460 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7461 | } |
| 7462 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7463 | @Deprecated |
| 7464 | @Override |
| 7465 | public String getDeviceId(String callingPackage) { |
| 7466 | return getDeviceIdWithFeature(callingPackage, null); |
| 7467 | } |
| 7468 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7469 | /** |
| 7470 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7471 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7472 | * |
| 7473 | * <p>Requires Permission: |
| 7474 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7475 | */ |
| 7476 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7477 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7478 | try { |
| 7479 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7480 | } catch (SecurityException se) { |
| 7481 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7482 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7483 | + Binder.getCallingUid()); |
| 7484 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7485 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7486 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7487 | return null; |
| 7488 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7489 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7490 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7491 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7492 | return null; |
| 7493 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7494 | |
| 7495 | final long identity = Binder.clearCallingIdentity(); |
| 7496 | try { |
| 7497 | return phone.getDeviceId(); |
| 7498 | } finally { |
| 7499 | Binder.restoreCallingIdentity(identity); |
| 7500 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7501 | } |
| 7502 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7503 | /** |
| 7504 | * {@hide} |
| 7505 | * Returns the IMS Registration Status on a particular subid |
| 7506 | * |
| 7507 | * @param subId |
| 7508 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7509 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7510 | Phone phone = getPhone(subId); |
| 7511 | if (phone != null) { |
| 7512 | return phone.isImsRegistered(); |
| 7513 | } else { |
| 7514 | return false; |
| 7515 | } |
| 7516 | } |
| 7517 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7518 | @Override |
| 7519 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7520 | final long identity = Binder.clearCallingIdentity(); |
| 7521 | try { |
| 7522 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7523 | } finally { |
| 7524 | Binder.restoreCallingIdentity(identity); |
| 7525 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7526 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7527 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7528 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7529 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7530 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7531 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7532 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7533 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7534 | } |
| 7535 | final long identity = Binder.clearCallingIdentity(); |
| 7536 | try { |
| 7537 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7538 | } finally { |
| 7539 | Binder.restoreCallingIdentity(identity); |
| 7540 | } |
| 7541 | } |
| 7542 | |
| 7543 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7544 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7545 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7546 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7547 | mApp, |
| 7548 | subscriptionId, |
| 7549 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7550 | final long identity = Binder.clearCallingIdentity(); |
| 7551 | try { |
| 7552 | Phone phone = getPhone(subscriptionId); |
| 7553 | if (phone == null) { |
| 7554 | return null; |
| 7555 | } |
| 7556 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7557 | } finally { |
| 7558 | Binder.restoreCallingIdentity(identity); |
| 7559 | } |
| 7560 | } |
| 7561 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7562 | /** |
| 7563 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7564 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7565 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7566 | final long identity = Binder.clearCallingIdentity(); |
| 7567 | try { |
| 7568 | Phone phone = getPhone(subId); |
| 7569 | if (phone != null) { |
| 7570 | return phone.isWifiCallingEnabled(); |
| 7571 | } else { |
| 7572 | return false; |
| 7573 | } |
| 7574 | } finally { |
| 7575 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7576 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7577 | } |
| 7578 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7579 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7580 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7581 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7582 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7583 | final long identity = Binder.clearCallingIdentity(); |
| 7584 | try { |
| 7585 | Phone phone = getPhone(subId); |
| 7586 | if (phone != null) { |
| 7587 | return phone.isVideoEnabled(); |
| 7588 | } else { |
| 7589 | return false; |
| 7590 | } |
| 7591 | } finally { |
| 7592 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7593 | } |
| 7594 | } |
| 7595 | |
| 7596 | /** |
| 7597 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7598 | * defined in {@link ImsRegistrationImplBase}. |
| 7599 | */ |
| 7600 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7601 | final long identity = Binder.clearCallingIdentity(); |
| 7602 | try { |
| 7603 | Phone phone = getPhone(subId); |
| 7604 | if (phone != null) { |
| 7605 | return phone.getImsRegistrationTech(); |
| 7606 | } else { |
| 7607 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7608 | } |
| 7609 | } finally { |
| 7610 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7611 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7612 | } |
| 7613 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7614 | @Override |
| 7615 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7616 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7617 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7618 | return; |
| 7619 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7620 | Phone defaultPhone = getDefaultPhone(); |
| 7621 | if (defaultPhone != null) { |
| 7622 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7623 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7624 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7625 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7626 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7627 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7628 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7629 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7630 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7631 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7632 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7633 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7634 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7635 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7636 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7637 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7638 | // There has been issues when Sms raw table somehow stores orphan |
| 7639 | // fragments. They lead to garbled message when new fragments come |
| 7640 | // in and combined with those stale ones. In case this happens again, |
| 7641 | // user can reset all network settings which will clean up this table. |
| 7642 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7643 | // Clean up IMS settings as well here. |
| 7644 | int slotId = getSlotIndex(subId); |
| 7645 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7646 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7647 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7648 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7649 | if (defaultPhone == null) { |
| 7650 | return; |
| 7651 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7652 | // Erase modem config if erase modem on network setting is enabled. |
| 7653 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7654 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7655 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7656 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7657 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7658 | |
| 7659 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7660 | } finally { |
| 7661 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7662 | } |
| 7663 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7664 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7665 | @VisibleForTesting |
| 7666 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7667 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7668 | return; |
| 7669 | } |
| 7670 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7671 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7672 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7673 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7674 | "user=" + defaultNetworkType); |
| 7675 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7676 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7677 | defaultNetworkType, null); |
| 7678 | } |
| 7679 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7680 | private void cleanUpSmsRawTable(Context context) { |
| 7681 | ContentResolver resolver = context.getContentResolver(); |
| 7682 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7683 | resolver.delete(uri, null, null); |
| 7684 | } |
| 7685 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7686 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7687 | public String getSimLocaleForSubscriber(int subId) { |
| 7688 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7689 | final Phone phone = getPhone(subId); |
| 7690 | if (phone == null) { |
| 7691 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7692 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7693 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7694 | final long identity = Binder.clearCallingIdentity(); |
| 7695 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7696 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7697 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7698 | if (info == null) { |
| 7699 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7700 | return null; |
| 7701 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7702 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7703 | // preferences (EF-PL and EF-LI)... |
| 7704 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7705 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7706 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7707 | if (localeFromDefaultSim != null) { |
| 7708 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7709 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7710 | + localeFromDefaultSim); |
| 7711 | return localeFromDefaultSim.toLanguageTag(); |
| 7712 | } else { |
| 7713 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7714 | } |
| 7715 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7716 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7717 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7718 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7719 | // the SIM and carrier preferences does not include a country we add the country |
| 7720 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7721 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7722 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7723 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7724 | return mccLocale.toLanguageTag(); |
| 7725 | } |
| 7726 | |
| 7727 | if (DBG) log("No locale found - returning null"); |
| 7728 | return null; |
| 7729 | } finally { |
| 7730 | Binder.restoreCallingIdentity(identity); |
| 7731 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7732 | } |
| 7733 | |
| 7734 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7735 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7736 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7737 | } |
| 7738 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7739 | /** |
| 7740 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7741 | */ |
| 7742 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7743 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7744 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7745 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7746 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7747 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7748 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7749 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7750 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7751 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7752 | * representing the state of the modem. |
| 7753 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7754 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7755 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7756 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7757 | */ |
| 7758 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7759 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7760 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7761 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7762 | |
| 7763 | final long identity = Binder.clearCallingIdentity(); |
| 7764 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7765 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7766 | } finally { |
| 7767 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7768 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7769 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7770 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7771 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7772 | // less than total activity duration. |
| 7773 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7774 | if (info == null) { |
| 7775 | return false; |
| 7776 | } |
| 7777 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7778 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7779 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7780 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7781 | return (info.isValid() |
| 7782 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7783 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7784 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7785 | && (totalTxTimeMs <= activityDurationMs)); |
| 7786 | } |
| 7787 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7788 | /** |
| 7789 | * {@hide} |
| 7790 | * Returns the service state information on specified subscription. |
| 7791 | */ |
| 7792 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7793 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7794 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7795 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7796 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7797 | return null; |
| 7798 | } |
| 7799 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7800 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7801 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7802 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7803 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7804 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7805 | .setCallingPid(Binder.getCallingPid()) |
| 7806 | .setCallingUid(Binder.getCallingUid()) |
| 7807 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7808 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7809 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7810 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7811 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7812 | .build()); |
| 7813 | |
| 7814 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7815 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7816 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7817 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7818 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7819 | .setCallingPid(Binder.getCallingPid()) |
| 7820 | .setCallingUid(Binder.getCallingUid()) |
| 7821 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7822 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7823 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7824 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7825 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7826 | .build()); |
| 7827 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7828 | boolean hasFinePermission = |
| 7829 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7830 | boolean hasCoarsePermission = |
| 7831 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7832 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7833 | final Phone phone = getPhone(subId); |
| 7834 | if (phone == null) { |
| 7835 | return null; |
| 7836 | } |
| 7837 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7838 | final long identity = Binder.clearCallingIdentity(); |
| 7839 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7840 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7841 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7842 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7843 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7844 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7845 | Rlog.d(LOG_TAG, |
| 7846 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7847 | return null; |
| 7848 | } |
| 7849 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7850 | ServiceState ss = phone.getServiceState(); |
| 7851 | |
| 7852 | // Scrub out the location info in ServiceState depending on what level of access |
| 7853 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7854 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7855 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7856 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7857 | } finally { |
| 7858 | Binder.restoreCallingIdentity(identity); |
| 7859 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7860 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7861 | |
| 7862 | /** |
| 7863 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7864 | * |
| 7865 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7866 | * voicemail ringtone. |
| 7867 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7868 | * PhoneAccount. |
| 7869 | */ |
| 7870 | @Override |
| 7871 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7872 | final long identity = Binder.clearCallingIdentity(); |
| 7873 | try { |
| 7874 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7875 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7876 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7877 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7878 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7879 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7880 | } finally { |
| 7881 | Binder.restoreCallingIdentity(identity); |
| 7882 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7883 | } |
| 7884 | |
| 7885 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7886 | * Sets the per-account voicemail ringtone. |
| 7887 | * |
| 7888 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7889 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7890 | * |
| 7891 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7892 | * voicemail ringtone. |
| 7893 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7894 | * PhoneAccount. |
| 7895 | */ |
| 7896 | @Override |
| 7897 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7898 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7899 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7900 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7901 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7902 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7903 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7904 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7905 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7906 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7907 | |
| 7908 | final long identity = Binder.clearCallingIdentity(); |
| 7909 | try { |
| 7910 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7911 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7912 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7913 | } |
| 7914 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7915 | } finally { |
| 7916 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7917 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7918 | } |
| 7919 | |
| 7920 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7921 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7922 | * |
| 7923 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7924 | * voicemail vibration setting. |
| 7925 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7926 | */ |
| 7927 | @Override |
| 7928 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7929 | final long identity = Binder.clearCallingIdentity(); |
| 7930 | try { |
| 7931 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7932 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7933 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7934 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7935 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7936 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7937 | } finally { |
| 7938 | Binder.restoreCallingIdentity(identity); |
| 7939 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7940 | } |
| 7941 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7942 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7943 | * Sets the per-account voicemail vibration. |
| 7944 | * |
| 7945 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7946 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7947 | * |
| 7948 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7949 | * voicemail vibration setting. |
| 7950 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7951 | * specific PhoneAccount. |
| 7952 | */ |
| 7953 | @Override |
| 7954 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7955 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7956 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7957 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7958 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7959 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7960 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7961 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7962 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7963 | } |
| 7964 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7965 | final long identity = Binder.clearCallingIdentity(); |
| 7966 | try { |
| 7967 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7968 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7969 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7970 | } |
| 7971 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7972 | } finally { |
| 7973 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7974 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7975 | } |
| 7976 | |
| 7977 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7978 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7979 | * |
| 7980 | * @throws SecurityException if the caller does not have the required permission |
| 7981 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7982 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7983 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7984 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7985 | } |
| 7986 | |
| 7987 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7988 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7989 | * permission. |
| 7990 | * |
| 7991 | * @throws SecurityException if the caller does not have the required permission |
| 7992 | */ |
| 7993 | private void enforceSendSmsPermission() { |
| 7994 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7995 | } |
| 7996 | |
| 7997 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7998 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7999 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8000 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8001 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8002 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8003 | final long identity = Binder.clearCallingIdentity(); |
| 8004 | try { |
| 8005 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8006 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8007 | if (componentName == null) { |
| 8008 | throw new SecurityException( |
| 8009 | "Caller not current active visual voicemail package[null]"); |
| 8010 | } |
| 8011 | String vvmPackage = componentName.getPackageName(); |
| 8012 | if (!callingPackage.equals(vvmPackage)) { |
| 8013 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 8014 | + vvmPackage + "]"); |
| 8015 | } |
| 8016 | } finally { |
| 8017 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8018 | } |
| 8019 | } |
| 8020 | |
| 8021 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8022 | * Return the application ID for the app type. |
| 8023 | * |
| 8024 | * @param subId the subscription ID that this request applies to. |
| 8025 | * @param appType the uicc app type. |
| 8026 | * @return Application ID for specificied app type, or null if no uicc. |
| 8027 | */ |
| 8028 | @Override |
| 8029 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8030 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8031 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8032 | |
| 8033 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8034 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8035 | if (phone == null) { |
| 8036 | return null; |
| 8037 | } |
| 8038 | String aid = null; |
| 8039 | try { |
| 8040 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 8041 | .getApplicationByType(appType).getAid(); |
| 8042 | } catch (Exception e) { |
| 8043 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8044 | } |
| 8045 | return aid; |
| 8046 | } finally { |
| 8047 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8048 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8049 | } |
| 8050 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8051 | /** |
| 8052 | * Return the Electronic Serial Number. |
| 8053 | * |
| 8054 | * @param subId the subscription ID that this request applies to. |
| 8055 | * @return ESN or null if error. |
| 8056 | */ |
| 8057 | @Override |
| 8058 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8059 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8060 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8061 | |
| 8062 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8063 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8064 | if (phone == null) { |
| 8065 | return null; |
| 8066 | } |
| 8067 | String esn = null; |
| 8068 | try { |
| 8069 | esn = phone.getEsn(); |
| 8070 | } catch (Exception e) { |
| 8071 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8072 | } |
| 8073 | return esn; |
| 8074 | } finally { |
| 8075 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8076 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8077 | } |
| 8078 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8079 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8080 | * Return the Preferred Roaming List Version. |
| 8081 | * |
| 8082 | * @param subId the subscription ID that this request applies to. |
| 8083 | * @return PRLVersion or null if error. |
| 8084 | */ |
| 8085 | @Override |
| 8086 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8087 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8088 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8089 | |
| 8090 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8091 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8092 | if (phone == null) { |
| 8093 | return null; |
| 8094 | } |
| 8095 | String cdmaPrlVersion = null; |
| 8096 | try { |
| 8097 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8098 | } catch (Exception e) { |
| 8099 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8100 | } |
| 8101 | return cdmaPrlVersion; |
| 8102 | } finally { |
| 8103 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8104 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8105 | } |
| 8106 | |
| 8107 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8108 | * Get snapshot of Telephony histograms |
| 8109 | * @return List of Telephony histograms |
| 8110 | * @hide |
| 8111 | */ |
| 8112 | @Override |
| 8113 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8114 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8115 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8116 | |
| 8117 | final long identity = Binder.clearCallingIdentity(); |
| 8118 | try { |
| 8119 | return RIL.getTelephonyRILTimingHistograms(); |
| 8120 | } finally { |
| 8121 | Binder.restoreCallingIdentity(identity); |
| 8122 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8123 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8124 | |
| 8125 | /** |
| 8126 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8127 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8128 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8129 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8130 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8131 | * @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] | 8132 | */ |
| 8133 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8134 | @TelephonyManager.SetCarrierRestrictionResult |
| 8135 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8136 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8137 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8138 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8139 | if (carrierRestrictionRules == null) { |
| 8140 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8141 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8142 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8143 | final long identity = Binder.clearCallingIdentity(); |
| 8144 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8145 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8146 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8147 | } finally { |
| 8148 | Binder.restoreCallingIdentity(identity); |
| 8149 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8150 | } |
| 8151 | |
| 8152 | /** |
| 8153 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8154 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8155 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8156 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8157 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8158 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8159 | */ |
| 8160 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8161 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8162 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8163 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8164 | |
| 8165 | final long identity = Binder.clearCallingIdentity(); |
| 8166 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8167 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8168 | if (response instanceof CarrierRestrictionRules) { |
| 8169 | return (CarrierRestrictionRules) response; |
| 8170 | } |
| 8171 | // Response is an Exception of some kind, |
| 8172 | // which is signalled to the user as a NULL retval |
| 8173 | return null; |
| 8174 | } catch (Exception e) { |
| 8175 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8176 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8177 | } finally { |
| 8178 | Binder.restoreCallingIdentity(identity); |
| 8179 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8180 | } |
| 8181 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8182 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8183 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8184 | * @param subId the subscription ID that this action applies to. |
| 8185 | * @param enabled control enable or disable radio. |
| 8186 | * {@hide} |
| 8187 | */ |
| 8188 | @Override |
| 8189 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8190 | enforceModifyPermission(); |
| 8191 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8192 | |
| 8193 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8194 | if (phone == null) { |
| 8195 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8196 | return; |
| 8197 | } |
| 8198 | try { |
| 8199 | phone.carrierActionSetRadioEnabled(enabled); |
| 8200 | } catch (Exception e) { |
| 8201 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8202 | } finally { |
| 8203 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8204 | } |
| 8205 | } |
| 8206 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8207 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8208 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8209 | * network status based on which carrier apps could apply actions accordingly, |
| 8210 | * enable/disable default url handler for example. |
| 8211 | * |
| 8212 | * @param subId the subscription ID that this action applies to. |
| 8213 | * @param report control start/stop reporting the default network status. |
| 8214 | * {@hide} |
| 8215 | */ |
| 8216 | @Override |
| 8217 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8218 | enforceModifyPermission(); |
| 8219 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8220 | |
| 8221 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8222 | if (phone == null) { |
| 8223 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8224 | return; |
| 8225 | } |
| 8226 | try { |
| 8227 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8228 | } catch (Exception e) { |
| 8229 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8230 | } finally { |
| 8231 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8232 | } |
| 8233 | } |
| 8234 | |
| 8235 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8236 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8237 | * @param subId the subscription ID that this action applies to. |
| 8238 | * {@hide} |
| 8239 | */ |
| 8240 | @Override |
| 8241 | public void carrierActionResetAll(int subId) { |
| 8242 | enforceModifyPermission(); |
| 8243 | final Phone phone = getPhone(subId); |
| 8244 | if (phone == null) { |
| 8245 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8246 | return; |
| 8247 | } |
| 8248 | try { |
| 8249 | phone.carrierActionResetAll(); |
| 8250 | } catch (Exception e) { |
| 8251 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8252 | } |
| 8253 | } |
| 8254 | |
| 8255 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8256 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8257 | * bug report is being generated. |
| 8258 | */ |
| 8259 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8260 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8261 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8262 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8263 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8264 | + Binder.getCallingPid() |
| 8265 | + ", uid=" + Binder.getCallingUid() |
| 8266 | + "without permission " |
| 8267 | + android.Manifest.permission.DUMP); |
| 8268 | return; |
| 8269 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8270 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8271 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8272 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8273 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8274 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8275 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8276 | @NonNull String[] args) { |
| 8277 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8278 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8279 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8280 | } |
| 8281 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8282 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8283 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8284 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8285 | * @param reason the reason the data enable change is taking place |
| 8286 | * @param enabled True if enabling the data, otherwise disabling. |
| 8287 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8288 | */ |
| 8289 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8290 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8291 | boolean enabled) { |
| 8292 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8293 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8294 | try { |
| 8295 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8296 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8297 | } catch (SecurityException se) { |
| 8298 | enforceModifyPermission(); |
| 8299 | } |
| 8300 | } else { |
| 8301 | enforceModifyPermission(); |
| 8302 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8303 | |
| 8304 | final long identity = Binder.clearCallingIdentity(); |
| 8305 | try { |
| 8306 | Phone phone = getPhone(subId); |
| 8307 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8308 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8309 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8310 | } else { |
| 8311 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 8312 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8313 | } |
| 8314 | } finally { |
| 8315 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8316 | } |
| 8317 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8318 | |
| 8319 | /** |
| 8320 | * Get Client request stats |
| 8321 | * @return List of Client Request Stats |
| 8322 | * @hide |
| 8323 | */ |
| 8324 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8325 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8326 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8327 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8328 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8329 | return null; |
| 8330 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8331 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8332 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8333 | final long identity = Binder.clearCallingIdentity(); |
| 8334 | try { |
| 8335 | if (phone != null) { |
| 8336 | return phone.getClientRequestStats(); |
| 8337 | } |
| 8338 | |
| 8339 | return null; |
| 8340 | } finally { |
| 8341 | Binder.restoreCallingIdentity(identity); |
| 8342 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8343 | } |
| 8344 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8345 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8346 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8347 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8348 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8349 | |
| 8350 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8351 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8352 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8353 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8354 | * @param state State of SIM (power down, power up, pass through) |
| 8355 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8356 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8357 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8358 | * |
| 8359 | **/ |
| 8360 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8361 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8362 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8363 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8364 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8365 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8366 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8367 | final long identity = Binder.clearCallingIdentity(); |
| 8368 | try { |
| 8369 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8370 | phone.setSimPowerState(state, null, workSource); |
| 8371 | } |
| 8372 | } finally { |
| 8373 | Binder.restoreCallingIdentity(identity); |
| 8374 | } |
| 8375 | } |
| 8376 | |
| 8377 | /** |
| 8378 | * Set SIM card power state. |
| 8379 | * |
| 8380 | * @param slotIndex SIM slot id. |
| 8381 | * @param state State of SIM (power down, power up, pass through) |
| 8382 | * @param callback callback to trigger after success or failure |
| 8383 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8384 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8385 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8386 | * |
| 8387 | **/ |
| 8388 | @Override |
| 8389 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8390 | IIntegerConsumer callback) { |
| 8391 | enforceModifyPermission(); |
| 8392 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8393 | |
| 8394 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8395 | |
| 8396 | final long identity = Binder.clearCallingIdentity(); |
| 8397 | try { |
| 8398 | if (phone != null) { |
| 8399 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8400 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8401 | } |
| 8402 | } finally { |
| 8403 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8404 | } |
| 8405 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8406 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8407 | private boolean isUssdApiAllowed(int subId) { |
| 8408 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8409 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8410 | if (configManager == null) { |
| 8411 | return false; |
| 8412 | } |
| 8413 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8414 | if (pb == null) { |
| 8415 | return false; |
| 8416 | } |
| 8417 | return pb.getBoolean( |
| 8418 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8419 | } |
| 8420 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8421 | /** |
| 8422 | * Check if phone is in emergency callback mode |
| 8423 | * @return true if phone is in emergency callback mode |
| 8424 | * @param subId sub id |
| 8425 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8426 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8427 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8428 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8429 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8430 | |
| 8431 | final long identity = Binder.clearCallingIdentity(); |
| 8432 | try { |
| 8433 | if (phone != null) { |
| 8434 | return phone.isInEcm(); |
| 8435 | } else { |
| 8436 | return false; |
| 8437 | } |
| 8438 | } finally { |
| 8439 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8440 | } |
| 8441 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8442 | |
| 8443 | /** |
| 8444 | * Get the current signal strength information for the given subscription. |
| 8445 | * Because this information is not updated when the device is in a low power state |
| 8446 | * it should not be relied-upon to be current. |
| 8447 | * @param subId Subscription index |
| 8448 | * @return the most recent cached signal strength info from the modem |
| 8449 | */ |
| 8450 | @Override |
| 8451 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8452 | final long identity = Binder.clearCallingIdentity(); |
| 8453 | try { |
| 8454 | Phone p = getPhone(subId); |
| 8455 | if (p == null) { |
| 8456 | return null; |
| 8457 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8458 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8459 | return p.getSignalStrength(); |
| 8460 | } finally { |
| 8461 | Binder.restoreCallingIdentity(identity); |
| 8462 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8463 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8464 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8465 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8466 | * Get the current modem radio state for the given slot. |
| 8467 | * @param slotIndex slot index. |
| 8468 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8469 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8470 | * @return the current radio power state from the modem |
| 8471 | */ |
| 8472 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8473 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8474 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8475 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8476 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8477 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8478 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8479 | } |
| 8480 | |
| 8481 | final long identity = Binder.clearCallingIdentity(); |
| 8482 | try { |
| 8483 | return phone.getRadioPowerState(); |
| 8484 | } finally { |
| 8485 | Binder.restoreCallingIdentity(identity); |
| 8486 | } |
| 8487 | } |
| 8488 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8489 | } |
| 8490 | |
| 8491 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8492 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8493 | * |
| 8494 | * <p>Requires one of the following permissions: |
| 8495 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8496 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8497 | * privileges. |
| 8498 | * |
| 8499 | * @param subId subscription id |
| 8500 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8501 | * {@code false}. |
| 8502 | */ |
| 8503 | @Override |
| 8504 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8505 | try { |
| 8506 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8507 | null); |
| 8508 | } catch (Exception e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8509 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8510 | mApp, subId, "isDataRoamingEnabled"); |
| 8511 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8512 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8513 | boolean isEnabled = false; |
| 8514 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8515 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8516 | Phone phone = getPhone(subId); |
| 8517 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8518 | } finally { |
| 8519 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8520 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8521 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8522 | } |
| 8523 | |
| 8524 | |
| 8525 | /** |
| 8526 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8527 | * |
| 8528 | * <p> Requires permission: |
| 8529 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8530 | * privileges. |
| 8531 | * |
| 8532 | * @param subId subscription id |
| 8533 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8534 | */ |
| 8535 | @Override |
| 8536 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8537 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8538 | mApp, subId, "setDataRoamingEnabled"); |
| 8539 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8540 | final long identity = Binder.clearCallingIdentity(); |
| 8541 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8542 | Phone phone = getPhone(subId); |
| 8543 | if (phone != null) { |
| 8544 | phone.setDataRoamingEnabled(isEnabled); |
| 8545 | } |
| 8546 | } finally { |
| 8547 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8548 | } |
| 8549 | } |
| 8550 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8551 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8552 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8553 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8554 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8555 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8556 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8557 | boolean isAllowed = true; |
| 8558 | final long identity = Binder.clearCallingIdentity(); |
| 8559 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8560 | Phone phone = getPhone(subId); |
| 8561 | if (phone != null) { |
| 8562 | isAllowed = phone.isCspPlmnEnabled(); |
| 8563 | } |
| 8564 | } finally { |
| 8565 | Binder.restoreCallingIdentity(identity); |
| 8566 | } |
| 8567 | return isAllowed; |
| 8568 | } |
| 8569 | |
| 8570 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8571 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8572 | // Verify that tha callingPackage belongs to the calling UID |
| 8573 | mApp.getSystemService(AppOpsManager.class) |
| 8574 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8575 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8576 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8577 | try { |
| 8578 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8579 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8580 | } catch (SecurityException e) { |
| 8581 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8582 | // has carrier privileges on an active UICC |
| 8583 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8584 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8585 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8586 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8587 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8588 | |
| 8589 | final long identity = Binder.clearCallingIdentity(); |
| 8590 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8591 | UiccController uiccController = UiccController.getInstance(); |
| 8592 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8593 | if (hasReadPermission) { |
| 8594 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8595 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8596 | |
| 8597 | // Remove private info if the caller doesn't have access |
| 8598 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8599 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8600 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8601 | // is available |
| 8602 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8603 | if (card == null || card.getUiccProfile() == null) { |
| 8604 | // assume no access if the card or profile is unavailable |
| 8605 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8606 | continue; |
| 8607 | } |
| 8608 | UiccProfile profile = card.getUiccProfile(); |
| 8609 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8610 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8611 | filteredInfos.add(cardInfo); |
| 8612 | } else { |
| 8613 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8614 | } |
| 8615 | } |
| 8616 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8617 | } finally { |
| 8618 | Binder.restoreCallingIdentity(identity); |
| 8619 | } |
| 8620 | } |
| 8621 | |
| 8622 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8623 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8624 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8625 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8626 | final long identity = Binder.clearCallingIdentity(); |
| 8627 | try { |
| 8628 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8629 | if (slots == null) { |
| 8630 | Rlog.i(LOG_TAG, "slots is null."); |
| 8631 | return null; |
| 8632 | } |
| 8633 | |
| 8634 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8635 | for (int i = 0; i < slots.length; i++) { |
| 8636 | UiccSlot slot = slots[i]; |
| 8637 | if (slot == null) { |
| 8638 | continue; |
| 8639 | } |
| 8640 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8641 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8642 | UiccCard card = slot.getUiccCard(); |
| 8643 | if (card != null) { |
| 8644 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8645 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8646 | cardId = slot.getEid(); |
| 8647 | if (TextUtils.isEmpty(cardId)) { |
| 8648 | cardId = slot.getIccId(); |
| 8649 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8650 | } |
| 8651 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8652 | if (cardId != null) { |
| 8653 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8654 | // if cardId is an EID, it's all digits so this is fine |
| 8655 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8656 | } |
| 8657 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8658 | int cardState = 0; |
| 8659 | switch (slot.getCardState()) { |
| 8660 | case CARDSTATE_ABSENT: |
| 8661 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8662 | break; |
| 8663 | case CARDSTATE_PRESENT: |
| 8664 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8665 | break; |
| 8666 | case CARDSTATE_ERROR: |
| 8667 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8668 | break; |
| 8669 | case CARDSTATE_RESTRICTED: |
| 8670 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8671 | break; |
| 8672 | default: |
| 8673 | break; |
| 8674 | |
| 8675 | } |
| 8676 | |
| 8677 | infos[i] = new UiccSlotInfo( |
| 8678 | slot.isActive(), |
| 8679 | slot.isEuicc(), |
| 8680 | cardId, |
| 8681 | cardState, |
| 8682 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8683 | slot.isExtendedApduSupported(), |
| 8684 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8685 | } |
| 8686 | return infos; |
| 8687 | } finally { |
| 8688 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8689 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8690 | } |
| 8691 | |
| 8692 | @Override |
| 8693 | public boolean switchSlots(int[] physicalSlots) { |
| 8694 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8695 | |
| 8696 | final long identity = Binder.clearCallingIdentity(); |
| 8697 | try { |
| 8698 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8699 | } finally { |
| 8700 | Binder.restoreCallingIdentity(identity); |
| 8701 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8702 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8703 | |
| 8704 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8705 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8706 | final long identity = Binder.clearCallingIdentity(); |
| 8707 | try { |
| 8708 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8709 | } finally { |
| 8710 | Binder.restoreCallingIdentity(identity); |
| 8711 | } |
| 8712 | } |
| 8713 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8714 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8715 | * A test API to reload the UICC profile. |
| 8716 | * |
| 8717 | * <p>Requires that the calling app has permission |
| 8718 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8719 | * @hide |
| 8720 | */ |
| 8721 | @Override |
| 8722 | public void refreshUiccProfile(int subId) { |
| 8723 | enforceModifyPermission(); |
| 8724 | |
| 8725 | final long identity = Binder.clearCallingIdentity(); |
| 8726 | try { |
| 8727 | Phone phone = getPhone(subId); |
| 8728 | if (phone == null) { |
| 8729 | return; |
| 8730 | } |
| 8731 | UiccCard uiccCard = phone.getUiccCard(); |
| 8732 | if (uiccCard == null) { |
| 8733 | return; |
| 8734 | } |
| 8735 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8736 | if (uiccProfile == null) { |
| 8737 | return; |
| 8738 | } |
| 8739 | uiccProfile.refresh(); |
| 8740 | } finally { |
| 8741 | Binder.restoreCallingIdentity(identity); |
| 8742 | } |
| 8743 | } |
| 8744 | |
| 8745 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8746 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8747 | */ |
| 8748 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8749 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8750 | } |
| 8751 | |
| 8752 | /** |
| 8753 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8754 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8755 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8756 | */ |
| 8757 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8758 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8759 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8760 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8761 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8762 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8763 | return isDataRoamingEnabled; |
| 8764 | } |
| 8765 | |
| 8766 | /** |
| 8767 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8768 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8769 | */ |
| 8770 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8771 | List<Integer> list = TelephonyProperties.default_network(); |
| 8772 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8773 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8774 | return list.get(phoneId); |
| 8775 | } |
| 8776 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8777 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8778 | |
| 8779 | @Override |
| 8780 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8781 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8782 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8783 | |
| 8784 | final long identity = Binder.clearCallingIdentity(); |
| 8785 | try { |
| 8786 | final Phone phone = getPhone(subId); |
| 8787 | if (phone == null) { |
| 8788 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8789 | return; |
| 8790 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8791 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8792 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8793 | if (carrierPrivilegeRules == null) { |
| 8794 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8795 | } else { |
| 8796 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8797 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8798 | } finally { |
| 8799 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8800 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8801 | } |
| 8802 | |
| 8803 | @Override |
| 8804 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8805 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8806 | |
| 8807 | final long identity = Binder.clearCallingIdentity(); |
| 8808 | try { |
| 8809 | final Phone phone = getPhone(subId); |
| 8810 | if (phone == null) { |
| 8811 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8812 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8813 | } |
| 8814 | return phone.getCarrierIdListVersion(); |
| 8815 | } finally { |
| 8816 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8817 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8818 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8819 | |
| 8820 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8821 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8822 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8823 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8824 | mApp, subId, callingPackage, callingFeatureId, |
| 8825 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8826 | return -1; |
| 8827 | } |
| 8828 | |
| 8829 | final long identity = Binder.clearCallingIdentity(); |
| 8830 | try { |
| 8831 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8832 | } finally { |
| 8833 | Binder.restoreCallingIdentity(identity); |
| 8834 | } |
| 8835 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8836 | |
| 8837 | @Override |
| 8838 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8839 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8840 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8841 | mApp, subId, "getCdmaRoamingMode"); |
| 8842 | |
| 8843 | final long identity = Binder.clearCallingIdentity(); |
| 8844 | try { |
| 8845 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8846 | } finally { |
| 8847 | Binder.restoreCallingIdentity(identity); |
| 8848 | } |
| 8849 | } |
| 8850 | |
| 8851 | @Override |
| 8852 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8853 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8854 | mApp, subId, "setCdmaRoamingMode"); |
| 8855 | |
| 8856 | final long identity = Binder.clearCallingIdentity(); |
| 8857 | try { |
| 8858 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8859 | } finally { |
| 8860 | Binder.restoreCallingIdentity(identity); |
| 8861 | } |
| 8862 | } |
| 8863 | |
| 8864 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8865 | public int getCdmaSubscriptionMode(int subId) { |
| 8866 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8867 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8868 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8869 | |
| 8870 | final long identity = Binder.clearCallingIdentity(); |
| 8871 | try { |
| 8872 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8873 | } finally { |
| 8874 | Binder.restoreCallingIdentity(identity); |
| 8875 | } |
| 8876 | } |
| 8877 | |
| 8878 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8879 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8880 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8881 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8882 | |
| 8883 | final long identity = Binder.clearCallingIdentity(); |
| 8884 | try { |
| 8885 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8886 | } finally { |
| 8887 | Binder.restoreCallingIdentity(identity); |
| 8888 | } |
| 8889 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8890 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8891 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8892 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8893 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8894 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8895 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8896 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8897 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8898 | } |
| 8899 | final long identity = Binder.clearCallingIdentity(); |
| 8900 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8901 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8902 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8903 | if (phone.getEmergencyNumberTracker() != null |
| 8904 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8905 | emergencyNumberListInternal.put( |
| 8906 | phone.getSubId(), |
| 8907 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8908 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8909 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8910 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8911 | } finally { |
| 8912 | Binder.restoreCallingIdentity(identity); |
| 8913 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8914 | } |
| 8915 | |
| 8916 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8917 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8918 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8919 | if (!exactMatch) { |
| 8920 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8921 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8922 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8923 | } |
| 8924 | final long identity = Binder.clearCallingIdentity(); |
| 8925 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8926 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8927 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8928 | && phone.getEmergencyNumberTracker() |
| 8929 | .isEmergencyNumber(number, exactMatch)) { |
| 8930 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8931 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8932 | } |
| 8933 | return false; |
| 8934 | } finally { |
| 8935 | Binder.restoreCallingIdentity(identity); |
| 8936 | } |
| 8937 | } |
| 8938 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8939 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 8940 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 8941 | */ |
| 8942 | @Override |
| 8943 | public void startEmergencyCallbackMode() { |
| 8944 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8945 | "startEmergencyCallbackMode"); |
| 8946 | enforceModifyPermission(); |
| 8947 | final long identity = Binder.clearCallingIdentity(); |
| 8948 | try { |
| 8949 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8950 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 8951 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 8952 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 8953 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 8954 | gsmCdmaPhone.obtainMessage( |
| 8955 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 8956 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 8957 | } |
| 8958 | } |
| 8959 | } finally { |
| 8960 | Binder.restoreCallingIdentity(identity); |
| 8961 | } |
| 8962 | } |
| 8963 | |
| 8964 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8965 | * Update emergency number list for test mode. |
| 8966 | */ |
| 8967 | @Override |
| 8968 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8969 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8970 | "updateEmergencyNumberListTestMode"); |
| 8971 | |
| 8972 | final long identity = Binder.clearCallingIdentity(); |
| 8973 | try { |
| 8974 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8975 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8976 | if (tracker != null) { |
| 8977 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8978 | } |
| 8979 | } |
| 8980 | } finally { |
| 8981 | Binder.restoreCallingIdentity(identity); |
| 8982 | } |
| 8983 | } |
| 8984 | |
| 8985 | /** |
| 8986 | * Get the full emergency number list for test mode. |
| 8987 | */ |
| 8988 | @Override |
| 8989 | public List<String> getEmergencyNumberListTestMode() { |
| 8990 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8991 | "getEmergencyNumberListTestMode"); |
| 8992 | |
| 8993 | final long identity = Binder.clearCallingIdentity(); |
| 8994 | try { |
| 8995 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8996 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8997 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8998 | if (tracker != null) { |
| 8999 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9000 | emergencyNumbers.add(num.getNumber()); |
| 9001 | } |
| 9002 | } |
| 9003 | } |
| 9004 | return new ArrayList<>(emergencyNumbers); |
| 9005 | } finally { |
| 9006 | Binder.restoreCallingIdentity(identity); |
| 9007 | } |
| 9008 | } |
| 9009 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9010 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9011 | public int getEmergencyNumberDbVersion(int subId) { |
| 9012 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9013 | |
| 9014 | final long identity = Binder.clearCallingIdentity(); |
| 9015 | try { |
| 9016 | final Phone phone = getPhone(subId); |
| 9017 | if (phone == null) { |
| 9018 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9019 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9020 | } |
| 9021 | return phone.getEmergencyNumberDbVersion(); |
| 9022 | } finally { |
| 9023 | Binder.restoreCallingIdentity(identity); |
| 9024 | } |
| 9025 | } |
| 9026 | |
| 9027 | @Override |
| 9028 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9029 | enforceModifyPermission(); |
| 9030 | |
| 9031 | final long identity = Binder.clearCallingIdentity(); |
| 9032 | try { |
| 9033 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9034 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9035 | if (tracker != null) { |
| 9036 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9037 | } |
| 9038 | } |
| 9039 | } finally { |
| 9040 | Binder.restoreCallingIdentity(identity); |
| 9041 | } |
| 9042 | } |
| 9043 | |
| 9044 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9045 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9046 | enforceActiveEmergencySessionPermission(); |
| 9047 | |
| 9048 | final long identity = Binder.clearCallingIdentity(); |
| 9049 | try { |
| 9050 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9051 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9052 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9053 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9054 | } |
| 9055 | } |
| 9056 | } finally { |
| 9057 | Binder.restoreCallingIdentity(identity); |
| 9058 | } |
| 9059 | } |
| 9060 | |
| 9061 | @Override |
| 9062 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9063 | enforceActiveEmergencySessionPermission(); |
| 9064 | |
| 9065 | final long identity = Binder.clearCallingIdentity(); |
| 9066 | try { |
| 9067 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9068 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9069 | if (tracker != null) { |
| 9070 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9071 | } |
| 9072 | } |
| 9073 | } finally { |
| 9074 | Binder.restoreCallingIdentity(identity); |
| 9075 | } |
| 9076 | } |
| 9077 | |
| 9078 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9079 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9080 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9081 | Phone phone = getPhone(subId); |
| 9082 | if (phone == null) { |
| 9083 | return null; |
| 9084 | } |
| 9085 | final long identity = Binder.clearCallingIdentity(); |
| 9086 | try { |
| 9087 | UiccProfile profile = UiccController.getInstance() |
| 9088 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9089 | if (profile != null) { |
| 9090 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9091 | } |
| 9092 | } finally { |
| 9093 | Binder.restoreCallingIdentity(identity); |
| 9094 | } |
| 9095 | return null; |
| 9096 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9097 | |
| 9098 | /** |
| 9099 | * Enable or disable a modem stack. |
| 9100 | */ |
| 9101 | @Override |
| 9102 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9103 | enforceModifyPermission(); |
| 9104 | |
| 9105 | final long identity = Binder.clearCallingIdentity(); |
| 9106 | try { |
| 9107 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9108 | if (phone == null) { |
| 9109 | return false; |
| 9110 | } else { |
| 9111 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9112 | } |
| 9113 | } finally { |
| 9114 | Binder.restoreCallingIdentity(identity); |
| 9115 | } |
| 9116 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9117 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9118 | /** |
| 9119 | * Whether a modem stack is enabled or not. |
| 9120 | */ |
| 9121 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9122 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9123 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9124 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9125 | if (phone == null) return false; |
| 9126 | |
| 9127 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9128 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9129 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9130 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9131 | } |
| 9132 | |
| 9133 | final long identity = Binder.clearCallingIdentity(); |
| 9134 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9135 | try { |
| 9136 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9137 | } catch (NoSuchElementException ex) { |
| 9138 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9139 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9140 | } finally { |
| 9141 | Binder.restoreCallingIdentity(identity); |
| 9142 | } |
| 9143 | } |
| 9144 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9145 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9146 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9147 | enforceModifyPermission(); |
| 9148 | |
| 9149 | final long identity = Binder.clearCallingIdentity(); |
| 9150 | try { |
| 9151 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9152 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9153 | .commit(); |
| 9154 | } finally { |
| 9155 | Binder.restoreCallingIdentity(identity); |
| 9156 | } |
| 9157 | } |
| 9158 | |
| 9159 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9160 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9161 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9162 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9163 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9164 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9165 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9166 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9167 | |
| 9168 | final long identity = Binder.clearCallingIdentity(); |
| 9169 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9170 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9171 | } finally { |
| 9172 | Binder.restoreCallingIdentity(identity); |
| 9173 | } |
| 9174 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9175 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9176 | @TelephonyManager.IsMultiSimSupportedResult |
| 9177 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9178 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9179 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9180 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9181 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9182 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9183 | } |
| 9184 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9185 | // supported by the modem, indicate that it is restricted. |
| 9186 | PhoneCapability staticCapability = |
| 9187 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9188 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9189 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9190 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9191 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9192 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9193 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9194 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9195 | } |
| 9196 | // Check if support of multiple SIMs is restricted by carrier |
| 9197 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9198 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9199 | } |
| 9200 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9201 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9202 | } |
| 9203 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9204 | /** |
| 9205 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9206 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9207 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9208 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9209 | * @param numOfSims number of active sims we want to switch to |
| 9210 | */ |
| 9211 | @Override |
| 9212 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9213 | if (numOfSims == 1) { |
| 9214 | enforceModifyPermission(); |
| 9215 | } else { |
| 9216 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9217 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9218 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9219 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9220 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9221 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9222 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9223 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9224 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9225 | return; |
| 9226 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9227 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9228 | } finally { |
| 9229 | Binder.restoreCallingIdentity(identity); |
| 9230 | } |
| 9231 | } |
| 9232 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9233 | @Override |
| 9234 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9235 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9236 | Phone phone = getPhone(subId); |
| 9237 | if (phone == null) { |
| 9238 | return false; |
| 9239 | } |
| 9240 | final long identity = Binder.clearCallingIdentity(); |
| 9241 | try { |
| 9242 | UiccCard uiccCard = phone.getUiccCard(); |
| 9243 | if (uiccCard == null) { |
| 9244 | return false; |
| 9245 | } |
| 9246 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 9247 | if (uiccProfile == null) { |
| 9248 | return false; |
| 9249 | } |
| 9250 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9251 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9252 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9253 | } |
| 9254 | return false; |
| 9255 | } finally { |
| 9256 | Binder.restoreCallingIdentity(identity); |
| 9257 | } |
| 9258 | } |
| 9259 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9260 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9261 | * Get whether making changes to modem configurations will trigger reboot. |
| 9262 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9263 | */ |
| 9264 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9265 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9266 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9267 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9268 | mApp, subId, callingPackage, callingFeatureId, |
| 9269 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9270 | return false; |
| 9271 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9272 | final long identity = Binder.clearCallingIdentity(); |
| 9273 | try { |
| 9274 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9275 | } finally { |
| 9276 | Binder.restoreCallingIdentity(identity); |
| 9277 | } |
| 9278 | } |
| 9279 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9280 | private void updateModemStateMetrics() { |
| 9281 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9282 | // TODO: check the state for each modem if the api is ready. |
| 9283 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9284 | } |
| 9285 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9286 | @Override |
| 9287 | public int[] getSlotsMapping() { |
| 9288 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 9289 | |
| 9290 | final long identity = Binder.clearCallingIdentity(); |
| 9291 | try { |
| 9292 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 9293 | // All logical slots should have a mapping to a physical slot. |
| 9294 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 9295 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 9296 | for (int i = 0; i < slotInfos.length; i++) { |
| 9297 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 9298 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 9299 | } |
| 9300 | } |
| 9301 | return logicalSlotsMapping; |
| 9302 | } finally { |
| 9303 | Binder.restoreCallingIdentity(identity); |
| 9304 | } |
| 9305 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9306 | |
| 9307 | /** |
| 9308 | * Get the IRadio HAL Version |
| 9309 | */ |
| 9310 | @Override |
| 9311 | public int getRadioHalVersion() { |
| 9312 | Phone phone = getDefaultPhone(); |
| 9313 | if (phone == null) return -1; |
| 9314 | HalVersion hv = phone.getHalVersion(); |
| 9315 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9316 | return hv.major * 100 + hv.minor; |
| 9317 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9318 | |
| 9319 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9320 | * Get the current calling package name. |
| 9321 | * @return the current calling package name |
| 9322 | */ |
| 9323 | @Override |
| 9324 | public String getCurrentPackageName() { |
| 9325 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9326 | } |
| 9327 | |
| 9328 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9329 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9330 | * corresponding network requests on a subId. |
| 9331 | * |
| 9332 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9333 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9334 | * 2) APN is un-metered for this subscription, or |
| 9335 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9336 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9337 | * |
| 9338 | * @return whether data is allowed for a apn type. |
| 9339 | * |
| 9340 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9341 | */ |
| 9342 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9343 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9344 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9345 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9346 | |
| 9347 | // Now that all security checks passes, perform the operation as ourselves. |
| 9348 | final long identity = Binder.clearCallingIdentity(); |
| 9349 | try { |
| 9350 | Phone phone = getPhone(subId); |
| 9351 | if (phone == null) return false; |
| 9352 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9353 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9354 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9355 | } finally { |
| 9356 | Binder.restoreCallingIdentity(identity); |
| 9357 | } |
| 9358 | } |
| 9359 | |
| 9360 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9361 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9362 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9363 | |
| 9364 | // Now that all security checks passes, perform the operation as ourselves. |
| 9365 | final long identity = Binder.clearCallingIdentity(); |
| 9366 | try { |
| 9367 | Phone phone = getPhone(subId); |
| 9368 | if (phone == null) return true; // By default return true. |
| 9369 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9370 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9371 | } finally { |
| 9372 | Binder.restoreCallingIdentity(identity); |
| 9373 | } |
| 9374 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9375 | |
| 9376 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9377 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9378 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9379 | enforceModifyPermission(); |
| 9380 | long token = Binder.clearCallingIdentity(); |
| 9381 | try { |
| 9382 | Phone phone = getPhone(subscriptionId); |
| 9383 | if (phone == null) { |
| 9384 | try { |
| 9385 | if (resultCallback != null) { |
| 9386 | resultCallback.accept(false); |
| 9387 | } |
| 9388 | } catch (RemoteException e) { |
| 9389 | // ignore |
| 9390 | } |
| 9391 | return; |
| 9392 | } |
| 9393 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9394 | Pair.create(specifiers, (x) -> { |
| 9395 | try { |
| 9396 | if (resultCallback != null) { |
| 9397 | resultCallback.accept(x); |
| 9398 | } |
| 9399 | } catch (RemoteException e) { |
| 9400 | // ignore |
| 9401 | } |
| 9402 | }); |
| 9403 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9404 | } finally { |
| 9405 | Binder.restoreCallingIdentity(token); |
| 9406 | } |
| 9407 | } |
| 9408 | |
| 9409 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9410 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9411 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9412 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9413 | mApp, subId, "getSystemSelectionChannels"); |
| 9414 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9415 | final long identity = Binder.clearCallingIdentity(); |
| 9416 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 9417 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 9418 | if (result instanceof IllegalStateException) { |
| 9419 | throw (IllegalStateException) result; |
| 9420 | } |
| 9421 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9422 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9423 | return specifiers; |
| 9424 | } finally { |
| 9425 | Binder.restoreCallingIdentity(identity); |
| 9426 | } |
| 9427 | } |
| 9428 | |
| 9429 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9430 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9431 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9432 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9433 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9434 | if (iccRecords == null) { |
| 9435 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9436 | return false; |
| 9437 | } |
| 9438 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9439 | } |
| 9440 | |
| 9441 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9442 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9443 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9444 | if (callingPackage == null) { |
| 9445 | callingPackage = getCurrentPackageName(); |
| 9446 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9447 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9448 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9449 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9450 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9451 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9452 | } |
| 9453 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9454 | Intent intent = new Intent(); |
| 9455 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9456 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9457 | // Bring up choose default SMS subscription dialog right now |
| 9458 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9459 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9460 | mApp.startActivity(intent); |
| 9461 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9462 | |
| 9463 | @Override |
| 9464 | public String getMmsUAProfUrl(int subId) { |
| 9465 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9466 | final long identity = Binder.clearCallingIdentity(); |
| 9467 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9468 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9469 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9470 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9471 | return carrierUAProfUrl; |
| 9472 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9473 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9474 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9475 | } finally { |
| 9476 | Binder.restoreCallingIdentity(identity); |
| 9477 | } |
| 9478 | } |
| 9479 | |
| 9480 | @Override |
| 9481 | public String getMmsUserAgent(int subId) { |
| 9482 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9483 | final long identity = Binder.clearCallingIdentity(); |
| 9484 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9485 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9486 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9487 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9488 | return carrierUserAgent; |
| 9489 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9490 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9491 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9492 | } finally { |
| 9493 | Binder.restoreCallingIdentity(identity); |
| 9494 | } |
| 9495 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9496 | |
| 9497 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9498 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9499 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9500 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9501 | final long identity = Binder.clearCallingIdentity(); |
| 9502 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9503 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9504 | if (phone == null) return false; |
| 9505 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9506 | switch (policy) { |
| 9507 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9508 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9509 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9510 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9511 | default: |
| 9512 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9513 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9514 | } finally { |
| 9515 | Binder.restoreCallingIdentity(identity); |
| 9516 | } |
| 9517 | } |
| 9518 | |
| 9519 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9520 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9521 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9522 | enforceModifyPermission(); |
| 9523 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9524 | final long identity = Binder.clearCallingIdentity(); |
| 9525 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9526 | Phone phone = getPhone(subscriptionId); |
| 9527 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9528 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9529 | switch (policy) { |
| 9530 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9531 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9532 | break; |
| 9533 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9534 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9535 | break; |
| 9536 | default: |
| 9537 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9538 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9539 | } finally { |
| 9540 | Binder.restoreCallingIdentity(identity); |
| 9541 | } |
| 9542 | } |
| 9543 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9544 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9545 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9546 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9547 | * otherwise. |
| 9548 | */ |
| 9549 | @Override |
| 9550 | public void setCepEnabled(boolean isCepEnabled) { |
| 9551 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9552 | |
| 9553 | final long identity = Binder.clearCallingIdentity(); |
| 9554 | try { |
| 9555 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9556 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9557 | Phone defaultPhone = phone.getImsPhone(); |
| 9558 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9559 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9560 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9561 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9562 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9563 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9564 | + imsPhone.getMsisdn()); |
| 9565 | } |
| 9566 | } |
| 9567 | } finally { |
| 9568 | Binder.restoreCallingIdentity(identity); |
| 9569 | } |
| 9570 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9571 | |
| 9572 | /** |
| 9573 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9574 | * |
| 9575 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9576 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9577 | * before being read. |
| 9578 | */ |
| 9579 | @Override |
| 9580 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9581 | isCompressed) { |
| 9582 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9583 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9584 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9585 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9586 | } |
| 9587 | if (!isImsAvailableOnDevice()) { |
| 9588 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9589 | "IMS not available on device."); |
| 9590 | } |
| 9591 | |
| 9592 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9593 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9594 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9595 | } finally { |
| 9596 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9597 | } |
| 9598 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9599 | |
| 9600 | @Override |
| 9601 | public boolean isIccLockEnabled(int subId) { |
| 9602 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9603 | |
| 9604 | // Now that all security checks passes, perform the operation as ourselves. |
| 9605 | final long identity = Binder.clearCallingIdentity(); |
| 9606 | try { |
| 9607 | Phone phone = getPhone(subId); |
| 9608 | if (phone != null && phone.getIccCard() != null) { |
| 9609 | return phone.getIccCard().getIccLockEnabled(); |
| 9610 | } else { |
| 9611 | return false; |
| 9612 | } |
| 9613 | } finally { |
| 9614 | Binder.restoreCallingIdentity(identity); |
| 9615 | } |
| 9616 | } |
| 9617 | |
| 9618 | /** |
| 9619 | * Set the ICC pin lock enabled or disabled. |
| 9620 | * |
| 9621 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9622 | * three cases: |
| 9623 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9624 | * successfully. |
| 9625 | * - Positive number and zero for remaining password attempts. |
| 9626 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9627 | * |
| 9628 | */ |
| 9629 | @Override |
| 9630 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9631 | enforceModifyPermission(); |
| 9632 | |
| 9633 | Phone phone = getPhone(subId); |
| 9634 | if (phone == null) { |
| 9635 | return 0; |
| 9636 | } |
| 9637 | // Now that all security checks passes, perform the operation as ourselves. |
| 9638 | final long identity = Binder.clearCallingIdentity(); |
| 9639 | try { |
| 9640 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9641 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9642 | return attemptsRemaining; |
| 9643 | |
| 9644 | } catch (Exception e) { |
| 9645 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9646 | } finally { |
| 9647 | Binder.restoreCallingIdentity(identity); |
| 9648 | } |
| 9649 | return 0; |
| 9650 | } |
| 9651 | |
| 9652 | /** |
| 9653 | * Change the ICC password used in ICC pin lock. |
| 9654 | * |
| 9655 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9656 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9657 | * - Positive number and zero for remaining password attempts. |
| 9658 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9659 | * |
| 9660 | */ |
| 9661 | @Override |
| 9662 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9663 | enforceModifyPermission(); |
| 9664 | |
| 9665 | Phone phone = getPhone(subId); |
| 9666 | if (phone == null) { |
| 9667 | return 0; |
| 9668 | } |
| 9669 | // Now that all security checks passes, perform the operation as ourselves. |
| 9670 | final long identity = Binder.clearCallingIdentity(); |
| 9671 | try { |
| 9672 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9673 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9674 | return attemptsRemaining; |
| 9675 | |
| 9676 | } catch (Exception e) { |
| 9677 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9678 | } finally { |
| 9679 | Binder.restoreCallingIdentity(identity); |
| 9680 | } |
| 9681 | return 0; |
| 9682 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9683 | |
| 9684 | /** |
| 9685 | * Request for receiving user activity notification |
| 9686 | */ |
| 9687 | @Override |
| 9688 | public void requestUserActivityNotification() { |
| 9689 | if (!mNotifyUserActivity.get() |
| 9690 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9691 | mNotifyUserActivity.set(true); |
| 9692 | } |
| 9693 | } |
| 9694 | |
| 9695 | /** |
| 9696 | * Called when userActivity is signalled in the power manager. |
| 9697 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9698 | */ |
| 9699 | @Override |
| 9700 | public void userActivity() { |
| 9701 | // *************************************** |
| 9702 | // * Inherited from PhoneWindowManager * |
| 9703 | // *************************************** |
| 9704 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9705 | // WITH ITS LOCKS HELD. |
| 9706 | // |
| 9707 | // This code must be VERY careful about the locks |
| 9708 | // it acquires. |
| 9709 | // In fact, the current code acquires way too many, |
| 9710 | // and probably has lurking deadlocks. |
| 9711 | |
| 9712 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9713 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9714 | } |
| 9715 | |
| 9716 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9717 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9718 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9719 | } |
| 9720 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9721 | |
| 9722 | @Override |
| 9723 | public boolean canConnectTo5GInDsdsMode() { |
| 9724 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9725 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9726 | |
| 9727 | @Override |
| 9728 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9729 | String callingFeatureId) { |
| 9730 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9731 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9732 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9733 | } |
| 9734 | |
| 9735 | Phone phone = getPhone(subId); |
| 9736 | if (phone == null) { |
| 9737 | throw new RuntimeException("phone is not available"); |
| 9738 | } |
| 9739 | // Now that all security checks passes, perform the operation as ourselves. |
| 9740 | final long identity = Binder.clearCallingIdentity(); |
| 9741 | try { |
| 9742 | return phone.getEquivalentHomePlmns(); |
| 9743 | } finally { |
| 9744 | Binder.restoreCallingIdentity(identity); |
| 9745 | } |
| 9746 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9747 | |
| 9748 | @Override |
| 9749 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 9750 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 9751 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 9752 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9753 | if (radioInterfaceCapabilities == null) { |
| 9754 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9755 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 9756 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9757 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9758 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9759 | @Override |
| 9760 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9761 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9762 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 9763 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9764 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 9765 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9766 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9767 | if (DBG) { |
| 9768 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9769 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9770 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9771 | } |
| 9772 | |
| 9773 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9774 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9775 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9776 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9777 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9778 | if (callback != null) { |
| 9779 | try { |
| 9780 | callback.onAuthenticationFailure( |
| 9781 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9782 | } catch (RemoteException exception) { |
| 9783 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9784 | } |
| 9785 | return; |
| 9786 | } |
| 9787 | } |
| 9788 | |
| 9789 | final long token = Binder.clearCallingIdentity(); |
| 9790 | try { |
| 9791 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9792 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9793 | forceBootStrapping, callback)); |
| 9794 | } finally { |
| 9795 | Binder.restoreCallingIdentity(token); |
| 9796 | } |
| 9797 | } |
| 9798 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9799 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 9800 | * Attempts to set the radio power state for all phones for thermal reason. |
| 9801 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9802 | * requested radio power state will actually be set. See {@link |
| 9803 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9804 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9805 | * @param enable {@code true} if trying to turn radio on. |
| 9806 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9807 | * false}. |
| 9808 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 9809 | private boolean setRadioPowerForThermal(boolean enable) { |
| 9810 | boolean isPhoneAvailable = false; |
| 9811 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 9812 | Phone phone = PhoneFactory.getPhone(i); |
| 9813 | if (phone != null) { |
| 9814 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9815 | isPhoneAvailable = true; |
| 9816 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9817 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 9818 | |
| 9819 | // return true if successfully informed the phone object about the thermal radio power |
| 9820 | // request. |
| 9821 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9822 | } |
| 9823 | |
| 9824 | private int handleDataThrottlingRequest(int subId, |
| 9825 | DataThrottlingRequest dataThrottlingRequest) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 9826 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 9827 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 9828 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 9829 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 9830 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 9831 | } |
| 9832 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9833 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9834 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 9835 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9836 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9837 | } |
| 9838 | |
| 9839 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9840 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 9841 | if (isDataThrottlingSupported) { |
| 9842 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9843 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 9844 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9845 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9846 | } else if (thermalMitigationResult |
| 9847 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 9848 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 9849 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 9850 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 9851 | } |
| 9852 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9853 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 9854 | |
| 9855 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9856 | } |
| 9857 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 9858 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 9859 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 9860 | for (String pckg : context.getResources() |
| 9861 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 9862 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 9863 | } |
| 9864 | } |
| 9865 | |
| 9866 | return sThermalMitigationAllowlistedPackages; |
| 9867 | } |
| 9868 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 9869 | private boolean isAnyPhoneInEmergencyState() { |
| 9870 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 9871 | if (tm.isInEmergencyCall()) { |
| 9872 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 9873 | return true; |
| 9874 | } |
| 9875 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9876 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 9877 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 9878 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 9879 | + phone.isInEcm()); |
| 9880 | return true; |
| 9881 | } |
| 9882 | } |
| 9883 | |
| 9884 | return false; |
| 9885 | } |
| 9886 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 9887 | /** |
| 9888 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 9889 | * @param packageName name of package to be allowlisted |
| 9890 | * @param context |
| 9891 | */ |
| 9892 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 9893 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 9894 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 9895 | } |
| 9896 | |
| 9897 | /** |
| 9898 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 9899 | * @param packageName name of package to remove from allowlist |
| 9900 | * @param context |
| 9901 | */ |
| 9902 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 9903 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 9904 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 9905 | } |
| 9906 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9907 | /** |
| 9908 | * Thermal mitigation request to control functionalities at modem. |
| 9909 | * |
| 9910 | * @param subId the id of the subscription. |
| 9911 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 9912 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9913 | * |
| 9914 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9915 | */ |
| 9916 | @Override |
| 9917 | @ThermalMitigationResult |
| 9918 | public int sendThermalMitigationRequest( |
| 9919 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 9920 | ThermalMitigationRequest thermalMitigationRequest, |
| 9921 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9922 | enforceModifyPermission(); |
| 9923 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 9924 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 9925 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 9926 | .contains(callingPackage)) { |
| 9927 | throw new SecurityException("Calling package must be configured in the device config. " |
| 9928 | + "calling package: " + callingPackage); |
| 9929 | } |
| 9930 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9931 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9932 | final long identity = Binder.clearCallingIdentity(); |
| 9933 | |
| 9934 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9935 | try { |
| 9936 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9937 | switch (thermalMitigationAction) { |
| 9938 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9939 | thermalMitigationResult = |
| 9940 | handleDataThrottlingRequest(subId, |
| 9941 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 9942 | break; |
| 9943 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9944 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9945 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9946 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9947 | } |
| 9948 | |
| 9949 | // Ensure that radio is on. If not able to power on due to phone being |
| 9950 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 9951 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9952 | thermalMitigationResult = |
| 9953 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9954 | break; |
| 9955 | } |
| 9956 | |
| 9957 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9958 | false); |
| 9959 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9960 | break; |
| 9961 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9962 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9963 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9964 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9965 | } |
| 9966 | |
| 9967 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9968 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9969 | Phone phone = getPhone(subId); |
| 9970 | if (phone == null) { |
| 9971 | thermalMitigationResult = |
| 9972 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9973 | break; |
| 9974 | } |
| 9975 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 9976 | TelephonyConnectionService service = |
| 9977 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 9978 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 9979 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 9980 | thermalMitigationResult = |
| 9981 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 9982 | break; |
| 9983 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9984 | thermalMitigationResult = |
| 9985 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 9986 | break; |
| 9987 | } |
| 9988 | } else { |
| 9989 | thermalMitigationResult = |
| 9990 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9991 | break; |
| 9992 | } |
| 9993 | |
| 9994 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9995 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 9996 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9997 | thermalMitigationResult = |
| 9998 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9999 | break; |
| 10000 | } |
| 10001 | thermalMitigationResult = |
| 10002 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10003 | break; |
| 10004 | default: |
| 10005 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10006 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10007 | } |
| 10008 | } catch (IllegalArgumentException e) { |
| 10009 | throw e; |
| 10010 | } catch (Exception e) { |
| 10011 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10012 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10013 | } finally { |
| 10014 | Binder.restoreCallingIdentity(identity); |
| 10015 | } |
| 10016 | |
| 10017 | if (DBG) { |
| 10018 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10019 | + thermalMitigationResult); |
| 10020 | } |
| 10021 | |
| 10022 | return thermalMitigationResult; |
| 10023 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10024 | |
| 10025 | /** |
| 10026 | * Set the GbaService Package Name that Telephony will bind to. |
| 10027 | * |
| 10028 | * @param subId The sim that the GbaService is associated with. |
| 10029 | * @param packageName The name of the package to be replaced with. |
| 10030 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10031 | */ |
| 10032 | @Override |
| 10033 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10034 | enforceModifyPermission(); |
| 10035 | |
| 10036 | final long identity = Binder.clearCallingIdentity(); |
| 10037 | try { |
| 10038 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10039 | } finally { |
| 10040 | Binder.restoreCallingIdentity(identity); |
| 10041 | } |
| 10042 | } |
| 10043 | |
| 10044 | /** |
| 10045 | * Return the package name of the currently bound GbaService. |
| 10046 | * |
| 10047 | * @param subId The sim that the GbaService is associated with. |
| 10048 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10049 | */ |
| 10050 | @Override |
| 10051 | public String getBoundGbaService(int subId) { |
| 10052 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10053 | |
| 10054 | final long identity = Binder.clearCallingIdentity(); |
| 10055 | try { |
| 10056 | return getGbaManager(subId).getServicePackage(); |
| 10057 | } finally { |
| 10058 | Binder.restoreCallingIdentity(identity); |
| 10059 | } |
| 10060 | } |
| 10061 | |
| 10062 | /** |
| 10063 | * Set the release time for telephony to unbind GbaService. |
| 10064 | * |
| 10065 | * @param subId The sim that the GbaService is associated with. |
| 10066 | * @param interval The release time to unbind GbaService by millisecond. |
| 10067 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10068 | */ |
| 10069 | @Override |
| 10070 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10071 | enforceModifyPermission(); |
| 10072 | |
| 10073 | final long identity = Binder.clearCallingIdentity(); |
| 10074 | try { |
| 10075 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10076 | } finally { |
| 10077 | Binder.restoreCallingIdentity(identity); |
| 10078 | } |
| 10079 | } |
| 10080 | |
| 10081 | /** |
| 10082 | * Return the release time for telephony to unbind GbaService. |
| 10083 | * |
| 10084 | * @param subId The sim that the GbaService is associated with. |
| 10085 | * @return The release time to unbind GbaService by millisecond. |
| 10086 | */ |
| 10087 | @Override |
| 10088 | public int getGbaReleaseTime(int subId) { |
| 10089 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10090 | |
| 10091 | final long identity = Binder.clearCallingIdentity(); |
| 10092 | try { |
| 10093 | return getGbaManager(subId).getReleaseTime(); |
| 10094 | } finally { |
| 10095 | Binder.restoreCallingIdentity(identity); |
| 10096 | } |
| 10097 | } |
| 10098 | |
| 10099 | private GbaManager getGbaManager(int subId) { |
| 10100 | GbaManager instance = GbaManager.getInstance(subId); |
| 10101 | if (instance == null) { |
| 10102 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10103 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10104 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10105 | } |
| 10106 | return instance; |
| 10107 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10108 | |
| 10109 | /** |
| 10110 | * indicate whether the device and the carrier can support |
| 10111 | * RCS VoLTE single registration. |
| 10112 | */ |
| 10113 | @Override |
| 10114 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10115 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10116 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10117 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10118 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10119 | |
| 10120 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10121 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10122 | } |
| 10123 | |
| 10124 | final long identity = Binder.clearCallingIdentity(); |
| 10125 | try { |
| 10126 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10127 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10128 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10129 | if (isCapable != null) { |
| 10130 | return isCapable; |
| 10131 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10132 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10133 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10134 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10135 | } finally { |
| 10136 | Binder.restoreCallingIdentity(identity); |
| 10137 | } |
| 10138 | } |
| 10139 | |
| 10140 | /** |
| 10141 | * Register RCS provisioning callback. |
| 10142 | */ |
| 10143 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10144 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10145 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10146 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10147 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10148 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10149 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10150 | |
| 10151 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10152 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10153 | } |
| 10154 | if (!isImsAvailableOnDevice()) { |
| 10155 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10156 | "IMS not available on device."); |
| 10157 | } |
| 10158 | |
| 10159 | final long identity = Binder.clearCallingIdentity(); |
| 10160 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10161 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10162 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10163 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10164 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10165 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10166 | } finally { |
| 10167 | Binder.restoreCallingIdentity(identity); |
| 10168 | } |
| 10169 | } |
| 10170 | |
| 10171 | /** |
| 10172 | * Unregister RCS provisioning callback. |
| 10173 | */ |
| 10174 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10175 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10176 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10177 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10178 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10179 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10180 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10181 | |
| 10182 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10183 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10184 | } |
| 10185 | if (!isImsAvailableOnDevice()) { |
| 10186 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10187 | "IMS not available on device."); |
| 10188 | } |
| 10189 | |
| 10190 | final long identity = Binder.clearCallingIdentity(); |
| 10191 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10192 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10193 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10194 | } finally { |
| 10195 | Binder.restoreCallingIdentity(identity); |
| 10196 | } |
| 10197 | } |
| 10198 | |
| 10199 | /** |
| 10200 | * trigger RCS reconfiguration. |
| 10201 | */ |
| 10202 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10203 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10204 | "triggerRcsReconfiguration", |
| 10205 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10206 | |
| 10207 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10208 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10209 | } |
| 10210 | if (!isImsAvailableOnDevice()) { |
| 10211 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10212 | "IMS not available on device."); |
| 10213 | } |
| 10214 | |
| 10215 | final long identity = Binder.clearCallingIdentity(); |
| 10216 | try { |
| 10217 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10218 | } finally { |
| 10219 | Binder.restoreCallingIdentity(identity); |
| 10220 | } |
| 10221 | } |
| 10222 | |
| 10223 | /** |
| 10224 | * Provide the client configuration parameters of the RCS application. |
| 10225 | */ |
| 10226 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10227 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10228 | "setRcsClientConfiguration", |
| 10229 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10230 | |
| 10231 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10232 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10233 | } |
| 10234 | if (!isImsAvailableOnDevice()) { |
| 10235 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10236 | "IMS not available on device."); |
| 10237 | } |
| 10238 | |
| 10239 | final long identity = Binder.clearCallingIdentity(); |
| 10240 | |
| 10241 | try { |
| 10242 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10243 | if (configBinder == null) { |
| 10244 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10245 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10246 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10247 | } else { |
| 10248 | configBinder.setRcsClientConfiguration(rcc); |
| 10249 | } |
| 10250 | } catch (RemoteException e) { |
| 10251 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10252 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10253 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10254 | } finally { |
| 10255 | Binder.restoreCallingIdentity(identity); |
| 10256 | } |
| 10257 | } |
| 10258 | |
| 10259 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10260 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10261 | */ |
| 10262 | @Override |
| 10263 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10264 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10265 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10266 | |
| 10267 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10268 | } |
| 10269 | |
| 10270 | /** |
| 10271 | * Gets the test mode for RCS VoLTE single registration. |
| 10272 | */ |
| 10273 | @Override |
| 10274 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10275 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10276 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10277 | |
| 10278 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10279 | } |
| 10280 | |
| 10281 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10282 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10283 | */ |
| 10284 | @Override |
| 10285 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10286 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10287 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10288 | enforceModifyPermission(); |
| 10289 | |
| 10290 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10291 | : Boolean.parseBoolean(enabledStr); |
| 10292 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10293 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10294 | } |
| 10295 | |
| 10296 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10297 | * Sends a device to device communication message. Only usable via shell. |
| 10298 | * @param message message to send. |
| 10299 | * @param value message value. |
| 10300 | */ |
| 10301 | @Override |
| 10302 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10303 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10304 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10305 | enforceModifyPermission(); |
| 10306 | |
| 10307 | final long identity = Binder.clearCallingIdentity(); |
| 10308 | try { |
| 10309 | TelephonyConnectionService service = |
| 10310 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10311 | if (service == null) { |
| 10312 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10313 | return; |
| 10314 | } |
| 10315 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10316 | } finally { |
| 10317 | Binder.restoreCallingIdentity(identity); |
| 10318 | } |
| 10319 | } |
| 10320 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10321 | /** |
| 10322 | * Sets the specified device to device transport active. |
| 10323 | * @param transport The transport to set active. |
| 10324 | */ |
| 10325 | @Override |
| 10326 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10327 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10328 | "setActiveDeviceToDeviceTransport"); |
| 10329 | enforceModifyPermission(); |
| 10330 | |
| 10331 | final long identity = Binder.clearCallingIdentity(); |
| 10332 | try { |
| 10333 | TelephonyConnectionService service = |
| 10334 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10335 | if (service == null) { |
| 10336 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10337 | return; |
| 10338 | } |
| 10339 | service.setActiveDeviceToDeviceTransport(transport); |
| 10340 | } finally { |
| 10341 | Binder.restoreCallingIdentity(identity); |
| 10342 | } |
| 10343 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10344 | |
Tyler Gunn | d457521 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10345 | @Override |
| 10346 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10347 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10348 | "setDeviceToDeviceForceEnabled"); |
| 10349 | |
| 10350 | final long identity = Binder.clearCallingIdentity(); |
| 10351 | try { |
| 10352 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10353 | p -> { |
| 10354 | Phone thePhone = p.getImsPhone(); |
| 10355 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10356 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10357 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10358 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10359 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10360 | (ImsPhoneCallTracker) tracker; |
| 10361 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10362 | } |
| 10363 | } |
| 10364 | } |
| 10365 | ); |
| 10366 | } finally { |
| 10367 | Binder.restoreCallingIdentity(identity); |
| 10368 | } |
| 10369 | } |
| 10370 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10371 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10372 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10373 | */ |
| 10374 | @Override |
| 10375 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10376 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10377 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10378 | } |
| 10379 | |
| 10380 | /** |
| 10381 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10382 | */ |
| 10383 | @Override |
| 10384 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10385 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10386 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10387 | enforceModifyPermission(); |
| 10388 | |
| 10389 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10390 | : Boolean.parseBoolean(enabledStr); |
| 10391 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10392 | subId, enabled); |
| 10393 | } |
| 10394 | |
| 10395 | /** |
| 10396 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10397 | */ |
| 10398 | @Override |
| 10399 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10400 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10401 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10402 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10403 | |
| 10404 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 10405 | * Overrides the ims feature validation result |
| 10406 | */ |
| 10407 | @Override |
| 10408 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 10409 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10410 | "setImsFeatureValidationOverride"); |
| 10411 | |
| 10412 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10413 | : Boolean.parseBoolean(enabledStr); |
| 10414 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 10415 | subId, enabled); |
| 10416 | } |
| 10417 | |
| 10418 | /** |
| 10419 | * Gets the ims feature validation override value |
| 10420 | */ |
| 10421 | @Override |
| 10422 | public boolean getImsFeatureValidationOverride(int subId) { |
| 10423 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10424 | "getImsFeatureValidationOverride"); |
| 10425 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 10426 | } |
| 10427 | |
| 10428 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10429 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10430 | * their mobile plan. |
| 10431 | */ |
| 10432 | @Override |
| 10433 | public String getMobileProvisioningUrl() { |
| 10434 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10435 | final long identity = Binder.clearCallingIdentity(); |
| 10436 | try { |
| 10437 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10438 | } finally { |
| 10439 | Binder.restoreCallingIdentity(identity); |
| 10440 | } |
| 10441 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10442 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10443 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10444 | * Get the EAB contact from the EAB database. |
| 10445 | */ |
| 10446 | @Override |
| 10447 | public String getContactFromEab(String contact) { |
| 10448 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10449 | enforceModifyPermission(); |
| 10450 | final long identity = Binder.clearCallingIdentity(); |
| 10451 | try { |
| 10452 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10453 | } finally { |
| 10454 | Binder.restoreCallingIdentity(identity); |
| 10455 | } |
| 10456 | } |
| 10457 | |
| 10458 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 10459 | * Get the EAB capability from the EAB database. |
| 10460 | */ |
| 10461 | @Override |
| 10462 | public String getCapabilityFromEab(String contact) { |
| 10463 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 10464 | enforceModifyPermission(); |
| 10465 | final long identity = Binder.clearCallingIdentity(); |
| 10466 | try { |
| 10467 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 10468 | } finally { |
| 10469 | Binder.restoreCallingIdentity(identity); |
| 10470 | } |
| 10471 | } |
| 10472 | |
| 10473 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10474 | * Remove the EAB contacts from the EAB database. |
| 10475 | */ |
| 10476 | @Override |
| 10477 | public int removeContactFromEab(int subId, String contacts) { |
| 10478 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10479 | enforceModifyPermission(); |
| 10480 | final long identity = Binder.clearCallingIdentity(); |
| 10481 | try { |
| 10482 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10483 | } finally { |
| 10484 | Binder.restoreCallingIdentity(identity); |
| 10485 | } |
| 10486 | } |
| 10487 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10488 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10489 | public boolean getDeviceUceEnabled() { |
| 10490 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10491 | final long identity = Binder.clearCallingIdentity(); |
| 10492 | try { |
| 10493 | return mApp.getDeviceUceEnabled(); |
| 10494 | } finally { |
| 10495 | Binder.restoreCallingIdentity(identity); |
| 10496 | } |
| 10497 | } |
| 10498 | |
| 10499 | @Override |
| 10500 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10501 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10502 | final long identity = Binder.clearCallingIdentity(); |
| 10503 | try { |
| 10504 | mApp.setDeviceUceEnabled(isEnabled); |
| 10505 | } finally { |
| 10506 | Binder.restoreCallingIdentity(identity); |
| 10507 | } |
| 10508 | } |
| 10509 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10510 | /** |
| 10511 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10512 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10513 | */ |
| 10514 | // Used for SHELL command only right now. |
| 10515 | @Override |
| 10516 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 10517 | List<String> featureTags) { |
| 10518 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10519 | "addUceRegistrationOverrideShell"); |
| 10520 | final long identity = Binder.clearCallingIdentity(); |
| 10521 | try { |
| 10522 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 10523 | new ArraySet<>(featureTags)); |
| 10524 | } catch (ImsException e) { |
| 10525 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10526 | } finally { |
| 10527 | Binder.restoreCallingIdentity(identity); |
| 10528 | } |
| 10529 | } |
| 10530 | |
| 10531 | /** |
| 10532 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10533 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10534 | */ |
| 10535 | // Used for SHELL command only right now. |
| 10536 | @Override |
| 10537 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 10538 | List<String> featureTags) { |
| 10539 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10540 | "removeUceRegistrationOverrideShell"); |
| 10541 | final long identity = Binder.clearCallingIdentity(); |
| 10542 | try { |
| 10543 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 10544 | new ArraySet<>(featureTags)); |
| 10545 | } catch (ImsException e) { |
| 10546 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10547 | } finally { |
| 10548 | Binder.restoreCallingIdentity(identity); |
| 10549 | } |
| 10550 | } |
| 10551 | |
| 10552 | /** |
| 10553 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 10554 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10555 | */ |
| 10556 | // Used for SHELL command only right now. |
| 10557 | @Override |
| 10558 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 10559 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10560 | "clearUceRegistrationOverrideShell"); |
| 10561 | final long identity = Binder.clearCallingIdentity(); |
| 10562 | try { |
| 10563 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 10564 | } catch (ImsException e) { |
| 10565 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10566 | } finally { |
| 10567 | Binder.restoreCallingIdentity(identity); |
| 10568 | } |
| 10569 | } |
| 10570 | |
| 10571 | /** |
| 10572 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10573 | */ |
| 10574 | // Used for SHELL command only right now. |
| 10575 | @Override |
| 10576 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 10577 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10578 | "getLatestRcsContactUceCapabilityShell"); |
| 10579 | final long identity = Binder.clearCallingIdentity(); |
| 10580 | try { |
| 10581 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 10582 | } catch (ImsException e) { |
| 10583 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10584 | } finally { |
| 10585 | Binder.restoreCallingIdentity(identity); |
| 10586 | } |
| 10587 | } |
| 10588 | |
| 10589 | /** |
| 10590 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 10591 | * device does not have an active PUBLISH. |
| 10592 | */ |
| 10593 | // Used for SHELL command only right now. |
| 10594 | @Override |
| 10595 | public String getLastUcePidfXmlShell(int subId) { |
| 10596 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 10597 | final long identity = Binder.clearCallingIdentity(); |
| 10598 | try { |
| 10599 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 10600 | } catch (ImsException e) { |
| 10601 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10602 | } finally { |
| 10603 | Binder.restoreCallingIdentity(identity); |
| 10604 | } |
| 10605 | } |
| 10606 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 10607 | /** |
| 10608 | * Remove UCE requests cannot be sent to the network status. |
| 10609 | */ |
| 10610 | // Used for SHELL command only right now. |
| 10611 | @Override |
| 10612 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 10613 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 10614 | final long identity = Binder.clearCallingIdentity(); |
| 10615 | try { |
| 10616 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 10617 | } catch (ImsException e) { |
| 10618 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10619 | } finally { |
| 10620 | Binder.restoreCallingIdentity(identity); |
| 10621 | } |
| 10622 | } |
| 10623 | |
James.cf Lin | 0fc71b0 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 10624 | /** |
| 10625 | * Remove UCE requests cannot be sent to the network status. |
| 10626 | */ |
| 10627 | // Used for SHELL command only. |
| 10628 | @Override |
| 10629 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 10630 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 10631 | final long identity = Binder.clearCallingIdentity(); |
| 10632 | try { |
| 10633 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 10634 | } catch (ImsException e) { |
| 10635 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10636 | } finally { |
| 10637 | Binder.restoreCallingIdentity(identity); |
| 10638 | } |
| 10639 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10640 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10641 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10642 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10643 | String callingPackage) { |
| 10644 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10645 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 10646 | |
| 10647 | final int callingUid = Binder.getCallingUid(); |
| 10648 | // Verify that tha callingPackage belongs to the calling UID |
| 10649 | mApp.getSystemService(AppOpsManager.class) |
| 10650 | .checkPackage(callingUid, callingPackage); |
| 10651 | |
| 10652 | validateSignalStrengthUpdateRequest(request, callingUid); |
| 10653 | |
| 10654 | final long identity = Binder.clearCallingIdentity(); |
| 10655 | try { |
| 10656 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10657 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10658 | |
| 10659 | if (result instanceof IllegalStateException) { |
| 10660 | throw (IllegalStateException) result; |
| 10661 | } |
| 10662 | } finally { |
| 10663 | Binder.restoreCallingIdentity(identity); |
| 10664 | } |
| 10665 | } |
| 10666 | |
| 10667 | @Override |
| 10668 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10669 | String callingPackage) { |
| 10670 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10671 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 10672 | |
| 10673 | final int callingUid = Binder.getCallingUid(); |
| 10674 | // Verify that tha callingPackage belongs to the calling UID |
| 10675 | mApp.getSystemService(AppOpsManager.class) |
| 10676 | .checkPackage(callingUid, callingPackage); |
| 10677 | |
| 10678 | final long identity = Binder.clearCallingIdentity(); |
| 10679 | try { |
| 10680 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10681 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10682 | |
| 10683 | if (result instanceof IllegalStateException) { |
| 10684 | throw (IllegalStateException) result; |
| 10685 | } |
| 10686 | } finally { |
| 10687 | Binder.restoreCallingIdentity(identity); |
| 10688 | } |
| 10689 | } |
| 10690 | |
| 10691 | private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request, |
| 10692 | int callingUid) { |
| 10693 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 10694 | // phone/system process do not have further restriction on request |
| 10695 | return; |
| 10696 | } |
| 10697 | |
| 10698 | // Applications has restrictions on how to use the request: |
| 10699 | // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle |
| 10700 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
| 10701 | // This is not system caller which has been checked above |
| 10702 | throw new IllegalArgumentException( |
| 10703 | "Only system can set isSystemThresholdReportingRequestedWhileIdle"); |
| 10704 | } |
| 10705 | |
| 10706 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 10707 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 10708 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 10709 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 10710 | || info.isEnabled()) { |
| 10711 | throw new IllegalArgumentException( |
| 10712 | "Only system can set hide fields in SignalThresholdInfo"); |
| 10713 | } |
| 10714 | |
| 10715 | // Thresholds length for each RAN need in range. This has been validated in |
| 10716 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 10717 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 10718 | final int[] thresholds = info.getThresholds(); |
| 10719 | Objects.requireNonNull(thresholds); |
| 10720 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 10721 | || thresholds.length |
| 10722 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 10723 | throw new IllegalArgumentException( |
| 10724 | "thresholds length is out of range: " + thresholds.length); |
| 10725 | } |
| 10726 | } |
| 10727 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10728 | |
| 10729 | /** |
| 10730 | * Gets the current phone capability. |
| 10731 | * |
| 10732 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 10733 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 10734 | * It's used to evaluate possible phone config change, for example from single |
| 10735 | * SIM device to multi-SIM device. |
| 10736 | */ |
| 10737 | @Override |
| 10738 | public PhoneCapability getPhoneCapability() { |
| 10739 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 10740 | final long identity = Binder.clearCallingIdentity(); |
| 10741 | try { |
| 10742 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 10743 | } finally { |
| 10744 | Binder.restoreCallingIdentity(identity); |
| 10745 | } |
| 10746 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 10747 | |
| 10748 | /** |
| 10749 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 10750 | * required to be done shortly after the API is invoked. |
| 10751 | */ |
| 10752 | @Override |
| 10753 | @TelephonyManager.PrepareUnattendedRebootResult |
| 10754 | public int prepareForUnattendedReboot() { |
| 10755 | enforceRebootPermission(); |
| 10756 | |
| 10757 | final long identity = Binder.clearCallingIdentity(); |
| 10758 | try { |
| 10759 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null); |
| 10760 | } finally { |
| 10761 | Binder.restoreCallingIdentity(identity); |
| 10762 | } |
| 10763 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 10764 | |
| 10765 | /** |
| 10766 | * Request to get the current slicing configuration including URSP rules and |
| 10767 | * NSSAIs (configured, allowed and rejected). |
| 10768 | * |
| 10769 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 10770 | */ |
| 10771 | @Override |
| 10772 | public void getSlicingConfig(ResultReceiver callback) { |
| 10773 | enforceReadPrivilegedPermission("getSlicingConfig"); |
| 10774 | |
| 10775 | final long identity = Binder.clearCallingIdentity(); |
| 10776 | try { |
| 10777 | Phone phone = getDefaultPhone(); |
| 10778 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 10779 | } finally { |
| 10780 | Binder.restoreCallingIdentity(identity); |
| 10781 | } |
| 10782 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 10783 | } |