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; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 25 | import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 26 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 27 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 28 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 29 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 30 | import android.annotation.Nullable; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 31 | import android.annotation.RequiresPermission; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 32 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 33 | import android.app.PendingIntent; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 34 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 35 | import android.app.role.RoleManager; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 36 | import android.compat.annotation.ChangeId; |
| 37 | import android.compat.annotation.EnabledSince; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 38 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 39 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 40 | import android.content.Context; |
| 41 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 42 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 43 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 44 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 45 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 46 | import android.net.Uri; |
| 47 | import android.os.AsyncResult; |
| 48 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 49 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 50 | import android.os.Bundle; |
| 51 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 52 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import android.os.Looper; |
| 54 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 55 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 56 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 57 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 58 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 59 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 60 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 61 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 62 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 63 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 64 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 65 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 66 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 67 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 68 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 69 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 70 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 71 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 72 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 73 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 74 | import android.telecom.TelecomManager; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 75 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 76 | import android.telephony.Annotation.ThermalMitigationResult; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 77 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 78 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 79 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 80 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 81 | import android.telephony.CellIdentityCdma; |
| 82 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 83 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 84 | import android.telephony.CellInfoGsm; |
| 85 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 86 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 87 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 88 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 89 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 90 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 91 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 92 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 93 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 94 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 95 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 96 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 97 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 98 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 99 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 100 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 101 | import android.telephony.SignalStrengthUpdateRequest; |
| 102 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 103 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 104 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 105 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 106 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 107 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 108 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 109 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 110 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 111 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 112 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 113 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 114 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 115 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 116 | import android.telephony.data.ApnSetting; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 117 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 118 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 119 | import android.telephony.gba.GbaAuthRequest; |
| 120 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 121 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 122 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 123 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 124 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 125 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 126 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 127 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 128 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 129 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 130 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 131 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 132 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 133 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 134 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 135 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 136 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 137 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 138 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 139 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 140 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 141 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 142 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 143 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 144 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 145 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 146 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 147 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.CallTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 157 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 161 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 163 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 165 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 166 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 176 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 177 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 179 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 181 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 182 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 183 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 185 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 187 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 188 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 189 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 190 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 191 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 192 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 193 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 194 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 195 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 196 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 197 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 198 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 199 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 200 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 201 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 202 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 203 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 204 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 205 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 206 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 207 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 208 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 209 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 210 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 211 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 212 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 213 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 214 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 215 | import com.android.services.telephony.TelecomAccountRegistry; |
| 216 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 217 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 218 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 219 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 220 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 221 | import java.io.IOException; |
| 222 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 223 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 224 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 225 | import java.util.Arrays; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 226 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 227 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 228 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 229 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 230 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 231 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 232 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 233 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 234 | import java.util.Set; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 235 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 236 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 237 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 238 | |
| 239 | /** |
| 240 | * Implementation of the ITelephony interface. |
| 241 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 242 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 243 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 244 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 245 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 246 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 247 | |
| 248 | // Message codes used with mMainThreadHandler |
| 249 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 250 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 251 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 252 | private static final int CMD_OPEN_CHANNEL = 9; |
| 253 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 254 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 255 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 256 | private static final int CMD_NV_READ_ITEM = 13; |
| 257 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 258 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 259 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 260 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 261 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 262 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 263 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 264 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 265 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 266 | private static final int CMD_SEND_ENVELOPE = 25; |
| 267 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 268 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 269 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 270 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 271 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 272 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 273 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 274 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 275 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 276 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 277 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 278 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 279 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 280 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 281 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 282 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 283 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 284 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 285 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 286 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 287 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 288 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 289 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 290 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 291 | private static final int CMD_SWITCH_SLOTS = 50; |
| 292 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 293 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 294 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 295 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 296 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 297 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 298 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 299 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 300 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 301 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 302 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 303 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 304 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 305 | private static final int CMD_MODEM_REBOOT = 64; |
| 306 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 307 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 308 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 309 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 310 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 311 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 312 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 313 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 314 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 315 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 316 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 317 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 318 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 319 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 320 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 321 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 322 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 323 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 324 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 325 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 326 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 327 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 328 | private static final int CMD_GET_CALL_WAITING = 87; |
| 329 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 330 | private static final int CMD_SET_CALL_WAITING = 89; |
| 331 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 332 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 333 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 334 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 335 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 336 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 337 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 338 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 339 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 340 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 341 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 342 | private static final int CMD_SET_SIM_POWER = 101; |
| 343 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 344 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 345 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 346 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 347 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 348 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 349 | 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] | 350 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 351 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 352 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 353 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 354 | private static final int CMD_ENABLE_VONR = 113; |
| 355 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 356 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 357 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 358 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 359 | // Parameters of select command. |
| 360 | private static final int SELECT_COMMAND = 0xA4; |
| 361 | private static final int SELECT_P1 = 0x04; |
| 362 | private static final int SELECT_P2 = 0; |
| 363 | private static final int SELECT_P3 = 0x10; |
| 364 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 365 | /** The singleton instance. */ |
| 366 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 367 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 368 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 369 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 370 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 371 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 372 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 373 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 374 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 375 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 376 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 377 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 378 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 379 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 380 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 381 | /** User Activity */ |
| 382 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 383 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 384 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 385 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 386 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 387 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 388 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 389 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 390 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 391 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 392 | // String to store multi SIM allowed |
| 393 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 394 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 395 | // The AID of ISD-R. |
| 396 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 397 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 398 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 399 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 400 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 401 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 402 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 403 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 404 | 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] | 405 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 406 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 407 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 408 | */ |
| 409 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 410 | "reset_network_erase_modem_config_enabled"; |
| 411 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 412 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 413 | /** |
| 414 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 415 | * one ICCID active at the same time. |
| 416 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 417 | * |
| 418 | * @hide |
| 419 | */ |
| 420 | @ChangeId |
| 421 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 422 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 423 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 424 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 425 | * A request object to use for transmitting data to an ICC. |
| 426 | */ |
| 427 | private static final class IccAPDUArgument { |
| 428 | public int channel, cla, command, p1, p2, p3; |
| 429 | public String data; |
| 430 | |
| 431 | public IccAPDUArgument(int channel, int cla, int command, |
| 432 | int p1, int p2, int p3, String data) { |
| 433 | this.channel = channel; |
| 434 | this.cla = cla; |
| 435 | this.command = command; |
| 436 | this.p1 = p1; |
| 437 | this.p2 = p2; |
| 438 | this.p3 = p3; |
| 439 | this.data = data; |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 444 | * A request object to use for transmitting data to an ICC. |
| 445 | */ |
| 446 | private static final class ManualNetworkSelectionArgument { |
| 447 | public OperatorInfo operatorInfo; |
| 448 | public boolean persistSelection; |
| 449 | |
| 450 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 451 | this.operatorInfo = operatorInfo; |
| 452 | this.persistSelection = persistSelection; |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 457 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 458 | * request after sending. The main thread will notify the request when it is complete. |
| 459 | */ |
| 460 | private static final class MainThreadRequest { |
| 461 | /** The argument to use for the request */ |
| 462 | public Object argument; |
| 463 | /** The result of the request that is run on the main thread */ |
| 464 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 465 | // The subscriber id that this request applies to. Defaults to |
| 466 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 467 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 468 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 469 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 470 | public Phone phone; |
| 471 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 472 | public WorkSource workSource; |
| 473 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 474 | public MainThreadRequest(Object argument) { |
| 475 | this.argument = argument; |
| 476 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 477 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 478 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 479 | this.argument = argument; |
| 480 | if (phone != null) { |
| 481 | this.phone = phone; |
| 482 | } |
| 483 | this.workSource = workSource; |
| 484 | } |
| 485 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 486 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 487 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 488 | if (subId != null) { |
| 489 | this.subId = subId; |
| 490 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 491 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 492 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 493 | } |
| 494 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 495 | private static final class IncomingThirdPartyCallArgs { |
| 496 | public final ComponentName component; |
| 497 | public final String callId; |
| 498 | public final String callerDisplayName; |
| 499 | |
| 500 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 501 | String callerDisplayName) { |
| 502 | this.component = component; |
| 503 | this.callId = callId; |
| 504 | this.callerDisplayName = callerDisplayName; |
| 505 | } |
| 506 | } |
| 507 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 508 | /** |
| 509 | * A handler that processes messages on the main thread in the phone process. Since many |
| 510 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 511 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 512 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 513 | * on, which will be notified when the operation completes and will contain the result of the |
| 514 | * request. |
| 515 | * |
| 516 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 517 | * note that request.result must be set to something non-null for the calling thread to |
| 518 | * unblock. |
| 519 | */ |
| 520 | private final class MainThreadHandler extends Handler { |
| 521 | @Override |
| 522 | public void handleMessage(Message msg) { |
| 523 | MainThreadRequest request; |
| 524 | Message onCompleted; |
| 525 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 526 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 527 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 528 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 529 | |
| 530 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 531 | case CMD_HANDLE_USSD_REQUEST: { |
| 532 | request = (MainThreadRequest) msg.obj; |
| 533 | final Phone phone = getPhoneFromRequest(request); |
| 534 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 535 | String ussdRequest = ussdObject.first; |
| 536 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 537 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 538 | if (!isUssdApiAllowed(request.subId)) { |
| 539 | // Carrier does not support use of this API, return failure. |
| 540 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 541 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 542 | Bundle returnData = new Bundle(); |
| 543 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 544 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 545 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 546 | request.result = true; |
| 547 | notifyRequester(request); |
| 548 | return; |
| 549 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 550 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 551 | try { |
| 552 | request.result = phone != null |
| 553 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 554 | } catch (CallStateException cse) { |
| 555 | request.result = false; |
| 556 | } |
| 557 | // Wake up the requesting thread |
| 558 | notifyRequester(request); |
| 559 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 560 | } |
| 561 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 562 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 563 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 564 | final Phone phone = getPhoneFromRequest(request); |
| 565 | request.result = phone != null ? |
| 566 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 567 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 568 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 569 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 570 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 571 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 572 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 573 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 574 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 575 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 576 | uiccPort = getUiccPortFromRequest(request); |
| 577 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 578 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 579 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 580 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 581 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 582 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 583 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 584 | uiccPort.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 585 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 586 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 587 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 588 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 589 | break; |
| 590 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 591 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 592 | ar = (AsyncResult) msg.obj; |
| 593 | request = (MainThreadRequest) ar.userObj; |
| 594 | if (ar.exception == null && ar.result != null) { |
| 595 | request.result = ar.result; |
| 596 | } else { |
| 597 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 598 | if (ar.result == null) { |
| 599 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 600 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 601 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 602 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 603 | } else { |
| 604 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 605 | } |
| 606 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 607 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 608 | break; |
| 609 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 610 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 611 | request = (MainThreadRequest) msg.obj; |
| 612 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 613 | uiccPort = getUiccPortFromRequest(request); |
| 614 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 615 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 616 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 617 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 618 | } else { |
| 619 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 620 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 621 | uiccPort.iccTransmitApduBasicChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 622 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 623 | iccArgument.p3, iccArgument.data, onCompleted); |
| 624 | } |
| 625 | break; |
| 626 | |
| 627 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 628 | ar = (AsyncResult) msg.obj; |
| 629 | request = (MainThreadRequest) ar.userObj; |
| 630 | if (ar.exception == null && ar.result != null) { |
| 631 | request.result = ar.result; |
| 632 | } else { |
| 633 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 634 | if (ar.result == null) { |
| 635 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 636 | } else if (ar.exception instanceof CommandException) { |
| 637 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 638 | ar.exception); |
| 639 | } else { |
| 640 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 641 | } |
| 642 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 643 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 644 | break; |
| 645 | |
| 646 | case CMD_EXCHANGE_SIM_IO: |
| 647 | request = (MainThreadRequest) msg.obj; |
| 648 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 649 | uiccPort = getUiccPortFromRequest(request); |
| 650 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 651 | loge("iccExchangeSimIO: No UICC"); |
| 652 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 653 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 654 | } else { |
| 655 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 656 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 657 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 658 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 659 | iccArgument.data, onCompleted); |
| 660 | } |
| 661 | break; |
| 662 | |
| 663 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 664 | ar = (AsyncResult) msg.obj; |
| 665 | request = (MainThreadRequest) ar.userObj; |
| 666 | if (ar.exception == null && ar.result != null) { |
| 667 | request.result = ar.result; |
| 668 | } else { |
| 669 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 670 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 671 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 672 | break; |
| 673 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 674 | case CMD_SEND_ENVELOPE: |
| 675 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 676 | uiccPort = getUiccPortFromRequest(request); |
| 677 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 678 | loge("sendEnvelopeWithStatus: No UICC"); |
| 679 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 680 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 681 | } else { |
| 682 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 683 | uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 684 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 685 | break; |
| 686 | |
| 687 | case EVENT_SEND_ENVELOPE_DONE: |
| 688 | ar = (AsyncResult) msg.obj; |
| 689 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 690 | if (ar.exception == null && ar.result != null) { |
| 691 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 692 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 693 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 694 | if (ar.result == null) { |
| 695 | loge("sendEnvelopeWithStatus: Empty response"); |
| 696 | } else if (ar.exception instanceof CommandException) { |
| 697 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 698 | ar.exception); |
| 699 | } else { |
| 700 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 701 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 702 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 703 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 704 | break; |
| 705 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 706 | case CMD_OPEN_CHANNEL: |
| 707 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 708 | uiccPort = getUiccPortFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 709 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 710 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 711 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 712 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 713 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 714 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 715 | } else { |
| 716 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 717 | uiccPort.iccOpenLogicalChannel(openChannelArgs.first, |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 718 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 719 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 720 | break; |
| 721 | |
| 722 | case EVENT_OPEN_CHANNEL_DONE: |
| 723 | ar = (AsyncResult) msg.obj; |
| 724 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 725 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 726 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 727 | int[] result = (int[]) ar.result; |
| 728 | int channelId = result[0]; |
| 729 | byte[] selectResponse = null; |
| 730 | if (result.length > 1) { |
| 731 | selectResponse = new byte[result.length - 1]; |
| 732 | for (int i = 1; i < result.length; ++i) { |
| 733 | selectResponse[i - 1] = (byte) result[i]; |
| 734 | } |
| 735 | } |
| 736 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 737 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 738 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 739 | if (ar.result == null) { |
| 740 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 741 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 742 | if (ar.exception != null) { |
| 743 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 744 | } |
| 745 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 746 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 747 | if (ar.exception instanceof CommandException) { |
| 748 | CommandException.Error error = |
| 749 | ((CommandException) (ar.exception)).getCommandError(); |
| 750 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 751 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 752 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 753 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 754 | } |
| 755 | } |
| 756 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 757 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 758 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 759 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 760 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 761 | break; |
| 762 | |
| 763 | case CMD_CLOSE_CHANNEL: |
| 764 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 765 | uiccPort = getUiccPortFromRequest(request); |
| 766 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 767 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 768 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 769 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 770 | } else { |
| 771 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 772 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 773 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 774 | break; |
| 775 | |
| 776 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 777 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 778 | break; |
| 779 | |
| 780 | case CMD_NV_READ_ITEM: |
| 781 | request = (MainThreadRequest) msg.obj; |
| 782 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 783 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 784 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 785 | break; |
| 786 | |
| 787 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 788 | ar = (AsyncResult) msg.obj; |
| 789 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 790 | if (ar.exception == null && ar.result != null) { |
| 791 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 792 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 793 | request.result = ""; |
| 794 | if (ar.result == null) { |
| 795 | loge("nvReadItem: Empty response"); |
| 796 | } else if (ar.exception instanceof CommandException) { |
| 797 | loge("nvReadItem: CommandException: " + |
| 798 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 799 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 800 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 801 | } |
| 802 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 803 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 804 | break; |
| 805 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 806 | case CMD_NV_WRITE_ITEM: |
| 807 | request = (MainThreadRequest) msg.obj; |
| 808 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 809 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 810 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 811 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 812 | break; |
| 813 | |
| 814 | case EVENT_NV_WRITE_ITEM_DONE: |
| 815 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 816 | break; |
| 817 | |
| 818 | case CMD_NV_WRITE_CDMA_PRL: |
| 819 | request = (MainThreadRequest) msg.obj; |
| 820 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 821 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 822 | break; |
| 823 | |
| 824 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 825 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 826 | break; |
| 827 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 828 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 829 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 830 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 831 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 832 | break; |
| 833 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 834 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 835 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 836 | break; |
| 837 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 838 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 839 | request = (MainThreadRequest) msg.obj; |
| 840 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 841 | request); |
| 842 | Phone phone = getPhoneFromRequest(request); |
| 843 | if (phone != null) { |
| 844 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 845 | } else { |
| 846 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 847 | request.result = false; |
| 848 | notifyRequester(request); |
| 849 | } |
| 850 | break; |
| 851 | } |
| 852 | |
| 853 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 854 | ar = (AsyncResult) msg.obj; |
| 855 | request = (MainThreadRequest) ar.userObj; |
| 856 | if (ar.exception == null && ar.result != null) { |
| 857 | request.result = ar.result; |
| 858 | } else { |
| 859 | // request.result must be set to something non-null |
| 860 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 861 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 862 | request.result = ar.result; |
| 863 | } else { |
| 864 | request.result = false; |
| 865 | } |
| 866 | if (ar.result == null) { |
| 867 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 868 | } else if (ar.exception instanceof CommandException) { |
| 869 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 870 | + ar.exception); |
| 871 | } else { |
| 872 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 873 | } |
| 874 | } |
| 875 | notifyRequester(request); |
| 876 | break; |
| 877 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 878 | case CMD_IS_VONR_ENABLED: { |
| 879 | request = (MainThreadRequest) msg.obj; |
| 880 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 881 | request); |
| 882 | Phone phone = getPhoneFromRequest(request); |
| 883 | if (phone != null) { |
| 884 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 885 | } else { |
| 886 | loge("isVoNrEnabled: No phone object"); |
| 887 | request.result = false; |
| 888 | notifyRequester(request); |
| 889 | } |
| 890 | break; |
| 891 | } |
| 892 | |
| 893 | case EVENT_IS_VONR_ENABLED_DONE: |
| 894 | ar = (AsyncResult) msg.obj; |
| 895 | request = (MainThreadRequest) ar.userObj; |
| 896 | if (ar.exception == null && ar.result != null) { |
| 897 | request.result = ar.result; |
| 898 | } else { |
| 899 | // request.result must be set to something non-null |
| 900 | // for the calling thread to unblock |
| 901 | if (ar.result != null) { |
| 902 | request.result = ar.result; |
| 903 | } else { |
| 904 | request.result = false; |
| 905 | } |
| 906 | if (ar.result == null) { |
| 907 | loge("isVoNrEnabled: Empty response"); |
| 908 | } else if (ar.exception instanceof CommandException) { |
| 909 | loge("isVoNrEnabled: CommandException: " |
| 910 | + ar.exception); |
| 911 | } else { |
| 912 | loge("isVoNrEnabled: Unknown exception"); |
| 913 | } |
| 914 | } |
| 915 | notifyRequester(request); |
| 916 | break; |
| 917 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 918 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 919 | request = (MainThreadRequest) msg.obj; |
| 920 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 921 | Phone phone = getPhoneFromRequest(request); |
| 922 | if (phone != null) { |
| 923 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 924 | request.workSource); |
| 925 | } else { |
| 926 | loge("enableNrDualConnectivity: No phone object"); |
| 927 | request.result = |
| 928 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 929 | notifyRequester(request); |
| 930 | } |
| 931 | break; |
| 932 | } |
| 933 | |
| 934 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 935 | ar = (AsyncResult) msg.obj; |
| 936 | request = (MainThreadRequest) ar.userObj; |
| 937 | if (ar.exception == null) { |
| 938 | request.result = |
| 939 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 940 | } else { |
| 941 | request.result = |
| 942 | TelephonyManager |
| 943 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 944 | if (ar.exception instanceof CommandException) { |
| 945 | CommandException.Error error = |
| 946 | ((CommandException) (ar.exception)).getCommandError(); |
| 947 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 948 | request.result = |
| 949 | TelephonyManager |
| 950 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 951 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 952 | request.result = |
| 953 | TelephonyManager |
| 954 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 955 | } |
| 956 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 957 | + ar.exception); |
| 958 | } else { |
| 959 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 960 | } |
| 961 | } |
| 962 | notifyRequester(request); |
| 963 | break; |
| 964 | } |
| 965 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 966 | case CMD_ENABLE_VONR: { |
| 967 | request = (MainThreadRequest) msg.obj; |
| 968 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 969 | Phone phone = getPhoneFromRequest(request); |
| 970 | if (phone != null) { |
| 971 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 972 | request.workSource); |
| 973 | } else { |
| 974 | loge("setVoNrEnabled: No phone object"); |
| 975 | request.result = |
| 976 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 977 | notifyRequester(request); |
| 978 | } |
| 979 | break; |
| 980 | } |
| 981 | |
| 982 | case EVENT_ENABLE_VONR_DONE: { |
| 983 | ar = (AsyncResult) msg.obj; |
| 984 | request = (MainThreadRequest) ar.userObj; |
| 985 | if (ar.exception == null) { |
| 986 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 987 | } else { |
| 988 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 989 | if (ar.exception instanceof CommandException) { |
| 990 | CommandException.Error error = |
| 991 | ((CommandException) (ar.exception)).getCommandError(); |
| 992 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 993 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 994 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 995 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 996 | } else { |
| 997 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 998 | } |
| 999 | loge("setVoNrEnabled" + ": CommandException: " |
| 1000 | + ar.exception); |
| 1001 | } else { |
| 1002 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1003 | } |
| 1004 | } |
| 1005 | notifyRequester(request); |
| 1006 | break; |
| 1007 | } |
| 1008 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1009 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1010 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1011 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1012 | request); |
| 1013 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1014 | break; |
| 1015 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1016 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1017 | ar = (AsyncResult) msg.obj; |
| 1018 | request = (MainThreadRequest) ar.userObj; |
| 1019 | if (ar.exception == null && ar.result != null) { |
| 1020 | request.result = ar.result; // Integer |
| 1021 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1022 | // request.result must be set to something non-null |
| 1023 | // for the calling thread to unblock |
| 1024 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1025 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1026 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1027 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1028 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1029 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1030 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1031 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1032 | } |
| 1033 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1034 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1035 | break; |
| 1036 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1037 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1038 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1039 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1040 | request); |
| 1041 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1042 | (Pair<Integer, Long>) request.argument; |
| 1043 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1044 | reasonWithNetworkTypes.first, |
| 1045 | reasonWithNetworkTypes.second, |
| 1046 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1047 | break; |
| 1048 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1049 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1050 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1051 | break; |
| 1052 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1053 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1054 | request = (MainThreadRequest)msg.obj; |
| 1055 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1056 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1057 | break; |
| 1058 | |
| 1059 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1060 | ar = (AsyncResult)msg.obj; |
| 1061 | request = (MainThreadRequest)ar.userObj; |
| 1062 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1063 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1064 | break; |
| 1065 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1066 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1067 | request = (MainThreadRequest) msg.obj; |
| 1068 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1069 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1070 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1071 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1072 | break; |
| 1073 | |
| 1074 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1075 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1076 | break; |
| 1077 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1078 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1079 | request = (MainThreadRequest) msg.obj; |
| 1080 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1081 | request); |
| 1082 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1083 | break; |
| 1084 | |
| 1085 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1086 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1087 | break; |
| 1088 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1089 | case CMD_PERFORM_NETWORK_SCAN: |
| 1090 | request = (MainThreadRequest) msg.obj; |
| 1091 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1092 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1093 | break; |
| 1094 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1095 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1096 | request = (MainThreadRequest) msg.obj; |
| 1097 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1098 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1099 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1100 | request.argument; |
| 1101 | int callForwardingReason = args.first; |
| 1102 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1103 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1104 | } |
| 1105 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1106 | ar = (AsyncResult) msg.obj; |
| 1107 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1108 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1109 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1110 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1111 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1112 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1113 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1114 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1115 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1116 | // any service for voice call. |
| 1117 | if ((callForwardInfo.serviceClass |
| 1118 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1119 | callForwardingInfo = new CallForwardingInfo( |
| 1120 | callForwardInfo.status |
| 1121 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1122 | callForwardInfo.reason, |
| 1123 | callForwardInfo.number, |
| 1124 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1125 | break; |
| 1126 | } |
| 1127 | } |
| 1128 | // Didn't find a call forward info for voice call. |
| 1129 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1130 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1131 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1132 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1133 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1134 | } else { |
| 1135 | if (ar.result == null) { |
| 1136 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1137 | } |
| 1138 | if (ar.exception != null) { |
| 1139 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1140 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1141 | int errorCode = TelephonyManager |
| 1142 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1143 | if (ar.exception instanceof CommandException) { |
| 1144 | CommandException.Error error = |
| 1145 | ((CommandException) (ar.exception)).getCommandError(); |
| 1146 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1147 | errorCode = TelephonyManager |
| 1148 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1149 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1150 | errorCode = TelephonyManager |
| 1151 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1152 | } |
| 1153 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1154 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1155 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1156 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1157 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1158 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1159 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1160 | request = (MainThreadRequest) msg.obj; |
| 1161 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1162 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1163 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1164 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1165 | request.argument).first; |
| 1166 | request.phone.setCallForwardingOption( |
| 1167 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1168 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1169 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1170 | callForwardingInfoToSet.getReason(), |
| 1171 | callForwardingInfoToSet.getNumber(), |
| 1172 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1173 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1174 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1175 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1176 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1177 | ar = (AsyncResult) msg.obj; |
| 1178 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1179 | Consumer<Integer> callback = |
| 1180 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1181 | request.argument).second; |
| 1182 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1183 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1184 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1185 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1186 | if (ar.exception instanceof CommandException) { |
| 1187 | CommandException.Error error = |
| 1188 | ((CommandException) (ar.exception)).getCommandError(); |
| 1189 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1190 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1191 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1192 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1193 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1194 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1195 | } |
| 1196 | } |
| 1197 | callback.accept(errorCode); |
| 1198 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1199 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1200 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1201 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1202 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1203 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1204 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1205 | request = (MainThreadRequest) msg.obj; |
| 1206 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1207 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1208 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1209 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1210 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1211 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1212 | ar = (AsyncResult) msg.obj; |
| 1213 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1214 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1215 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1216 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1217 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1218 | // Service Class is a bit mask per 3gpp 27.007. |
| 1219 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1220 | if (callForwardResults.length > 1 |
| 1221 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1222 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1223 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1224 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1225 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1226 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1227 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1228 | } |
| 1229 | } else { |
| 1230 | if (ar.result == null) { |
| 1231 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1232 | } |
| 1233 | if (ar.exception != null) { |
| 1234 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1235 | } |
| 1236 | if (ar.exception instanceof CommandException) { |
| 1237 | CommandException.Error error = |
| 1238 | ((CommandException) (ar.exception)).getCommandError(); |
| 1239 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1240 | callForwardingStatus = |
| 1241 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1242 | } |
| 1243 | } |
| 1244 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1245 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1246 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1247 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1248 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1249 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1250 | request = (MainThreadRequest) msg.obj; |
| 1251 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1252 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1253 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1254 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1255 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1256 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1257 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1258 | ar = (AsyncResult) msg.obj; |
| 1259 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1260 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1261 | Consumer<Integer> callback = |
| 1262 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1263 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1264 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1265 | if (ar.exception instanceof CommandException) { |
| 1266 | CommandException.Error error = |
| 1267 | ((CommandException) (ar.exception)).getCommandError(); |
| 1268 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1269 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1270 | } else { |
| 1271 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1272 | } |
| 1273 | } else { |
| 1274 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1275 | } |
| 1276 | } else { |
| 1277 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1278 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1279 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1280 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1281 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1282 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1283 | ar = (AsyncResult) msg.obj; |
| 1284 | request = (MainThreadRequest) ar.userObj; |
| 1285 | CellNetworkScanResult cellScanResult; |
| 1286 | if (ar.exception == null && ar.result != null) { |
| 1287 | cellScanResult = new CellNetworkScanResult( |
| 1288 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1289 | (List<OperatorInfo>) ar.result); |
| 1290 | } else { |
| 1291 | if (ar.result == null) { |
| 1292 | loge("getCellNetworkScanResults: Empty response"); |
| 1293 | } |
| 1294 | if (ar.exception != null) { |
| 1295 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1296 | } |
| 1297 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1298 | if (ar.exception instanceof CommandException) { |
| 1299 | CommandException.Error error = |
| 1300 | ((CommandException) (ar.exception)).getCommandError(); |
| 1301 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1302 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1303 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1304 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1305 | } |
| 1306 | } |
| 1307 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1308 | } |
| 1309 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1310 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1311 | break; |
| 1312 | |
| 1313 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1314 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1315 | ManualNetworkSelectionArgument selArg = |
| 1316 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1317 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1318 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1319 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1320 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1321 | break; |
| 1322 | |
| 1323 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1324 | ar = (AsyncResult) msg.obj; |
| 1325 | request = (MainThreadRequest) ar.userObj; |
| 1326 | if (ar.exception == null) { |
| 1327 | request.result = true; |
| 1328 | } else { |
| 1329 | request.result = false; |
| 1330 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1331 | } |
| 1332 | notifyRequester(request); |
| 1333 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1334 | break; |
| 1335 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1336 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1337 | request = (MainThreadRequest) msg.obj; |
| 1338 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1339 | if (defaultPhone != null) { |
| 1340 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1341 | } else { |
| 1342 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1343 | Bundle bundle = new Bundle(); |
| 1344 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1345 | new ModemActivityInfo(0, 0, 0, |
| 1346 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1347 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1348 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1349 | break; |
| 1350 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1351 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1352 | ar = (AsyncResult) msg.obj; |
| 1353 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1354 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1355 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1356 | ModemActivityInfo ret = null; |
| 1357 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1358 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1359 | // Update the last modem activity info and the result of the request. |
| 1360 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1361 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1362 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1363 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1364 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1365 | .getTransmitTimeMillis(); |
| 1366 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1367 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1368 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1369 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1370 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1371 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1372 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1373 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1374 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1375 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1376 | info.getReceiveTimeMillis() |
| 1377 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1378 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1379 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1380 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1381 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1382 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1383 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1384 | } else { |
| 1385 | if (ar.result == null) { |
| 1386 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1387 | error = TelephonyManager.ModemActivityInfoException |
| 1388 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1389 | } else if (ar.exception instanceof CommandException) { |
| 1390 | loge("queryModemActivityInfo: CommandException: " + |
| 1391 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1392 | error = TelephonyManager.ModemActivityInfoException |
| 1393 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1394 | } else { |
| 1395 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1396 | error = TelephonyManager.ModemActivityInfoException |
| 1397 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1398 | } |
| 1399 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1400 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1401 | if (ret != null) { |
| 1402 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1403 | } else { |
| 1404 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1405 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1406 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1407 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1408 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1409 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1410 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1411 | case CMD_SET_ALLOWED_CARRIERS: |
| 1412 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1413 | CarrierRestrictionRules argument = |
| 1414 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1415 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1416 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1417 | break; |
| 1418 | |
| 1419 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1420 | ar = (AsyncResult) msg.obj; |
| 1421 | request = (MainThreadRequest) ar.userObj; |
| 1422 | if (ar.exception == null && ar.result != null) { |
| 1423 | request.result = ar.result; |
| 1424 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1425 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1426 | if (ar.exception instanceof CommandException) { |
| 1427 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1428 | CommandException.Error error = |
| 1429 | ((CommandException) (ar.exception)).getCommandError(); |
| 1430 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1431 | request.result = |
| 1432 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1433 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1434 | } else { |
| 1435 | loge("setAllowedCarriers: Unknown exception"); |
| 1436 | } |
| 1437 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1438 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1439 | break; |
| 1440 | |
| 1441 | case CMD_GET_ALLOWED_CARRIERS: |
| 1442 | request = (MainThreadRequest) msg.obj; |
| 1443 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1444 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1445 | break; |
| 1446 | |
| 1447 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1448 | ar = (AsyncResult) msg.obj; |
| 1449 | request = (MainThreadRequest) ar.userObj; |
| 1450 | if (ar.exception == null && ar.result != null) { |
| 1451 | request.result = ar.result; |
| 1452 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1453 | request.result = new IllegalStateException( |
| 1454 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1455 | if (ar.result == null) { |
| 1456 | loge("getAllowedCarriers: Empty response"); |
| 1457 | } else if (ar.exception instanceof CommandException) { |
| 1458 | loge("getAllowedCarriers: CommandException: " + |
| 1459 | ar.exception); |
| 1460 | } else { |
| 1461 | loge("getAllowedCarriers: Unknown exception"); |
| 1462 | } |
| 1463 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1464 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1465 | break; |
| 1466 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1467 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1468 | ar = (AsyncResult) msg.obj; |
| 1469 | request = (MainThreadRequest) ar.userObj; |
| 1470 | if (ar.exception == null && ar.result != null) { |
| 1471 | request.result = ar.result; |
| 1472 | } else { |
| 1473 | request.result = new IllegalArgumentException( |
| 1474 | "Failed to retrieve Forbidden Plmns"); |
| 1475 | if (ar.result == null) { |
| 1476 | loge("getForbiddenPlmns: Empty response"); |
| 1477 | } else { |
| 1478 | loge("getForbiddenPlmns: Unknown exception"); |
| 1479 | } |
| 1480 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1481 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1482 | break; |
| 1483 | |
| 1484 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1485 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1486 | uiccPort = getUiccPortFromRequest(request); |
| 1487 | if (uiccPort == null) { |
| 1488 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1489 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1490 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1491 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1492 | break; |
| 1493 | } |
| 1494 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1495 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1496 | if (uiccApp == null) { |
| 1497 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1498 | + appType); |
| 1499 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1500 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1501 | break; |
| 1502 | } else { |
| 1503 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1504 | + " specified type -- " + appType); |
| 1505 | } |
| 1506 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1507 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1508 | onCompleted); |
| 1509 | break; |
| 1510 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1511 | case CMD_SWITCH_SLOTS: |
| 1512 | request = (MainThreadRequest) msg.obj; |
| 1513 | int[] physicalSlots = (int[]) request.argument; |
| 1514 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1515 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1516 | break; |
| 1517 | |
| 1518 | case EVENT_SWITCH_SLOTS_DONE: |
| 1519 | ar = (AsyncResult) msg.obj; |
| 1520 | request = (MainThreadRequest) ar.userObj; |
| 1521 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1522 | notifyRequester(request); |
| 1523 | break; |
| 1524 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1525 | request = (MainThreadRequest) msg.obj; |
| 1526 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1527 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1528 | break; |
| 1529 | |
| 1530 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1531 | ar = (AsyncResult) msg.obj; |
| 1532 | request = (MainThreadRequest) ar.userObj; |
| 1533 | if (ar.exception != null) { |
| 1534 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1535 | } else { |
| 1536 | int mode = ((int[]) ar.result)[0]; |
| 1537 | if (mode == 0) { |
| 1538 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1539 | } else { |
| 1540 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1541 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1542 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1543 | notifyRequester(request); |
| 1544 | break; |
| 1545 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1546 | request = (MainThreadRequest) msg.obj; |
| 1547 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1548 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1549 | break; |
| 1550 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1551 | ar = (AsyncResult) msg.obj; |
| 1552 | request = (MainThreadRequest) ar.userObj; |
| 1553 | if (ar.exception != null) { |
| 1554 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1555 | } else { |
| 1556 | request.result = ((int[]) ar.result)[0]; |
| 1557 | } |
| 1558 | notifyRequester(request); |
| 1559 | break; |
| 1560 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1561 | request = (MainThreadRequest) msg.obj; |
| 1562 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1563 | int mode = (int) request.argument; |
| 1564 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1565 | break; |
| 1566 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1567 | ar = (AsyncResult) msg.obj; |
| 1568 | request = (MainThreadRequest) ar.userObj; |
| 1569 | request.result = ar.exception == null; |
| 1570 | notifyRequester(request); |
| 1571 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1572 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1573 | request = (MainThreadRequest) msg.obj; |
| 1574 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1575 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1576 | break; |
| 1577 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1578 | ar = (AsyncResult) msg.obj; |
| 1579 | request = (MainThreadRequest) ar.userObj; |
| 1580 | if (ar.exception != null) { |
| 1581 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1582 | } else { |
| 1583 | request.result = ((int[]) ar.result)[0]; |
| 1584 | } |
| 1585 | notifyRequester(request); |
| 1586 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1587 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1588 | request = (MainThreadRequest) msg.obj; |
| 1589 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1590 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1591 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1592 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1593 | break; |
| 1594 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1595 | ar = (AsyncResult) msg.obj; |
| 1596 | request = (MainThreadRequest) ar.userObj; |
| 1597 | request.result = ar.exception == null; |
| 1598 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1599 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1600 | case CMD_GET_ALL_CELL_INFO: |
| 1601 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1602 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1603 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1604 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1605 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1606 | ar = (AsyncResult) msg.obj; |
| 1607 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1608 | // If a timeout occurs, the response will be null |
| 1609 | request.result = (ar.exception == null && ar.result != null) |
| 1610 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1611 | synchronized (request) { |
| 1612 | request.notifyAll(); |
| 1613 | } |
| 1614 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1615 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1616 | request = (MainThreadRequest) msg.obj; |
| 1617 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1618 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1619 | break; |
| 1620 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1621 | ar = (AsyncResult) msg.obj; |
| 1622 | request = (MainThreadRequest) ar.userObj; |
| 1623 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1624 | try { |
| 1625 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1626 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1627 | cb.onError( |
| 1628 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1629 | ar.exception.getClass().getName(), |
| 1630 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1631 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1632 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1633 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1634 | } else { |
| 1635 | // use the result as returned |
| 1636 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1637 | } |
| 1638 | } catch (RemoteException re) { |
| 1639 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1640 | } |
| 1641 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1642 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1643 | request = (MainThreadRequest) msg.obj; |
| 1644 | WorkSource ws = (WorkSource) request.argument; |
| 1645 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1646 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1647 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1648 | } |
| 1649 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1650 | ar = (AsyncResult) msg.obj; |
| 1651 | request = (MainThreadRequest) ar.userObj; |
| 1652 | if (ar.exception == null) { |
| 1653 | request.result = ar.result; |
| 1654 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1655 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1656 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1657 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1658 | } |
| 1659 | |
| 1660 | synchronized (request) { |
| 1661 | request.notifyAll(); |
| 1662 | } |
| 1663 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1664 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1665 | case CMD_MODEM_REBOOT: |
| 1666 | request = (MainThreadRequest) msg.obj; |
| 1667 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1668 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1669 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1670 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1671 | handleNullReturnEvent(msg, "rebootModem"); |
| 1672 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1673 | case CMD_REQUEST_ENABLE_MODEM: |
| 1674 | request = (MainThreadRequest) msg.obj; |
| 1675 | boolean enable = (boolean) request.argument; |
| 1676 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1677 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1678 | PhoneConfigurationManager.getInstance() |
| 1679 | .enablePhone(request.phone, enable, onCompleted); |
| 1680 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1681 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1682 | ar = (AsyncResult) msg.obj; |
| 1683 | request = (MainThreadRequest) ar.userObj; |
| 1684 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1685 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1686 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1687 | if ((boolean) request.result) { |
| 1688 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1689 | updateModemStateMetrics(); |
| 1690 | } else { |
| 1691 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1692 | + ar.exception); |
| 1693 | } |
| 1694 | notifyRequester(request); |
| 1695 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1696 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1697 | case CMD_GET_MODEM_STATUS: |
| 1698 | request = (MainThreadRequest) msg.obj; |
| 1699 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1700 | PhoneConfigurationManager.getInstance() |
| 1701 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1702 | break; |
| 1703 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1704 | ar = (AsyncResult) msg.obj; |
| 1705 | request = (MainThreadRequest) ar.userObj; |
| 1706 | int id = request.phone.getPhoneId(); |
| 1707 | if (ar.exception == null && ar.result != null) { |
| 1708 | request.result = ar.result; |
| 1709 | //update the cache as modem status has changed |
| 1710 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1711 | (boolean) request.result); |
| 1712 | } else { |
| 1713 | // Return true if modem status cannot be retrieved. For most cases, |
| 1714 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1715 | // and disable modem are not supported. Modem is always on. |
| 1716 | // TODO: this should be fixed in R to support a third |
| 1717 | // status UNKNOWN b/131631629 |
| 1718 | request.result = true; |
| 1719 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1720 | + ar.exception); |
| 1721 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1722 | notifyRequester(request); |
| 1723 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1724 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1725 | request = (MainThreadRequest) msg.obj; |
| 1726 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1727 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1728 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1729 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1730 | break; |
| 1731 | } |
| 1732 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1733 | ar = (AsyncResult) msg.obj; |
| 1734 | request = (MainThreadRequest) ar.userObj; |
| 1735 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1736 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1737 | args.second.accept(ar.exception == null); |
| 1738 | notifyRequester(request); |
| 1739 | break; |
| 1740 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1741 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1742 | request = (MainThreadRequest) msg.obj; |
| 1743 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1744 | Phone phone = getPhoneFromRequest(request); |
| 1745 | if (phone != null) { |
| 1746 | phone.getSystemSelectionChannels(onCompleted); |
| 1747 | } else { |
| 1748 | loge("getSystemSelectionChannels: No phone object"); |
| 1749 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1750 | notifyRequester(request); |
| 1751 | } |
| 1752 | break; |
| 1753 | } |
| 1754 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1755 | ar = (AsyncResult) msg.obj; |
| 1756 | request = (MainThreadRequest) ar.userObj; |
| 1757 | if (ar.exception == null && ar.result != null) { |
| 1758 | request.result = ar.result; |
| 1759 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1760 | request.result = new IllegalStateException( |
| 1761 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1762 | if (ar.result == null) { |
| 1763 | loge("getSystemSelectionChannels: Empty response"); |
| 1764 | } else { |
| 1765 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1766 | } |
| 1767 | } |
| 1768 | notifyRequester(request); |
| 1769 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1770 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1771 | ar = (AsyncResult) msg.obj; |
| 1772 | request = (MainThreadRequest) ar.userObj; |
| 1773 | if (ar.exception == null && ar.result != null) { |
| 1774 | request.result = ar.result; |
| 1775 | } else { |
| 1776 | request.result = -1; |
| 1777 | loge("Failed to set Forbidden Plmns"); |
| 1778 | if (ar.result == null) { |
| 1779 | loge("setForbidenPlmns: Empty response"); |
| 1780 | } else if (ar.exception != null) { |
| 1781 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1782 | request.result = -1; |
| 1783 | } else { |
| 1784 | loge("setForbiddenPlmns: Unknown exception"); |
| 1785 | } |
| 1786 | } |
| 1787 | notifyRequester(request); |
| 1788 | break; |
| 1789 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1790 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1791 | uiccPort = getUiccPortFromRequest(request); |
| 1792 | if (uiccPort == null) { |
| 1793 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1794 | request.result = -1; |
| 1795 | notifyRequester(request); |
| 1796 | break; |
| 1797 | } |
| 1798 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1799 | (Pair<Integer, List<String>>) request.argument; |
| 1800 | appType = setFplmnsArgs.first; |
| 1801 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1802 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1803 | if (uiccApp == null) { |
| 1804 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1805 | request.result = -1; |
| 1806 | loge("Failed to get UICC App"); |
| 1807 | notifyRequester(request); |
| 1808 | } else { |
| 1809 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1810 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1811 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1812 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1813 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1814 | case CMD_ERASE_MODEM_CONFIG: |
| 1815 | request = (MainThreadRequest) msg.obj; |
| 1816 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1817 | defaultPhone.eraseModemConfig(onCompleted); |
| 1818 | break; |
| 1819 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1820 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1821 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1822 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1823 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1824 | request = (MainThreadRequest) msg.obj; |
| 1825 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1826 | notifyRequester(request); |
| 1827 | break; |
| 1828 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1829 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1830 | request = (MainThreadRequest) msg.obj; |
| 1831 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1832 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1833 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1834 | changed.first, changed.second, onCompleted); |
| 1835 | break; |
| 1836 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1837 | ar = (AsyncResult) msg.obj; |
| 1838 | request = (MainThreadRequest) ar.userObj; |
| 1839 | if (ar.exception == null) { |
| 1840 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1841 | // If the operation is successful, update the PIN storage |
| 1842 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1843 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1844 | UiccController.getInstance().getPinStorage() |
| 1845 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1846 | } else { |
| 1847 | request.result = msg.arg1; |
| 1848 | } |
| 1849 | notifyRequester(request); |
| 1850 | break; |
| 1851 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1852 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1853 | request = (MainThreadRequest) msg.obj; |
| 1854 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1855 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1856 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1857 | enabled.first, enabled.second, onCompleted); |
| 1858 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1859 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1860 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1861 | ar = (AsyncResult) msg.obj; |
| 1862 | request = (MainThreadRequest) ar.userObj; |
| 1863 | if (ar.exception == null) { |
| 1864 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1865 | // If the operation is successful, update the PIN storage |
| 1866 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1867 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1868 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1869 | UiccController.getInstance().getPinStorage() |
| 1870 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1871 | } else { |
| 1872 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1873 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1874 | } else { |
| 1875 | request.result = msg.arg1; |
| 1876 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1877 | |
| 1878 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1879 | notifyRequester(request); |
| 1880 | break; |
| 1881 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1882 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1883 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1884 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1885 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1886 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1887 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1888 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1889 | |
| 1890 | case CMD_SET_DATA_THROTTLING: { |
| 1891 | request = (MainThreadRequest) msg.obj; |
| 1892 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1893 | DataThrottlingRequest dataThrottlingRequest = |
| 1894 | (DataThrottlingRequest) request.argument; |
| 1895 | Phone phone = getPhoneFromRequest(request); |
| 1896 | if (phone != null) { |
| 1897 | phone.setDataThrottling(onCompleted, |
| 1898 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1899 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1900 | } else { |
| 1901 | loge("setDataThrottling: No phone object"); |
| 1902 | request.result = |
| 1903 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1904 | notifyRequester(request); |
| 1905 | } |
| 1906 | |
| 1907 | break; |
| 1908 | } |
| 1909 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1910 | ar = (AsyncResult) msg.obj; |
| 1911 | request = (MainThreadRequest) ar.userObj; |
| 1912 | |
| 1913 | if (ar.exception == null) { |
| 1914 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1915 | } else if (ar.exception instanceof CommandException) { |
| 1916 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1917 | CommandException.Error error = |
| 1918 | ((CommandException) (ar.exception)).getCommandError(); |
| 1919 | |
| 1920 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1921 | request.result = TelephonyManager |
| 1922 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1923 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1924 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 1925 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1926 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1927 | } else { |
| 1928 | request.result = |
| 1929 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1930 | } |
| 1931 | } else { |
| 1932 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1933 | } |
| 1934 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1935 | notifyRequester(request); |
| 1936 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1937 | |
| 1938 | case CMD_SET_SIM_POWER: { |
| 1939 | request = (MainThreadRequest) msg.obj; |
| 1940 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1941 | request = (MainThreadRequest) msg.obj; |
| 1942 | int stateToSet = |
| 1943 | ((Pair<Integer, IIntegerConsumer>) |
| 1944 | request.argument).first; |
| 1945 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1946 | break; |
| 1947 | } |
| 1948 | case EVENT_SET_SIM_POWER_DONE: { |
| 1949 | ar = (AsyncResult) msg.obj; |
| 1950 | request = (MainThreadRequest) ar.userObj; |
| 1951 | IIntegerConsumer callback = |
| 1952 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1953 | if (ar.exception != null) { |
| 1954 | loge("setSimPower exception: " + ar.exception); |
| 1955 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1956 | .RESULT_ERROR_UNKNOWN; |
| 1957 | if (ar.exception instanceof CommandException) { |
| 1958 | CommandException.Error error = |
| 1959 | ((CommandException) (ar.exception)).getCommandError(); |
| 1960 | if (error == CommandException.Error.SIM_ERR) { |
| 1961 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1962 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1963 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1964 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1965 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1966 | } else { |
| 1967 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1968 | } |
| 1969 | } |
| 1970 | try { |
| 1971 | callback.accept(errorCode); |
| 1972 | } catch (RemoteException e) { |
| 1973 | // Ignore if the remote process is no longer available to call back. |
| 1974 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1975 | } |
| 1976 | } else { |
| 1977 | try { |
| 1978 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1979 | } catch (RemoteException e) { |
| 1980 | // Ignore if the remote process is no longer available to call back. |
| 1981 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1982 | } |
| 1983 | } |
| 1984 | break; |
| 1985 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1986 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1987 | request = (MainThreadRequest) msg.obj; |
| 1988 | |
| 1989 | final Phone phone = getPhoneFromRequest(request); |
| 1990 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1991 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1992 | notifyRequester(request); |
| 1993 | break; |
| 1994 | } |
| 1995 | |
| 1996 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1997 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1998 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1999 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2000 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2001 | request.subId, pair.first /*callingUid*/, |
| 2002 | pair.second /*request*/, onCompleted); |
| 2003 | break; |
| 2004 | } |
| 2005 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2006 | ar = (AsyncResult) msg.obj; |
| 2007 | request = (MainThreadRequest) ar.userObj; |
| 2008 | // request.result will be the exception of ar if present, true otherwise. |
| 2009 | // Be cautious not to leave result null which will wait() forever |
| 2010 | request.result = ar.exception != null ? ar.exception : true; |
| 2011 | notifyRequester(request); |
| 2012 | break; |
| 2013 | } |
| 2014 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2015 | request = (MainThreadRequest) msg.obj; |
| 2016 | |
| 2017 | Phone phone = getPhoneFromRequest(request); |
| 2018 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2019 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2020 | notifyRequester(request); |
| 2021 | break; |
| 2022 | } |
| 2023 | |
| 2024 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2025 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2026 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2027 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2028 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2029 | request.subId, pair.first /*callingUid*/, |
| 2030 | pair.second /*request*/, onCompleted); |
| 2031 | break; |
| 2032 | } |
| 2033 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2034 | ar = (AsyncResult) msg.obj; |
| 2035 | request = (MainThreadRequest) ar.userObj; |
| 2036 | request.result = ar.exception != null ? ar.exception : true; |
| 2037 | notifyRequester(request); |
| 2038 | break; |
| 2039 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2040 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2041 | case CMD_GET_SLICING_CONFIG: { |
| 2042 | request = (MainThreadRequest) msg.obj; |
| 2043 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2044 | request.phone.getSlicingConfig(onCompleted); |
| 2045 | break; |
| 2046 | } |
| 2047 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2048 | ar = (AsyncResult) msg.obj; |
| 2049 | request = (MainThreadRequest) ar.userObj; |
| 2050 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2051 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2052 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2053 | Bundle bundle = new Bundle(); |
| 2054 | int resultCode = 0; |
| 2055 | if (ar.exception != null) { |
| 2056 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2057 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2058 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2059 | } else if (ar.result == null) { |
| 2060 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2061 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2062 | } else { |
| 2063 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2064 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2065 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2069 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2070 | } |
| 2071 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2072 | result.send(resultCode, bundle); |
| 2073 | notifyRequester(request); |
| 2074 | break; |
| 2075 | } |
| 2076 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2077 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2078 | request = (MainThreadRequest) msg.obj; |
| 2079 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2080 | UiccController.getInstance().getPinStorage() |
| 2081 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2082 | notifyRequester(request); |
| 2083 | break; |
| 2084 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2085 | default: |
| 2086 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2087 | break; |
| 2088 | } |
| 2089 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2090 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2091 | private void notifyRequester(MainThreadRequest request) { |
| 2092 | synchronized (request) { |
| 2093 | request.notifyAll(); |
| 2094 | } |
| 2095 | } |
| 2096 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2097 | private void handleNullReturnEvent(Message msg, String command) { |
| 2098 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2099 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2100 | if (ar.exception == null) { |
| 2101 | request.result = true; |
| 2102 | } else { |
| 2103 | request.result = false; |
| 2104 | if (ar.exception instanceof CommandException) { |
| 2105 | loge(command + ": CommandException: " + ar.exception); |
| 2106 | } else { |
| 2107 | loge(command + ": Unknown exception"); |
| 2108 | } |
| 2109 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2110 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2111 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2112 | } |
| 2113 | |
| 2114 | /** |
| 2115 | * Posts the specified command to be executed on the main thread, |
| 2116 | * waits for the request to complete, and returns the result. |
| 2117 | * @see #sendRequestAsync |
| 2118 | */ |
| 2119 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2120 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2121 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2122 | } |
| 2123 | |
| 2124 | /** |
| 2125 | * Posts the specified command to be executed on the main thread, |
| 2126 | * waits for the request to complete, and returns the result. |
| 2127 | * @see #sendRequestAsync |
| 2128 | */ |
| 2129 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2130 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2131 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2132 | } |
| 2133 | |
| 2134 | /** |
| 2135 | * Posts the specified command to be executed on the main thread, |
| 2136 | * waits for the request to complete, and returns the result. |
| 2137 | * @see #sendRequestAsync |
| 2138 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2139 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2140 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2141 | } |
| 2142 | |
| 2143 | /** |
| 2144 | * Posts the specified command to be executed on the main thread, |
| 2145 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2146 | * if not timeout or null otherwise. |
| 2147 | * @see #sendRequestAsync |
| 2148 | */ |
| 2149 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2150 | long timeoutInMs) { |
| 2151 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2152 | } |
| 2153 | |
| 2154 | /** |
| 2155 | * Posts the specified command to be executed on the main thread, |
| 2156 | * waits for the request to complete, and returns the result. |
| 2157 | * @see #sendRequestAsync |
| 2158 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2159 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2160 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2161 | } |
| 2162 | |
| 2163 | /** |
| 2164 | * Posts the specified command to be executed on the main thread, |
| 2165 | * waits for the request to complete, and returns the result. |
| 2166 | * @see #sendRequestAsync |
| 2167 | */ |
| 2168 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2169 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2170 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2171 | } |
| 2172 | |
| 2173 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2174 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2175 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2176 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2177 | * @see #sendRequestAsync |
| 2178 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2179 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2180 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2181 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2182 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2183 | } |
| 2184 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2185 | MainThreadRequest request = null; |
| 2186 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2187 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2188 | } else if (phone != null) { |
| 2189 | request = new MainThreadRequest(argument, phone, workSource); |
| 2190 | } else { |
| 2191 | request = new MainThreadRequest(argument, subId, workSource); |
| 2192 | } |
| 2193 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2194 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2195 | msg.sendToTarget(); |
| 2196 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2197 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2198 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2199 | if (timeoutInMs >= 0) { |
| 2200 | // Wait for at least timeoutInMs before returning null request result |
| 2201 | long now = SystemClock.elapsedRealtime(); |
| 2202 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2203 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2204 | try { |
| 2205 | request.wait(deadline - now); |
| 2206 | } catch (InterruptedException e) { |
| 2207 | // Do nothing, go back and check if request is completed or timeout |
| 2208 | } finally { |
| 2209 | now = SystemClock.elapsedRealtime(); |
| 2210 | } |
| 2211 | } |
| 2212 | } else { |
| 2213 | // Wait for the request to complete |
| 2214 | while (request.result == null) { |
| 2215 | try { |
| 2216 | request.wait(); |
| 2217 | } catch (InterruptedException e) { |
| 2218 | // Do nothing, go back and wait until the request is complete |
| 2219 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2220 | } |
| 2221 | } |
| 2222 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2223 | if (request.result == null) { |
| 2224 | Log.wtf(LOG_TAG, |
| 2225 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2226 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2227 | return request.result; |
| 2228 | } |
| 2229 | |
| 2230 | /** |
| 2231 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2232 | * Posts the specified command to be executed on the main thread, and |
| 2233 | * returns immediately. |
| 2234 | * @see #sendRequest |
| 2235 | */ |
| 2236 | private void sendRequestAsync(int command) { |
| 2237 | mMainThreadHandler.sendEmptyMessage(command); |
| 2238 | } |
| 2239 | |
| 2240 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2241 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2242 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2243 | */ |
| 2244 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2245 | sendRequestAsync(command, argument, null, null); |
| 2246 | } |
| 2247 | |
| 2248 | /** |
| 2249 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2250 | * @see {@link #sendRequest(int,Object)} |
| 2251 | */ |
| 2252 | private void sendRequestAsync( |
| 2253 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2254 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2255 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2256 | msg.sendToTarget(); |
| 2257 | } |
| 2258 | |
| 2259 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2260 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2261 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2262 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2263 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2264 | synchronized (PhoneInterfaceManager.class) { |
| 2265 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2266 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2267 | } else { |
| 2268 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2269 | } |
| 2270 | return sInstance; |
| 2271 | } |
| 2272 | } |
| 2273 | |
| 2274 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2275 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2276 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2277 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2278 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2279 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2280 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2281 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2282 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2283 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2284 | mTelephonySharedPreferences = |
| 2285 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2286 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2287 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2288 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2289 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2290 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2291 | publish(); |
| 2292 | } |
| 2293 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2294 | private Phone getDefaultPhone() { |
| 2295 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2296 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2297 | } |
| 2298 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2299 | private void publish() { |
| 2300 | if (DBG) log("publish: " + this); |
| 2301 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2302 | TelephonyFrameworkInitializer |
| 2303 | .getTelephonyServiceManager() |
| 2304 | .getTelephonyServiceRegisterer() |
| 2305 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2306 | } |
| 2307 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2308 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2309 | if (request.phone != null) { |
| 2310 | return request.phone; |
| 2311 | } else { |
| 2312 | return getPhoneFromSubId(request.subId); |
| 2313 | } |
| 2314 | } |
| 2315 | |
| 2316 | private Phone getPhoneFromSubId(int subId) { |
| 2317 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2318 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2319 | } |
| 2320 | |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2321 | private UiccPort getUiccPortFromRequest(MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2322 | Phone phone = getPhoneFromRequest(request); |
| 2323 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2324 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2325 | } |
| 2326 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2327 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2328 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2329 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2330 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2331 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2332 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2333 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2334 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2335 | } |
| 2336 | |
| 2337 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2338 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2339 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2340 | } |
| 2341 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2342 | private boolean isImsAvailableOnDevice() { |
| 2343 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2344 | if (pm == null) { |
| 2345 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2346 | // so do not throw error and allow. |
| 2347 | return true; |
| 2348 | } |
| 2349 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2350 | } |
| 2351 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2352 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2353 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2354 | } |
| 2355 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2356 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2357 | if (DBG) log("dial: " + number); |
| 2358 | // No permission check needed here: This is just a wrapper around the |
| 2359 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2360 | // the UI before it does anything. |
| 2361 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2362 | final long identity = Binder.clearCallingIdentity(); |
| 2363 | try { |
| 2364 | String url = createTelUrl(number); |
| 2365 | if (url == null) { |
| 2366 | return; |
| 2367 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2368 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2369 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2370 | PhoneConstants.State state = mCM.getState(subId); |
| 2371 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2372 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2373 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2374 | mApp.startActivity(intent); |
| 2375 | } |
| 2376 | } finally { |
| 2377 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2378 | } |
| 2379 | } |
| 2380 | |
| 2381 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2382 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2383 | } |
| 2384 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2385 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2386 | if (DBG) log("call: " + number); |
| 2387 | |
| 2388 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2389 | // need to do a permission check since we're calling startActivity() |
| 2390 | // from the context of the phone app. |
| 2391 | enforceCallPermission(); |
| 2392 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2393 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2394 | != AppOpsManager.MODE_ALLOWED) { |
| 2395 | return; |
| 2396 | } |
| 2397 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2398 | final long identity = Binder.clearCallingIdentity(); |
| 2399 | try { |
| 2400 | String url = createTelUrl(number); |
| 2401 | if (url == null) { |
| 2402 | return; |
| 2403 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2404 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2405 | boolean isValid = false; |
| 2406 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2407 | if (slist != null) { |
| 2408 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2409 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2410 | isValid = true; |
| 2411 | break; |
| 2412 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2413 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2414 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2415 | if (!isValid) { |
| 2416 | return; |
| 2417 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2418 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2419 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2420 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2421 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2422 | mApp.startActivity(intent); |
| 2423 | } finally { |
| 2424 | Binder.restoreCallingIdentity(identity); |
| 2425 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2426 | } |
| 2427 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2428 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2429 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2430 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2431 | } |
| 2432 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2433 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2434 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2435 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2436 | } |
| 2437 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2438 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2439 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2440 | |
| 2441 | final long identity = Binder.clearCallingIdentity(); |
| 2442 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2443 | Phone phone = getPhone(subId); |
| 2444 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2445 | checkSimPin.start(); |
| 2446 | return checkSimPin.unlockSim(null, pin); |
| 2447 | } finally { |
| 2448 | Binder.restoreCallingIdentity(identity); |
| 2449 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2450 | } |
| 2451 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2452 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2453 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2454 | |
| 2455 | final long identity = Binder.clearCallingIdentity(); |
| 2456 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2457 | Phone phone = getPhone(subId); |
| 2458 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2459 | checkSimPuk.start(); |
| 2460 | return checkSimPuk.unlockSim(puk, pin); |
| 2461 | } finally { |
| 2462 | Binder.restoreCallingIdentity(identity); |
| 2463 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2464 | } |
| 2465 | |
| 2466 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2467 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2468 | * a synchronous one. |
| 2469 | */ |
| 2470 | private static class UnlockSim extends Thread { |
| 2471 | |
| 2472 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2473 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2474 | |
| 2475 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2476 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2477 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2478 | |
| 2479 | // For replies from SimCard interface |
| 2480 | private Handler mHandler; |
| 2481 | |
| 2482 | // For async handler to identify request type |
| 2483 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2484 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2485 | UnlockSim(int phoneId, IccCard simCard) { |
| 2486 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2487 | mSimCard = simCard; |
| 2488 | } |
| 2489 | |
| 2490 | @Override |
| 2491 | public void run() { |
| 2492 | Looper.prepare(); |
| 2493 | synchronized (UnlockSim.this) { |
| 2494 | mHandler = new Handler() { |
| 2495 | @Override |
| 2496 | public void handleMessage(Message msg) { |
| 2497 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2498 | switch (msg.what) { |
| 2499 | case SUPPLY_PIN_COMPLETE: |
| 2500 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2501 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2502 | mRetryCount = msg.arg1; |
| 2503 | if (ar.exception != null) { |
| 2504 | if (ar.exception instanceof CommandException && |
| 2505 | ((CommandException)(ar.exception)).getCommandError() |
| 2506 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2507 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2508 | } //When UiccCardApp dispose,handle message and return exception |
| 2509 | else if (ar.exception instanceof CommandException && |
| 2510 | ((CommandException) (ar.exception)).getCommandError() |
| 2511 | == CommandException.Error.ABORTED) { |
| 2512 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2513 | } else { |
| 2514 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2515 | } |
| 2516 | } else { |
| 2517 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2518 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2519 | mDone = true; |
| 2520 | UnlockSim.this.notifyAll(); |
| 2521 | } |
| 2522 | break; |
| 2523 | } |
| 2524 | } |
| 2525 | }; |
| 2526 | UnlockSim.this.notifyAll(); |
| 2527 | } |
| 2528 | Looper.loop(); |
| 2529 | } |
| 2530 | |
| 2531 | /* |
| 2532 | * Use PIN or PUK to unlock SIM card |
| 2533 | * |
| 2534 | * If PUK is null, unlock SIM card with PIN |
| 2535 | * |
| 2536 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2537 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2538 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2539 | |
| 2540 | while (mHandler == null) { |
| 2541 | try { |
| 2542 | wait(); |
| 2543 | } catch (InterruptedException e) { |
| 2544 | Thread.currentThread().interrupt(); |
| 2545 | } |
| 2546 | } |
| 2547 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2548 | |
| 2549 | if (puk == null) { |
| 2550 | mSimCard.supplyPin(pin, callback); |
| 2551 | } else { |
| 2552 | mSimCard.supplyPuk(puk, pin, callback); |
| 2553 | } |
| 2554 | |
| 2555 | while (!mDone) { |
| 2556 | try { |
| 2557 | Log.d(LOG_TAG, "wait for done"); |
| 2558 | wait(); |
| 2559 | } catch (InterruptedException e) { |
| 2560 | // Restore the interrupted status |
| 2561 | Thread.currentThread().interrupt(); |
| 2562 | } |
| 2563 | } |
| 2564 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2565 | int[] resultArray = new int[2]; |
| 2566 | resultArray[0] = mResult; |
| 2567 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2568 | |
| 2569 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2570 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2571 | } |
| 2572 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2573 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2574 | } |
| 2575 | } |
| 2576 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2577 | /** |
| 2578 | * This method has been removed due to privacy and stability concerns. |
| 2579 | */ |
| 2580 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2581 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2582 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2583 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2584 | } |
| 2585 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2586 | @Override |
| 2587 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2588 | mApp.getSystemService(AppOpsManager.class) |
| 2589 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2590 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2591 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2592 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2593 | // Callers targeting S have no business invoking this method. |
| 2594 | return; |
| 2595 | } |
| 2596 | |
| 2597 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2598 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2599 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2600 | .setCallingPackage(callingPackage) |
| 2601 | .setCallingFeatureId(null) |
| 2602 | .setCallingPid(Binder.getCallingPid()) |
| 2603 | .setCallingUid(Binder.getCallingUid()) |
| 2604 | .setMethod("updateServiceLocation") |
| 2605 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2606 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2607 | .build()); |
| 2608 | // Apps that lack location permission have no business calling this method; |
| 2609 | // however, because no permission was declared in the public API, denials must |
| 2610 | // all be "soft". |
| 2611 | switch (locationResult) { |
| 2612 | case DENIED_HARD: /* fall through */ |
| 2613 | case DENIED_SOFT: |
| 2614 | return; |
| 2615 | } |
| 2616 | |
| 2617 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2618 | final long identity = Binder.clearCallingIdentity(); |
| 2619 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2620 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2621 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2622 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2623 | } |
| 2624 | } finally { |
| 2625 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2626 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2627 | } |
| 2628 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2629 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2630 | @Override |
| 2631 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2632 | return isRadioOnWithFeature(callingPackage, null); |
| 2633 | } |
| 2634 | |
| 2635 | |
| 2636 | @Override |
| 2637 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2638 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2639 | callingFeatureId); |
| 2640 | } |
| 2641 | |
| 2642 | @Deprecated |
| 2643 | @Override |
| 2644 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2645 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2646 | } |
| 2647 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2648 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2649 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2650 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2651 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2652 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2653 | return false; |
| 2654 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2655 | |
| 2656 | final long identity = Binder.clearCallingIdentity(); |
| 2657 | try { |
| 2658 | return isRadioOnForSubscriber(subId); |
| 2659 | } finally { |
| 2660 | Binder.restoreCallingIdentity(identity); |
| 2661 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2662 | } |
| 2663 | |
| 2664 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2665 | final long identity = Binder.clearCallingIdentity(); |
| 2666 | try { |
| 2667 | final Phone phone = getPhone(subId); |
| 2668 | if (phone != null) { |
| 2669 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2670 | } else { |
| 2671 | return false; |
| 2672 | } |
| 2673 | } finally { |
| 2674 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2675 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2676 | } |
| 2677 | |
| 2678 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2679 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2680 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2681 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2682 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2683 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2684 | |
| 2685 | final long identity = Binder.clearCallingIdentity(); |
| 2686 | try { |
| 2687 | final Phone phone = getPhone(subId); |
| 2688 | if (phone != null) { |
| 2689 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2690 | } |
| 2691 | } finally { |
| 2692 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2693 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2694 | } |
| 2695 | |
| 2696 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2697 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2698 | } |
| 2699 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2700 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2701 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2702 | |
| 2703 | final long identity = Binder.clearCallingIdentity(); |
| 2704 | try { |
| 2705 | final Phone phone = getPhone(subId); |
| 2706 | if (phone == null) { |
| 2707 | return false; |
| 2708 | } |
| 2709 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2710 | toggleRadioOnOffForSubscriber(subId); |
| 2711 | } |
| 2712 | return true; |
| 2713 | } finally { |
| 2714 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2715 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2716 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2717 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2718 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2719 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2720 | /* |
| 2721 | * If any of the Radios are available, it will need to be |
| 2722 | * shutdown. So return true if any Radio is available. |
| 2723 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2724 | final long identity = Binder.clearCallingIdentity(); |
| 2725 | try { |
| 2726 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2727 | Phone phone = PhoneFactory.getPhone(i); |
| 2728 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2729 | } |
| 2730 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2731 | return false; |
| 2732 | } finally { |
| 2733 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2734 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2735 | } |
| 2736 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2737 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2738 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2739 | enforceModifyPermission(); |
| 2740 | |
| 2741 | final long identity = Binder.clearCallingIdentity(); |
| 2742 | try { |
| 2743 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2744 | logv("Shutting down Phone " + i); |
| 2745 | shutdownRadioUsingPhoneId(i); |
| 2746 | } |
| 2747 | } finally { |
| 2748 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2749 | } |
| 2750 | } |
| 2751 | |
| 2752 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2753 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2754 | if (phone != null && phone.isRadioAvailable()) { |
| 2755 | phone.shutdownRadio(); |
| 2756 | } |
| 2757 | } |
| 2758 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2759 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2760 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2761 | |
| 2762 | final long identity = Binder.clearCallingIdentity(); |
| 2763 | try { |
| 2764 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2765 | if (defaultPhone != null) { |
| 2766 | defaultPhone.setRadioPower(turnOn); |
| 2767 | return true; |
| 2768 | } else { |
| 2769 | loge("There's no default phone."); |
| 2770 | return false; |
| 2771 | } |
| 2772 | } finally { |
| 2773 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2774 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2775 | } |
| 2776 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2777 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2778 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2779 | |
| 2780 | final long identity = Binder.clearCallingIdentity(); |
| 2781 | try { |
| 2782 | final Phone phone = getPhone(subId); |
| 2783 | if (phone != null) { |
| 2784 | phone.setRadioPower(turnOn); |
| 2785 | return true; |
| 2786 | } else { |
| 2787 | return false; |
| 2788 | } |
| 2789 | } finally { |
| 2790 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2791 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2792 | } |
| 2793 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2794 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2795 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2796 | public boolean enableDataConnectivity() { |
| 2797 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2798 | |
| 2799 | final long identity = Binder.clearCallingIdentity(); |
| 2800 | try { |
| 2801 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2802 | final Phone phone = getPhone(subId); |
| 2803 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2804 | phone.getDataEnabledSettings().setDataEnabled( |
| 2805 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2806 | return true; |
| 2807 | } else { |
| 2808 | return false; |
| 2809 | } |
| 2810 | } finally { |
| 2811 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2812 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2813 | } |
| 2814 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2815 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2816 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2817 | public boolean disableDataConnectivity() { |
| 2818 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2819 | |
| 2820 | final long identity = Binder.clearCallingIdentity(); |
| 2821 | try { |
| 2822 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2823 | final Phone phone = getPhone(subId); |
| 2824 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2825 | phone.getDataEnabledSettings().setDataEnabled( |
| 2826 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2827 | return true; |
| 2828 | } else { |
| 2829 | return false; |
| 2830 | } |
| 2831 | } finally { |
| 2832 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2833 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2834 | } |
| 2835 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2836 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2837 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2838 | final long identity = Binder.clearCallingIdentity(); |
| 2839 | try { |
| 2840 | final Phone phone = getPhone(subId); |
| 2841 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2842 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2843 | } else { |
| 2844 | return false; |
| 2845 | } |
| 2846 | } finally { |
| 2847 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2848 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2849 | } |
| 2850 | |
| 2851 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2852 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2853 | } |
| 2854 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2855 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2856 | enforceCallPermission(); |
| 2857 | |
| 2858 | final long identity = Binder.clearCallingIdentity(); |
| 2859 | try { |
| 2860 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2861 | return; |
| 2862 | } |
| 2863 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2864 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2865 | } finally { |
| 2866 | Binder.restoreCallingIdentity(identity); |
| 2867 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2868 | }; |
| 2869 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2870 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2871 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2872 | |
| 2873 | final long identity = Binder.clearCallingIdentity(); |
| 2874 | try { |
| 2875 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2876 | return false; |
| 2877 | } |
| 2878 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2879 | } finally { |
| 2880 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2881 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2882 | } |
| 2883 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2884 | /** |
| 2885 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 2886 | * tag on getCallState Binder call. |
| 2887 | */ |
| 2888 | @Deprecated |
| 2889 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2890 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2891 | if (CompatChanges.isChangeEnabled( |
| 2892 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2893 | Binder.getCallingUid())) { |
| 2894 | // Do not allow this API to be called on API version 31+, it should only be |
| 2895 | // called on old apps using this Binder call directly. |
| 2896 | throw new SecurityException("This method can only be used for applications " |
| 2897 | + "targeting API version 30 or less."); |
| 2898 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2899 | final long identity = Binder.clearCallingIdentity(); |
| 2900 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2901 | Phone phone = getPhone(getDefaultSubscription()); |
| 2902 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2903 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2904 | } finally { |
| 2905 | Binder.restoreCallingIdentity(identity); |
| 2906 | } |
| 2907 | } |
| 2908 | |
| 2909 | @Override |
| 2910 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 2911 | if (CompatChanges.isChangeEnabled( |
| 2912 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2913 | Binder.getCallingUid())) { |
| 2914 | // Check READ_PHONE_STATE for API version 31+ |
| 2915 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2916 | featureId, "getCallStateForSubscription")) { |
| 2917 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 2918 | + "targeting API level 31+."); |
| 2919 | } |
| 2920 | } |
| 2921 | final long identity = Binder.clearCallingIdentity(); |
| 2922 | try { |
| 2923 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2924 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2925 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2926 | } finally { |
| 2927 | Binder.restoreCallingIdentity(identity); |
| 2928 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2929 | } |
| 2930 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2931 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2932 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2933 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2934 | } |
| 2935 | |
| 2936 | @Override |
| 2937 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2938 | final long identity = Binder.clearCallingIdentity(); |
| 2939 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2940 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2941 | if (phone != null) { |
Jack Yu | 2c45095 | 2021-11-29 11:36:17 -0800 | [diff] [blame] | 2942 | if (phone.isUsingNewDataStack()) { |
| 2943 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
| 2944 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2945 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2946 | } else { |
| 2947 | return PhoneConstantConversions.convertDataState( |
| 2948 | PhoneConstants.DataState.DISCONNECTED); |
| 2949 | } |
| 2950 | } finally { |
| 2951 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2952 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2953 | } |
| 2954 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2955 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2956 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2957 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2958 | } |
| 2959 | |
| 2960 | @Override |
| 2961 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2962 | final long identity = Binder.clearCallingIdentity(); |
| 2963 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2964 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2965 | if (phone != null) { |
| 2966 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2967 | } else { |
| 2968 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2969 | } |
| 2970 | } finally { |
| 2971 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2972 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2973 | } |
| 2974 | |
| 2975 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2976 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2977 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2978 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2979 | |
| 2980 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2981 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2982 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2983 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2984 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2985 | .setCallingPid(Binder.getCallingPid()) |
| 2986 | .setCallingUid(Binder.getCallingUid()) |
| 2987 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2988 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2989 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2990 | .build()); |
| 2991 | switch (locationResult) { |
| 2992 | case DENIED_HARD: |
| 2993 | throw new SecurityException("Not allowed to access cell location"); |
| 2994 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2995 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2996 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2997 | } |
| 2998 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2999 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3000 | final long identity = Binder.clearCallingIdentity(); |
| 3001 | try { |
| 3002 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3003 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3004 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3005 | } finally { |
| 3006 | Binder.restoreCallingIdentity(identity); |
| 3007 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3008 | } |
| 3009 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3010 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3011 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3012 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3013 | // registered cell info, so return a NULL country instead. |
| 3014 | final long identity = Binder.clearCallingIdentity(); |
| 3015 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3016 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3017 | // Get default phone in this case. |
| 3018 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3019 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3020 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3021 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3022 | if (phone == null) return ""; |
| 3023 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3024 | if (sst == null) return ""; |
| 3025 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3026 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3027 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3028 | } finally { |
| 3029 | Binder.restoreCallingIdentity(identity); |
| 3030 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3031 | } |
| 3032 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3033 | /** |
| 3034 | * This method was removed due to potential issues caused by performing partial |
| 3035 | * updates of service state, and lack of a credible use case. |
| 3036 | * |
| 3037 | * This has the ability to break the telephony implementation by disabling notification of |
| 3038 | * changes in device connectivity. DO NOT USE THIS! |
| 3039 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3040 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3041 | public void enableLocationUpdates() { |
| 3042 | mApp.enforceCallingOrSelfPermission( |
| 3043 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3044 | } |
| 3045 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3046 | /** |
| 3047 | * This method was removed due to potential issues caused by performing partial |
| 3048 | * updates of service state, and lack of a credible use case. |
| 3049 | * |
| 3050 | * This has the ability to break the telephony implementation by disabling notification of |
| 3051 | * changes in device connectivity. DO NOT USE THIS! |
| 3052 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3053 | @Override |
| 3054 | public void disableLocationUpdates() { |
| 3055 | mApp.enforceCallingOrSelfPermission( |
| 3056 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3057 | } |
| 3058 | |
| 3059 | @Override |
| 3060 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3061 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3062 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3063 | try { |
| 3064 | mApp.getSystemService(AppOpsManager.class) |
| 3065 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3066 | } catch (SecurityException e) { |
| 3067 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3068 | throw e; |
| 3069 | } |
| 3070 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3071 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3072 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3073 | throw new SecurityException( |
| 3074 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3075 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3076 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3077 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3078 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3079 | return null; |
| 3080 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3081 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3082 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3083 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3084 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3085 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3086 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3087 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3088 | for (CellInfo ci : info) { |
| 3089 | if (ci instanceof CellInfoGsm) { |
| 3090 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3091 | } else if (ci instanceof CellInfoWcdma) { |
| 3092 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3093 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3094 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3095 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3096 | } |
| 3097 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3098 | private List<CellInfo> getCachedCellInfo() { |
| 3099 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3100 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3101 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3102 | if (info != null) cellInfos.addAll(info); |
| 3103 | } |
| 3104 | return cellInfos; |
| 3105 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3106 | |
| 3107 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3108 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3109 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3110 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3111 | |
| 3112 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3113 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3114 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3115 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3116 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3117 | .setCallingPid(Binder.getCallingPid()) |
| 3118 | .setCallingUid(Binder.getCallingUid()) |
| 3119 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3120 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3121 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3122 | .build()); |
| 3123 | switch (locationResult) { |
| 3124 | case DENIED_HARD: |
| 3125 | throw new SecurityException("Not allowed to access cell info"); |
| 3126 | case DENIED_SOFT: |
| 3127 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3128 | } |
| 3129 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3130 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3131 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3132 | return getCachedCellInfo(); |
| 3133 | } |
| 3134 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3135 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3136 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3137 | final long identity = Binder.clearCallingIdentity(); |
| 3138 | try { |
| 3139 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3140 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3141 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3142 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3143 | if (info != null) cellInfos.addAll(info); |
| 3144 | } |
| 3145 | return cellInfos; |
| 3146 | } finally { |
| 3147 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3148 | } |
| 3149 | } |
| 3150 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3151 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3152 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3153 | String callingFeatureId) { |
| 3154 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3155 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3156 | } |
| 3157 | |
| 3158 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3159 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3160 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3161 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3162 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3163 | } |
| 3164 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3165 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3166 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3167 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3168 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3169 | |
| 3170 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3171 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3172 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3173 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3174 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3175 | .setCallingPid(Binder.getCallingPid()) |
| 3176 | .setCallingUid(Binder.getCallingUid()) |
| 3177 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3178 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3179 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3180 | .build()); |
| 3181 | switch (locationResult) { |
| 3182 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3183 | if (TelephonyPermissions |
| 3184 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3185 | // Safetynet logging for b/154934934 |
| 3186 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3187 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3188 | throw new SecurityException("Not allowed to access cell info"); |
| 3189 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3190 | if (TelephonyPermissions |
| 3191 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3192 | // Safetynet logging for b/154934934 |
| 3193 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3194 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3195 | try { |
| 3196 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3197 | } catch (RemoteException re) { |
| 3198 | // Drop without consequences |
| 3199 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3200 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3201 | } |
| 3202 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3203 | |
| 3204 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3205 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3206 | |
| 3207 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3208 | } |
| 3209 | |
| 3210 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3211 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3212 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3213 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3214 | |
| 3215 | final long identity = Binder.clearCallingIdentity(); |
| 3216 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3217 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3218 | } finally { |
| 3219 | Binder.restoreCallingIdentity(identity); |
| 3220 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3221 | } |
| 3222 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3223 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3224 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3225 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3226 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3227 | return null; |
| 3228 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3229 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3230 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3231 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3232 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3233 | return null; |
| 3234 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3235 | |
| 3236 | final long identity = Binder.clearCallingIdentity(); |
| 3237 | try { |
| 3238 | return phone.getImei(); |
| 3239 | } finally { |
| 3240 | Binder.restoreCallingIdentity(identity); |
| 3241 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3242 | } |
| 3243 | |
| 3244 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3245 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3246 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3247 | String tac = null; |
| 3248 | if (phone != null) { |
| 3249 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3250 | try { |
| 3251 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3252 | } catch (IndexOutOfBoundsException e) { |
| 3253 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3254 | return null; |
| 3255 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3256 | } |
| 3257 | return tac; |
| 3258 | } |
| 3259 | |
| 3260 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3261 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3262 | try { |
| 3263 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3264 | } catch (SecurityException se) { |
| 3265 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3266 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3267 | + Binder.getCallingUid()); |
| 3268 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3269 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3270 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3271 | return null; |
| 3272 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3273 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3274 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3275 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3276 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3277 | return null; |
| 3278 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3279 | |
| 3280 | final long identity = Binder.clearCallingIdentity(); |
| 3281 | try { |
| 3282 | return phone.getMeid(); |
| 3283 | } finally { |
| 3284 | Binder.restoreCallingIdentity(identity); |
| 3285 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3286 | } |
| 3287 | |
| 3288 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3289 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3290 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3291 | String manufacturerCode = null; |
| 3292 | if (phone != null) { |
| 3293 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3294 | try { |
| 3295 | manufacturerCode = |
| 3296 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3297 | } catch (IndexOutOfBoundsException e) { |
| 3298 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3299 | return null; |
| 3300 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3301 | } |
| 3302 | return manufacturerCode; |
| 3303 | } |
| 3304 | |
| 3305 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3306 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3307 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3308 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3309 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3310 | return null; |
| 3311 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3312 | int subId = phone.getSubId(); |
| 3313 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3314 | mApp, subId, callingPackage, callingFeatureId, |
| 3315 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3316 | return null; |
| 3317 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3318 | |
| 3319 | final long identity = Binder.clearCallingIdentity(); |
| 3320 | try { |
| 3321 | return phone.getDeviceSvn(); |
| 3322 | } finally { |
| 3323 | Binder.restoreCallingIdentity(identity); |
| 3324 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3325 | } |
| 3326 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3327 | @Override |
| 3328 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3329 | final long identity = Binder.clearCallingIdentity(); |
| 3330 | try { |
| 3331 | final Phone phone = getPhone(subId); |
| 3332 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3333 | } finally { |
| 3334 | Binder.restoreCallingIdentity(identity); |
| 3335 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3336 | } |
| 3337 | |
| 3338 | @Override |
| 3339 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3340 | final long identity = Binder.clearCallingIdentity(); |
| 3341 | try { |
| 3342 | final Phone phone = getPhone(subId); |
| 3343 | return phone == null ? null : phone.getCarrierName(); |
| 3344 | } finally { |
| 3345 | Binder.restoreCallingIdentity(identity); |
| 3346 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3347 | } |
| 3348 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3349 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3350 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3351 | final long identity = Binder.clearCallingIdentity(); |
| 3352 | try { |
| 3353 | final Phone phone = getPhone(subId); |
| 3354 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3355 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3356 | } finally { |
| 3357 | Binder.restoreCallingIdentity(identity); |
| 3358 | } |
| 3359 | } |
| 3360 | |
| 3361 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3362 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3363 | final long identity = Binder.clearCallingIdentity(); |
| 3364 | try { |
| 3365 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3366 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3367 | } finally { |
| 3368 | Binder.restoreCallingIdentity(identity); |
| 3369 | } |
| 3370 | } |
| 3371 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3372 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3373 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3374 | if (!isSubscriptionMccMnc) { |
| 3375 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3376 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3377 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3378 | if (phone == null) { |
| 3379 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3380 | } |
| 3381 | final long identity = Binder.clearCallingIdentity(); |
| 3382 | try { |
| 3383 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3384 | } finally { |
| 3385 | Binder.restoreCallingIdentity(identity); |
| 3386 | } |
| 3387 | } |
| 3388 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3389 | // |
| 3390 | // Internal helper methods. |
| 3391 | // |
| 3392 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3393 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3394 | * Make sure the caller is the calling package itself |
| 3395 | * |
| 3396 | * @throws SecurityException if the caller is not the calling package |
| 3397 | */ |
| 3398 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3399 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3400 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3401 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3402 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3403 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3404 | } catch (PackageManager.NameNotFoundException e) { |
| 3405 | // packageUid is -1 |
| 3406 | } |
| 3407 | if (packageUid != callingUid) { |
| 3408 | throw new SecurityException(message + ": Package " + callingPackage |
| 3409 | + " does not belong to " + callingUid); |
| 3410 | } |
| 3411 | } |
| 3412 | |
| 3413 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3414 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3415 | * |
| 3416 | * @throws SecurityException if the caller does not have the required permission |
| 3417 | */ |
| 3418 | private void enforceModifyPermission() { |
| 3419 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3420 | } |
| 3421 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3422 | private void enforceActiveEmergencySessionPermission() { |
| 3423 | mApp.enforceCallingOrSelfPermission( |
| 3424 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3425 | } |
| 3426 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3427 | /** |
| 3428 | * Make sure the caller has the CALL_PHONE permission. |
| 3429 | * |
| 3430 | * @throws SecurityException if the caller does not have the required permission |
| 3431 | */ |
| 3432 | private void enforceCallPermission() { |
| 3433 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3434 | } |
| 3435 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3436 | private void enforceSettingsPermission() { |
| 3437 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3438 | } |
| 3439 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3440 | private void enforceRebootPermission() { |
| 3441 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3442 | } |
| 3443 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3444 | private String createTelUrl(String number) { |
| 3445 | if (TextUtils.isEmpty(number)) { |
| 3446 | return null; |
| 3447 | } |
| 3448 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3449 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3450 | } |
| 3451 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3452 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3453 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3454 | } |
| 3455 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3456 | private static void logv(String msg) { |
| 3457 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3458 | } |
| 3459 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3460 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3461 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3462 | } |
| 3463 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3464 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3465 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3466 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3467 | } |
| 3468 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3469 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3470 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3471 | final long identity = Binder.clearCallingIdentity(); |
| 3472 | try { |
| 3473 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3474 | if (phone == null) { |
| 3475 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3476 | } else { |
| 3477 | return phone.getPhoneType(); |
| 3478 | } |
| 3479 | } finally { |
| 3480 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3481 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3482 | } |
| 3483 | |
| 3484 | /** |
| 3485 | * Returns the CDMA ERI icon index to display |
| 3486 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3487 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3488 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3489 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3490 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3491 | } |
| 3492 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3493 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3494 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3495 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3496 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3497 | mApp, subId, callingPackage, callingFeatureId, |
| 3498 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3499 | return -1; |
| 3500 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3501 | |
| 3502 | final long identity = Binder.clearCallingIdentity(); |
| 3503 | try { |
| 3504 | final Phone phone = getPhone(subId); |
| 3505 | if (phone != null) { |
| 3506 | return phone.getCdmaEriIconIndex(); |
| 3507 | } else { |
| 3508 | return -1; |
| 3509 | } |
| 3510 | } finally { |
| 3511 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3512 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3513 | } |
| 3514 | |
| 3515 | /** |
| 3516 | * Returns the CDMA ERI icon mode, |
| 3517 | * 0 - ON |
| 3518 | * 1 - FLASHING |
| 3519 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3520 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3521 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3522 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3523 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3524 | } |
| 3525 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3526 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3527 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3528 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3529 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3530 | mApp, subId, callingPackage, callingFeatureId, |
| 3531 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3532 | return -1; |
| 3533 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3534 | |
| 3535 | final long identity = Binder.clearCallingIdentity(); |
| 3536 | try { |
| 3537 | final Phone phone = getPhone(subId); |
| 3538 | if (phone != null) { |
| 3539 | return phone.getCdmaEriIconMode(); |
| 3540 | } else { |
| 3541 | return -1; |
| 3542 | } |
| 3543 | } finally { |
| 3544 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3545 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3546 | } |
| 3547 | |
| 3548 | /** |
| 3549 | * Returns the CDMA ERI text, |
| 3550 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3551 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3552 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3553 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3554 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3555 | } |
| 3556 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3557 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3558 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3559 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3560 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3561 | mApp, subId, callingPackage, callingFeatureId, |
| 3562 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3563 | return null; |
| 3564 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3565 | |
| 3566 | final long identity = Binder.clearCallingIdentity(); |
| 3567 | try { |
| 3568 | final Phone phone = getPhone(subId); |
| 3569 | if (phone != null) { |
| 3570 | return phone.getCdmaEriText(); |
| 3571 | } else { |
| 3572 | return null; |
| 3573 | } |
| 3574 | } finally { |
| 3575 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3576 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3577 | } |
| 3578 | |
| 3579 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3580 | * Returns the CDMA MDN. |
| 3581 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3582 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3583 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3584 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3585 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3586 | |
| 3587 | final long identity = Binder.clearCallingIdentity(); |
| 3588 | try { |
| 3589 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3590 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3591 | return phone.getLine1Number(); |
| 3592 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3593 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3594 | return null; |
| 3595 | } |
| 3596 | } finally { |
| 3597 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3598 | } |
| 3599 | } |
| 3600 | |
| 3601 | /** |
| 3602 | * Returns the CDMA MIN. |
| 3603 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3604 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3605 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3606 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3607 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3608 | |
| 3609 | final long identity = Binder.clearCallingIdentity(); |
| 3610 | try { |
| 3611 | final Phone phone = getPhone(subId); |
| 3612 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3613 | return phone.getCdmaMin(); |
| 3614 | } else { |
| 3615 | return null; |
| 3616 | } |
| 3617 | } finally { |
| 3618 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3619 | } |
| 3620 | } |
| 3621 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3622 | @Override |
| 3623 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3624 | INumberVerificationCallback callback, String callingPackage) { |
| 3625 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3626 | != PERMISSION_GRANTED) { |
| 3627 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3628 | } |
| 3629 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3630 | |
| 3631 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3632 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3633 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3634 | + "calling package: " + callingPackage |
| 3635 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3636 | } |
| 3637 | |
| 3638 | if (range == null) { |
| 3639 | throw new NullPointerException("Range must be non-null"); |
| 3640 | } |
| 3641 | |
| 3642 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3643 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3644 | |
| 3645 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3646 | } |
| 3647 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3648 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3649 | * Returns true if CDMA provisioning needs to run. |
| 3650 | */ |
| 3651 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3652 | final long identity = Binder.clearCallingIdentity(); |
| 3653 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3654 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3655 | } finally { |
| 3656 | Binder.restoreCallingIdentity(identity); |
| 3657 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3658 | } |
| 3659 | |
| 3660 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3661 | * Sets the voice mail number of a given subId. |
| 3662 | */ |
| 3663 | @Override |
| 3664 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3665 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3666 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3667 | |
| 3668 | final long identity = Binder.clearCallingIdentity(); |
| 3669 | try { |
| 3670 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3671 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3672 | return success; |
| 3673 | } finally { |
| 3674 | Binder.restoreCallingIdentity(identity); |
| 3675 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3676 | } |
| 3677 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3678 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3679 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3680 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3681 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3682 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3683 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3684 | throw new SecurityException("caller must be system dialer"); |
| 3685 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3686 | |
| 3687 | final long identity = Binder.clearCallingIdentity(); |
| 3688 | try { |
| 3689 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3690 | if (phoneAccountHandle == null) { |
| 3691 | return null; |
| 3692 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3693 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3694 | } finally { |
| 3695 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3696 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3697 | } |
| 3698 | |
| 3699 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3700 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3701 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3702 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3703 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3704 | mApp, subId, callingPackage, callingFeatureId, |
| 3705 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3706 | return null; |
| 3707 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3708 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3709 | final long identity = Binder.clearCallingIdentity(); |
| 3710 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3711 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3712 | } finally { |
| 3713 | Binder.restoreCallingIdentity(identity); |
| 3714 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3715 | } |
| 3716 | |
| 3717 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3718 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3719 | VisualVoicemailSmsFilterSettings settings) { |
| 3720 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3721 | |
| 3722 | final long identity = Binder.clearCallingIdentity(); |
| 3723 | try { |
| 3724 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3725 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3726 | } finally { |
| 3727 | Binder.restoreCallingIdentity(identity); |
| 3728 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3729 | } |
| 3730 | |
| 3731 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3732 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3733 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3734 | |
| 3735 | final long identity = Binder.clearCallingIdentity(); |
| 3736 | try { |
| 3737 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3738 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3739 | } finally { |
| 3740 | Binder.restoreCallingIdentity(identity); |
| 3741 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3742 | } |
| 3743 | |
| 3744 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3745 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3746 | String callingPackage, int subId) { |
| 3747 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3748 | |
| 3749 | final long identity = Binder.clearCallingIdentity(); |
| 3750 | try { |
| 3751 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3752 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3753 | } finally { |
| 3754 | Binder.restoreCallingIdentity(identity); |
| 3755 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3756 | } |
| 3757 | |
| 3758 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3759 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3760 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3761 | |
| 3762 | final long identity = Binder.clearCallingIdentity(); |
| 3763 | try { |
| 3764 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3765 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3766 | } finally { |
| 3767 | Binder.restoreCallingIdentity(identity); |
| 3768 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3769 | } |
| 3770 | |
| 3771 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3772 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3773 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3774 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3775 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3776 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3777 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3778 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3779 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3780 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3781 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3782 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3783 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3784 | * Sets the voice activation state of a given subId. |
| 3785 | */ |
| 3786 | @Override |
| 3787 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3788 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3789 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3790 | |
| 3791 | final long identity = Binder.clearCallingIdentity(); |
| 3792 | try { |
| 3793 | final Phone phone = getPhone(subId); |
| 3794 | if (phone != null) { |
| 3795 | phone.setVoiceActivationState(activationState); |
| 3796 | } else { |
| 3797 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3798 | } |
| 3799 | } finally { |
| 3800 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3801 | } |
| 3802 | } |
| 3803 | |
| 3804 | /** |
| 3805 | * Sets the data activation state of a given subId. |
| 3806 | */ |
| 3807 | @Override |
| 3808 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3809 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3810 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3811 | |
| 3812 | final long identity = Binder.clearCallingIdentity(); |
| 3813 | try { |
| 3814 | final Phone phone = getPhone(subId); |
| 3815 | if (phone != null) { |
| 3816 | phone.setDataActivationState(activationState); |
| 3817 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3818 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3819 | } |
| 3820 | } finally { |
| 3821 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3822 | } |
| 3823 | } |
| 3824 | |
| 3825 | /** |
| 3826 | * Returns the voice activation state of a given subId. |
| 3827 | */ |
| 3828 | @Override |
| 3829 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3830 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3831 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3832 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3833 | final long identity = Binder.clearCallingIdentity(); |
| 3834 | try { |
| 3835 | if (phone != null) { |
| 3836 | return phone.getVoiceActivationState(); |
| 3837 | } else { |
| 3838 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3839 | } |
| 3840 | } finally { |
| 3841 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3842 | } |
| 3843 | } |
| 3844 | |
| 3845 | /** |
| 3846 | * Returns the data activation state of a given subId. |
| 3847 | */ |
| 3848 | @Override |
| 3849 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3850 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3851 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3852 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3853 | final long identity = Binder.clearCallingIdentity(); |
| 3854 | try { |
| 3855 | if (phone != null) { |
| 3856 | return phone.getDataActivationState(); |
| 3857 | } else { |
| 3858 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3859 | } |
| 3860 | } finally { |
| 3861 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3862 | } |
| 3863 | } |
| 3864 | |
| 3865 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3866 | * Returns the unread count of voicemails for a subId |
| 3867 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3868 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3869 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3870 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3871 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3872 | mApp, subId, callingPackage, callingFeatureId, |
| 3873 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3874 | return 0; |
| 3875 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3876 | final long identity = Binder.clearCallingIdentity(); |
| 3877 | try { |
| 3878 | final Phone phone = getPhone(subId); |
| 3879 | if (phone != null) { |
| 3880 | return phone.getVoiceMessageCount(); |
| 3881 | } else { |
| 3882 | return 0; |
| 3883 | } |
| 3884 | } finally { |
| 3885 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3886 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3887 | } |
| 3888 | |
| 3889 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3890 | * returns true, if the device is in a state where both voice and data |
| 3891 | * are supported simultaneously. This can change based on location or network condition. |
| 3892 | */ |
| 3893 | @Override |
| 3894 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3895 | final long identity = Binder.clearCallingIdentity(); |
| 3896 | try { |
| 3897 | final Phone phone = getPhone(subId); |
| 3898 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3899 | } finally { |
| 3900 | Binder.restoreCallingIdentity(identity); |
| 3901 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3902 | } |
| 3903 | |
| 3904 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3905 | * Send the dialer code if called from the current default dialer or the caller has |
| 3906 | * carrier privilege. |
| 3907 | * @param inputCode The dialer code to send |
| 3908 | */ |
| 3909 | @Override |
| 3910 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3911 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3912 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3913 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3914 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3915 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3916 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3917 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3918 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3919 | |
| 3920 | final long identity = Binder.clearCallingIdentity(); |
| 3921 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3922 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3923 | } finally { |
| 3924 | Binder.restoreCallingIdentity(identity); |
| 3925 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3926 | } |
| 3927 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3928 | @Override |
| 3929 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3930 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3931 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3932 | mApp, subId, "getNetworkSelectionMode"); |
| 3933 | final long identity = Binder.clearCallingIdentity(); |
| 3934 | try { |
| 3935 | if (!isActiveSubscription(subId)) { |
| 3936 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3937 | } |
| 3938 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3939 | } finally { |
| 3940 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3941 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3942 | } |
| 3943 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3944 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3945 | public boolean isInEmergencySmsMode() { |
| 3946 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3947 | final long identity = Binder.clearCallingIdentity(); |
| 3948 | try { |
| 3949 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3950 | if (phone.isInEmergencySmsMode()) { |
| 3951 | return true; |
| 3952 | } |
| 3953 | } |
| 3954 | } finally { |
| 3955 | Binder.restoreCallingIdentity(identity); |
| 3956 | } |
| 3957 | return false; |
| 3958 | } |
| 3959 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3960 | /** |
| 3961 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3962 | * @param subId The subscription to use to check the configuration. |
| 3963 | * @param c The callback that will be used to send the result. |
| 3964 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3965 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3966 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3967 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3968 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3969 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3970 | |
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).addRegistrationCallbackForSubscription(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 unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback 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, "unregisterImsRegistrationCallback"); |
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 | final long token = Binder.clearCallingIdentity(); |
| 4000 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4001 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 4002 | .removeRegistrationCallbackForSubscription(c, subId); |
| 4003 | } catch (ImsException e) { |
| 4004 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4005 | + "is inactive, ignoring unregister."); |
| 4006 | // If the subscription is no longer active, just return, since the callback |
| 4007 | // will already have been removed internally. |
| 4008 | } finally { |
| 4009 | Binder.restoreCallingIdentity(token); |
| 4010 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4011 | } |
| 4012 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4013 | /** |
| 4014 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4015 | */ |
| 4016 | @Override |
| 4017 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4018 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4019 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4020 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4021 | "IMS not available on device."); |
| 4022 | } |
| 4023 | final long token = Binder.clearCallingIdentity(); |
| 4024 | try { |
| 4025 | Phone phone = getPhone(subId); |
| 4026 | if (phone == null) { |
| 4027 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4028 | + subId + "'"); |
| 4029 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4030 | } |
| 4031 | phone.getImsRegistrationState(regState -> { |
| 4032 | try { |
| 4033 | consumer.accept((regState == null) |
| 4034 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4035 | } catch (RemoteException e) { |
| 4036 | // Ignore if the remote process is no longer available to call back. |
| 4037 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4038 | } |
| 4039 | }); |
| 4040 | } finally { |
| 4041 | Binder.restoreCallingIdentity(token); |
| 4042 | } |
| 4043 | } |
| 4044 | |
| 4045 | /** |
| 4046 | * Get the transport type for the IMS service registration state. |
| 4047 | */ |
| 4048 | @Override |
| 4049 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4050 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4051 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4052 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4053 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4054 | "IMS not available on device."); |
| 4055 | } |
| 4056 | final long token = Binder.clearCallingIdentity(); |
| 4057 | try { |
| 4058 | Phone phone = getPhone(subId); |
| 4059 | if (phone == null) { |
| 4060 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4061 | + subId + "'"); |
| 4062 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4063 | } |
| 4064 | phone.getImsRegistrationTech(regTech -> { |
| 4065 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4066 | int regTechConverted = (regTech == null) |
| 4067 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4068 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4069 | regTechConverted); |
| 4070 | try { |
| 4071 | consumer.accept(regTechConverted); |
| 4072 | } catch (RemoteException e) { |
| 4073 | // Ignore if the remote process is no longer available to call back. |
| 4074 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4075 | } |
| 4076 | }); |
| 4077 | } finally { |
| 4078 | Binder.restoreCallingIdentity(token); |
| 4079 | } |
| 4080 | } |
| 4081 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4082 | /** |
| 4083 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4084 | * @param subId The subscription to use to check the configuration. |
| 4085 | * @param c The callback that will be used to send the result. |
| 4086 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4087 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4088 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4089 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4090 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4091 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4092 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4093 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4094 | "IMS not available on device."); |
| 4095 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4096 | final long token = Binder.clearCallingIdentity(); |
| 4097 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4098 | int slotId = getSlotIndexOrException(subId); |
| 4099 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4100 | ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4101 | } catch (ImsException e) { |
| 4102 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4103 | } finally { |
| 4104 | Binder.restoreCallingIdentity(token); |
| 4105 | } |
| 4106 | } |
| 4107 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4108 | /** |
| 4109 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4110 | * @param subId The subscription to use to check the configuration. |
| 4111 | * @param c The callback that will be used to send the result. |
| 4112 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4113 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4114 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4115 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4116 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4117 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4118 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4119 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4120 | |
| 4121 | final long token = Binder.clearCallingIdentity(); |
| 4122 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4123 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4124 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4125 | } catch (ImsException e) { |
| 4126 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4127 | + "is inactive, ignoring unregister."); |
| 4128 | // If the subscription is no longer active, just return, since the callback |
| 4129 | // will already have been removed internally. |
| 4130 | } finally { |
| 4131 | Binder.restoreCallingIdentity(token); |
| 4132 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4133 | } |
| 4134 | |
| 4135 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4136 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4137 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4138 | final long token = Binder.clearCallingIdentity(); |
| 4139 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4140 | int slotId = getSlotIndexOrException(subId); |
| 4141 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4142 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4143 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4144 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4145 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4146 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4147 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4148 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4149 | } finally { |
| 4150 | Binder.restoreCallingIdentity(token); |
| 4151 | } |
| 4152 | } |
| 4153 | |
| 4154 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4155 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4156 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4157 | final long token = Binder.clearCallingIdentity(); |
| 4158 | try { |
| 4159 | Phone phone = getPhone(subId); |
| 4160 | if (phone == null) return false; |
| 4161 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4162 | } catch (com.android.ims.ImsException e) { |
| 4163 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4164 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4165 | } finally { |
| 4166 | Binder.restoreCallingIdentity(token); |
| 4167 | } |
| 4168 | } |
| 4169 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4170 | /** |
| 4171 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4172 | * subscription. |
| 4173 | * @param subId The subscription to use to check the configuration. |
| 4174 | * @param callback The callback that will be used to send the result. |
| 4175 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4176 | * @param transportType The transport type of the MmTelFeature capability. |
| 4177 | */ |
| 4178 | @Override |
| 4179 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4180 | int transportType) { |
| 4181 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 4182 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4183 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4184 | "IMS not available on device."); |
| 4185 | } |
| 4186 | final long token = Binder.clearCallingIdentity(); |
| 4187 | try { |
| 4188 | int slotId = getSlotIndex(subId); |
| 4189 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4190 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4191 | + subId + "'"); |
| 4192 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4193 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4194 | verifyImsMmTelConfiguredOrThrow(slotId); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4195 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4196 | transportType, aBoolean -> { |
| 4197 | try { |
| 4198 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4199 | } catch (RemoteException e) { |
| 4200 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4201 | + "running. Ignore"); |
| 4202 | } |
| 4203 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4204 | } catch (ImsException e) { |
| 4205 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4206 | } finally { |
| 4207 | Binder.restoreCallingIdentity(token); |
| 4208 | } |
| 4209 | } |
| 4210 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4211 | /** |
| 4212 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4213 | * @param subId The subscription to use to check the configuration. |
| 4214 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4215 | @Override |
| 4216 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4217 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4218 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4219 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4220 | final long token = Binder.clearCallingIdentity(); |
| 4221 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4222 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4223 | // 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] | 4224 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4225 | } catch (ImsException e) { |
| 4226 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4227 | } finally { |
| 4228 | Binder.restoreCallingIdentity(token); |
| 4229 | } |
| 4230 | } |
| 4231 | |
| 4232 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4233 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4234 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4235 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4236 | final long identity = Binder.clearCallingIdentity(); |
| 4237 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4238 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4239 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4240 | // 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] | 4241 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4242 | } catch (ImsException e) { |
| 4243 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4244 | } finally { |
| 4245 | Binder.restoreCallingIdentity(identity); |
| 4246 | } |
| 4247 | } |
| 4248 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4249 | /** |
| 4250 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4251 | * @param subId The subscription to use to check the configuration. |
| 4252 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4253 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4254 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4255 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4256 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4257 | final long identity = Binder.clearCallingIdentity(); |
| 4258 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4259 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4260 | // 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] | 4261 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4262 | } catch (ImsException e) { |
| 4263 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4264 | } finally { |
| 4265 | Binder.restoreCallingIdentity(identity); |
| 4266 | } |
| 4267 | } |
| 4268 | |
| 4269 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4270 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4271 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4272 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4273 | final long identity = Binder.clearCallingIdentity(); |
| 4274 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4275 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4276 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4277 | // 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] | 4278 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4279 | } catch (ImsException e) { |
| 4280 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4281 | } finally { |
| 4282 | Binder.restoreCallingIdentity(identity); |
| 4283 | } |
| 4284 | } |
| 4285 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4286 | /** |
| 4287 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4288 | * @param subId The subscription to use to check the configuration. |
| 4289 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4290 | @Override |
| 4291 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4292 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4293 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4294 | final long identity = Binder.clearCallingIdentity(); |
| 4295 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4296 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4297 | // 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] | 4298 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4299 | } catch (ImsException e) { |
| 4300 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4301 | } finally { |
| 4302 | Binder.restoreCallingIdentity(identity); |
| 4303 | } |
| 4304 | } |
| 4305 | |
| 4306 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4307 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4308 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4309 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4310 | final long identity = Binder.clearCallingIdentity(); |
| 4311 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4312 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4313 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4314 | // 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] | 4315 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4316 | } catch (ImsException e) { |
| 4317 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4318 | } finally { |
| 4319 | Binder.restoreCallingIdentity(identity); |
| 4320 | } |
| 4321 | } |
| 4322 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4323 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4324 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4325 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4326 | * @param subId The subscription to use to check the configuration. |
| 4327 | */ |
| 4328 | @Override |
| 4329 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4330 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4331 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4332 | final long identity = Binder.clearCallingIdentity(); |
| 4333 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4334 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4335 | // 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] | 4336 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4337 | } catch (ImsException e) { |
| 4338 | throw new ServiceSpecificException(e.getCode()); |
| 4339 | } finally { |
| 4340 | Binder.restoreCallingIdentity(identity); |
| 4341 | } |
| 4342 | } |
| 4343 | |
| 4344 | /** |
| 4345 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4346 | * Requires MODIFY_PHONE_STATE permission. |
| 4347 | * @param subId The subscription to use to check the configuration. |
| 4348 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4349 | * false otherwise |
| 4350 | */ |
| 4351 | @Override |
| 4352 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4353 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4354 | "setCrossSimCallingEnabled"); |
| 4355 | final long identity = Binder.clearCallingIdentity(); |
| 4356 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4357 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4358 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4359 | // 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] | 4360 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4361 | } catch (ImsException e) { |
| 4362 | throw new ServiceSpecificException(e.getCode()); |
| 4363 | } finally { |
| 4364 | Binder.restoreCallingIdentity(identity); |
| 4365 | } |
| 4366 | } |
| 4367 | |
| 4368 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4369 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4370 | * @param subId The subscription to use to check the configuration. |
| 4371 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4372 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4373 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4374 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4375 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4376 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4377 | final long identity = Binder.clearCallingIdentity(); |
| 4378 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4379 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4380 | // 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] | 4381 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4382 | } catch (ImsException e) { |
| 4383 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4384 | } finally { |
| 4385 | Binder.restoreCallingIdentity(identity); |
| 4386 | } |
| 4387 | } |
| 4388 | |
| 4389 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4390 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4391 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4392 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4393 | final long identity = Binder.clearCallingIdentity(); |
| 4394 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4395 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4396 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4397 | // 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] | 4398 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4399 | } catch (ImsException e) { |
| 4400 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4401 | } finally { |
| 4402 | Binder.restoreCallingIdentity(identity); |
| 4403 | } |
| 4404 | } |
| 4405 | |
| 4406 | @Override |
| 4407 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4408 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4409 | "setVoWiFiNonPersistent"); |
| 4410 | final long identity = Binder.clearCallingIdentity(); |
| 4411 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4412 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4413 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4414 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4415 | } catch (ImsException e) { |
| 4416 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4417 | } finally { |
| 4418 | Binder.restoreCallingIdentity(identity); |
| 4419 | } |
| 4420 | } |
| 4421 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4422 | /** |
| 4423 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4424 | * @param subId The subscription to use to check the configuration. |
| 4425 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4426 | @Override |
| 4427 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4428 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4429 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4430 | final long identity = Binder.clearCallingIdentity(); |
| 4431 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4432 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4433 | // 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] | 4434 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4435 | } catch (ImsException e) { |
| 4436 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4437 | } finally { |
| 4438 | Binder.restoreCallingIdentity(identity); |
| 4439 | } |
| 4440 | } |
| 4441 | |
| 4442 | @Override |
| 4443 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4444 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4445 | "setVoWiFiModeSetting"); |
| 4446 | final long identity = Binder.clearCallingIdentity(); |
| 4447 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4448 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4449 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4450 | // 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] | 4451 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4452 | } catch (ImsException e) { |
| 4453 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4454 | } finally { |
| 4455 | Binder.restoreCallingIdentity(identity); |
| 4456 | } |
| 4457 | } |
| 4458 | |
| 4459 | @Override |
| 4460 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4461 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4462 | final long identity = Binder.clearCallingIdentity(); |
| 4463 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4464 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4465 | // 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] | 4466 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4467 | } catch (ImsException e) { |
| 4468 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4469 | } finally { |
| 4470 | Binder.restoreCallingIdentity(identity); |
| 4471 | } |
| 4472 | } |
| 4473 | |
| 4474 | @Override |
| 4475 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4476 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4477 | "setVoWiFiRoamingModeSetting"); |
| 4478 | final long identity = Binder.clearCallingIdentity(); |
| 4479 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4480 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4481 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4482 | // 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] | 4483 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4484 | } catch (ImsException e) { |
| 4485 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4486 | } finally { |
| 4487 | Binder.restoreCallingIdentity(identity); |
| 4488 | } |
| 4489 | } |
| 4490 | |
| 4491 | @Override |
| 4492 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4493 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4494 | "setRttCapabilityEnabled"); |
| 4495 | final long identity = Binder.clearCallingIdentity(); |
| 4496 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4497 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4498 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4499 | // 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] | 4500 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4501 | } catch (ImsException e) { |
| 4502 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4503 | } finally { |
| 4504 | Binder.restoreCallingIdentity(identity); |
| 4505 | } |
| 4506 | } |
| 4507 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4508 | /** |
| 4509 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4510 | * @param subId The subscription to use to check the configuration. |
| 4511 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4512 | @Override |
| 4513 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4514 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4515 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4516 | final long identity = Binder.clearCallingIdentity(); |
| 4517 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4518 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4519 | // 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] | 4520 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4521 | } catch (ImsException e) { |
| 4522 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4523 | } finally { |
| 4524 | Binder.restoreCallingIdentity(identity); |
| 4525 | } |
| 4526 | } |
| 4527 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4528 | @Override |
| 4529 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4530 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4531 | final long identity = Binder.clearCallingIdentity(); |
| 4532 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4533 | if (!isImsAvailableOnDevice()) { |
| 4534 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4535 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4536 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4537 | int slotId = getSlotIndexOrException(subId); |
| 4538 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4539 | ImsManager.getInstance(mApp, slotId) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4540 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4541 | } catch (ImsException e) { |
| 4542 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4543 | } finally { |
| 4544 | Binder.restoreCallingIdentity(identity); |
| 4545 | } |
| 4546 | } |
| 4547 | |
| 4548 | @Override |
| 4549 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4550 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4551 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4552 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4553 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4554 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4555 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4556 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4557 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4558 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4559 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4560 | + "is inactive, ignoring unregister."); |
| 4561 | // If the subscription is no longer active, just return, since the callback will already |
| 4562 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4563 | } finally { |
| 4564 | Binder.restoreCallingIdentity(identity); |
| 4565 | } |
| 4566 | } |
| 4567 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4568 | |
| 4569 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4570 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4571 | message); |
| 4572 | } |
| 4573 | |
| 4574 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4575 | boolean isMmtelCapability) { |
| 4576 | Phone phone = getPhone(subId); |
| 4577 | if (phone == null) { |
| 4578 | loge("phone instance null for subid " + subId); |
| 4579 | return false; |
| 4580 | } |
| 4581 | if (isMmtelCapability) { |
| 4582 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4583 | return false; |
| 4584 | } |
| 4585 | } else { |
| 4586 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4587 | return false; |
| 4588 | } |
| 4589 | } |
| 4590 | return true; |
| 4591 | } |
| 4592 | |
| 4593 | @Override |
| 4594 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4595 | boolean isProvisioned) { |
| 4596 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4597 | |
| 4598 | final long identity = Binder.clearCallingIdentity(); |
| 4599 | try { |
| 4600 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4601 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4602 | return; |
| 4603 | } |
| 4604 | |
| 4605 | // this capability requires provisioning, route to the correct API. |
| 4606 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4607 | switch (capability) { |
| 4608 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4609 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4610 | ims.setEabProvisioned(isProvisioned); |
| 4611 | break; |
| 4612 | default: { |
| 4613 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4614 | + "rcs capability '" + capability + "', which does not require " |
| 4615 | + "provisioning."); |
| 4616 | } |
| 4617 | } |
| 4618 | } finally { |
| 4619 | Binder.restoreCallingIdentity(identity); |
| 4620 | } |
| 4621 | |
| 4622 | } |
| 4623 | |
| 4624 | |
| 4625 | @Override |
| 4626 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4627 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4628 | final long identity = Binder.clearCallingIdentity(); |
| 4629 | try { |
| 4630 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4631 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4632 | return true; |
| 4633 | } |
| 4634 | |
| 4635 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4636 | switch (capability) { |
| 4637 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4638 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4639 | return ims.isEabProvisionedOnDevice(); |
| 4640 | |
| 4641 | default: { |
| 4642 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4643 | + "capability '" + capability + "', which does not require " |
| 4644 | + "provisioning."); |
| 4645 | } |
| 4646 | } |
| 4647 | |
| 4648 | } finally { |
| 4649 | Binder.restoreCallingIdentity(identity); |
| 4650 | } |
| 4651 | } |
| 4652 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4653 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4654 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4655 | boolean isProvisioned) { |
| 4656 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4657 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE |
| 4658 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4659 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4660 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4661 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4662 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4663 | final long identity = Binder.clearCallingIdentity(); |
| 4664 | try { |
| 4665 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4666 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4667 | return; |
| 4668 | } |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4669 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4670 | || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
| 4671 | loge("setImsProvisioningStatusForCapability: called for technology that does " |
| 4672 | + "not support provisioning - " + tech); |
| 4673 | return; |
| 4674 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4675 | |
| 4676 | // this capability requires provisioning, route to the correct API. |
| 4677 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4678 | switch (capability) { |
| 4679 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4680 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4681 | ims.setVolteProvisioned(isProvisioned); |
| 4682 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4683 | ims.setWfcProvisioned(isProvisioned); |
| 4684 | } |
| 4685 | break; |
| 4686 | } |
| 4687 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4688 | // There is currently no difference in VT provisioning type. |
| 4689 | ims.setVtProvisioned(isProvisioned); |
| 4690 | break; |
| 4691 | } |
| 4692 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4693 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4694 | // change the capability of the feature instead if needed. |
| 4695 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4696 | == isProvisioned) { |
| 4697 | // No change in provisioning. |
| 4698 | return; |
| 4699 | } |
| 4700 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4701 | try { |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4702 | ims.changeMmTelCapability(isProvisioned, capability, tech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4703 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4704 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4705 | + ", Exception" + e.getMessage()); |
| 4706 | } |
| 4707 | break; |
| 4708 | } |
| 4709 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4710 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4711 | + "MmTel capability '" + capability + "', which does not require " |
| 4712 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4713 | } |
| 4714 | } |
| 4715 | |
| 4716 | } finally { |
| 4717 | Binder.restoreCallingIdentity(identity); |
| 4718 | } |
| 4719 | } |
| 4720 | |
| 4721 | @Override |
| 4722 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4723 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4724 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE |
| 4725 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4726 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4727 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4728 | } |
| 4729 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4730 | final long identity = Binder.clearCallingIdentity(); |
| 4731 | try { |
| 4732 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4733 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4734 | return true; |
| 4735 | } |
| 4736 | |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4737 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4738 | || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
| 4739 | loge("getImsProvisioningStatusForCapability: called for technology that does " |
| 4740 | + "not support provisioning - " + tech); |
| 4741 | return true; |
| 4742 | } |
| 4743 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4744 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4745 | switch (capability) { |
| 4746 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4747 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4748 | return ims.isVolteProvisionedOnDevice(); |
| 4749 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4750 | return ims.isWfcProvisionedOnDevice(); |
| 4751 | } |
| 4752 | // This should never happen, since we are checking tech above to make sure it |
| 4753 | // is either LTE or IWLAN. |
| 4754 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4755 | + "capability."); |
| 4756 | } |
| 4757 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4758 | // There is currently no difference in VT provisioning type. |
| 4759 | return ims.isVtProvisionedOnDevice(); |
| 4760 | } |
| 4761 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4762 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4763 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4764 | } |
| 4765 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4766 | throw new IllegalArgumentException( |
| 4767 | "Tried to get provisioning for MmTel capability '" + capability |
| 4768 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4769 | } |
| 4770 | } |
| 4771 | |
| 4772 | } finally { |
| 4773 | Binder.restoreCallingIdentity(identity); |
| 4774 | } |
| 4775 | } |
| 4776 | |
| 4777 | @Override |
| 4778 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4779 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4780 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4781 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4782 | } |
| 4783 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4784 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4785 | return (provisionedBits & capability) > 0; |
| 4786 | } |
| 4787 | |
| 4788 | @Override |
| 4789 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4790 | boolean isProvisioned) { |
| 4791 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4792 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4793 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4794 | } |
| 4795 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4796 | "setProvisioningStatusForCapability"); |
| 4797 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4798 | // If the current provisioning status for capability already matches isProvisioned, |
| 4799 | // do nothing. |
| 4800 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4801 | return; |
| 4802 | } |
| 4803 | if (isProvisioned) { |
| 4804 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4805 | } else { |
| 4806 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4807 | } |
| 4808 | } |
| 4809 | |
| 4810 | /** |
| 4811 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4812 | * technology. The bitfield should mirror the bitfield defined by |
| 4813 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4814 | */ |
| 4815 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4816 | String key = getMmTelProvisioningKey(subId, tech); |
| 4817 | // Default is no capabilities are provisioned. |
| 4818 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4819 | } |
| 4820 | |
| 4821 | /** |
| 4822 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4823 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4824 | * technology specified. |
| 4825 | * |
| 4826 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4827 | */ |
| 4828 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4829 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4830 | String key = getMmTelProvisioningKey(subId, tech); |
| 4831 | editor.putInt(key, newField); |
| 4832 | editor.commit(); |
| 4833 | } |
| 4834 | |
| 4835 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4836 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4837 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4838 | } |
| 4839 | |
| 4840 | /** |
| 4841 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4842 | * carrier associated with the subscription id. |
| 4843 | */ |
| 4844 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4845 | int capability) { |
| 4846 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4847 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4848 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4849 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4850 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4851 | false); |
| 4852 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4853 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4854 | |
| 4855 | // First check to make sure that the capability requires provisioning. |
| 4856 | switch (capability) { |
| 4857 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4858 | // intentional fallthrough |
| 4859 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4860 | if (requireVoiceVtProvisioning) { |
| 4861 | // Voice and Video requires provisioning |
| 4862 | return true; |
| 4863 | } |
| 4864 | break; |
| 4865 | } |
| 4866 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4867 | if (requireUtProvisioning) { |
| 4868 | // UT requires provisioning |
| 4869 | return true; |
| 4870 | } |
| 4871 | break; |
| 4872 | } |
| 4873 | } |
| 4874 | return false; |
| 4875 | } |
| 4876 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4877 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4878 | int capability) { |
| 4879 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4880 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4881 | |
| 4882 | boolean requireRcsProvisioning = c.getBoolean( |
| 4883 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4884 | |
| 4885 | // First check to make sure that the capability requires provisioning. |
| 4886 | switch (capability) { |
| 4887 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4888 | // intentional fallthrough |
| 4889 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4890 | if (requireRcsProvisioning) { |
| 4891 | // OPTION or PRESENCE requires provisioning |
| 4892 | return true; |
| 4893 | } |
| 4894 | break; |
| 4895 | } |
| 4896 | } |
| 4897 | return false; |
| 4898 | } |
| 4899 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4900 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4901 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4902 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4903 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4904 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4905 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4906 | final long identity = Binder.clearCallingIdentity(); |
| 4907 | try { |
| 4908 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4909 | int slotId = getSlotIndex(subId); |
| 4910 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4911 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4912 | + subId + "' for key:" + key); |
| 4913 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4914 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4915 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4916 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4917 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4918 | + subId + "' for key:" + key); |
| 4919 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4920 | } finally { |
| 4921 | Binder.restoreCallingIdentity(identity); |
| 4922 | } |
| 4923 | } |
| 4924 | |
| 4925 | @Override |
| 4926 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4927 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4928 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4929 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4930 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4931 | final long identity = Binder.clearCallingIdentity(); |
| 4932 | try { |
| 4933 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4934 | int slotId = getSlotIndex(subId); |
| 4935 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4936 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4937 | + subId + "' for key:" + key); |
| 4938 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4939 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4940 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4941 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4942 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4943 | + subId + "' for key:" + key); |
| 4944 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4945 | } finally { |
| 4946 | Binder.restoreCallingIdentity(identity); |
| 4947 | } |
| 4948 | } |
| 4949 | |
| 4950 | @Override |
| 4951 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4952 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4953 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4954 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4955 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4956 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4957 | final long identity = Binder.clearCallingIdentity(); |
| 4958 | try { |
| 4959 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4960 | int slotId = getSlotIndex(subId); |
| 4961 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4962 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4963 | + subId + "' for key:" + key); |
| 4964 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4965 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4966 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4967 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4968 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4969 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4970 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4971 | } finally { |
| 4972 | Binder.restoreCallingIdentity(identity); |
| 4973 | } |
| 4974 | } |
| 4975 | |
| 4976 | @Override |
| 4977 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4978 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4979 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4980 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4981 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4982 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4983 | final long identity = Binder.clearCallingIdentity(); |
| 4984 | try { |
| 4985 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4986 | int slotId = getSlotIndex(subId); |
| 4987 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4988 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4989 | + subId + "' for key:" + key); |
| 4990 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4991 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4992 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4993 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4994 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4995 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4996 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4997 | } finally { |
| 4998 | Binder.restoreCallingIdentity(identity); |
| 4999 | } |
| 5000 | } |
| 5001 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5002 | /** |
| 5003 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5004 | * for the given slot ID or no ImsResolver instance has been created. |
| 5005 | * @param slotId The slot ID that the IMS service is created for. |
| 5006 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5007 | */ |
| 5008 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5009 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5010 | ImsFeature.FEATURE_MMTEL)) { |
| 5011 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5012 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5013 | } |
| 5014 | } |
| 5015 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5016 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5017 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5018 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5019 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5020 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5021 | } |
| 5022 | return slotId; |
| 5023 | } |
| 5024 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5025 | private int getSlotIndex(int subId) { |
| 5026 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5027 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5028 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5029 | } |
| 5030 | return slotId; |
| 5031 | } |
| 5032 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5033 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5034 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5035 | */ |
| 5036 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5037 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5038 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5039 | try { |
| 5040 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5041 | } catch (SecurityException se) { |
| 5042 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5043 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5044 | + Binder.getCallingUid()); |
| 5045 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5046 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5047 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5048 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5049 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5050 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5051 | mApp, subId, callingPackage, callingFeatureId, |
| 5052 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5053 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5054 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5055 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5056 | final long identity = Binder.clearCallingIdentity(); |
| 5057 | try { |
| 5058 | final Phone phone = getPhone(subId); |
| 5059 | if (phone != null) { |
| 5060 | return phone.getServiceState().getDataNetworkType(); |
| 5061 | } else { |
| 5062 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5063 | } |
| 5064 | } finally { |
| 5065 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5066 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5067 | } |
| 5068 | |
| 5069 | /** |
| 5070 | * Returns the data network type |
| 5071 | */ |
| 5072 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5073 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5074 | return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(), |
| 5075 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5076 | } |
| 5077 | |
| 5078 | /** |
| 5079 | * Returns the data network type for a subId |
| 5080 | */ |
| 5081 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5082 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5083 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5084 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5085 | mApp, subId, callingPackage, callingFeatureId, |
| 5086 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5087 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5088 | } |
| 5089 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5090 | final long identity = Binder.clearCallingIdentity(); |
| 5091 | try { |
| 5092 | final Phone phone = getPhone(subId); |
| 5093 | if (phone != null) { |
| 5094 | return phone.getServiceState().getDataNetworkType(); |
| 5095 | } else { |
| 5096 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5097 | } |
| 5098 | } finally { |
| 5099 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5100 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5101 | } |
| 5102 | |
| 5103 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5104 | * Returns the Voice network type for a subId |
| 5105 | */ |
| 5106 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5107 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5108 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5109 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5110 | mApp, subId, callingPackage, callingFeatureId, |
| 5111 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5112 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5113 | } |
| 5114 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5115 | final long identity = Binder.clearCallingIdentity(); |
| 5116 | try { |
| 5117 | final Phone phone = getPhone(subId); |
| 5118 | if (phone != null) { |
| 5119 | return phone.getServiceState().getVoiceNetworkType(); |
| 5120 | } else { |
| 5121 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5122 | } |
| 5123 | } finally { |
| 5124 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5125 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5126 | } |
| 5127 | |
| 5128 | /** |
| 5129 | * @return true if a ICC card is present |
| 5130 | */ |
| 5131 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5132 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5133 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 5134 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5135 | } |
| 5136 | |
| 5137 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5138 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5139 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5140 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5141 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5142 | final long identity = Binder.clearCallingIdentity(); |
| 5143 | try { |
| 5144 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5145 | if (phone != null) { |
| 5146 | return phone.getIccCard().hasIccCard(); |
| 5147 | } else { |
| 5148 | return false; |
| 5149 | } |
| 5150 | } finally { |
| 5151 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5152 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5153 | } |
| 5154 | |
| 5155 | /** |
| 5156 | * Return if the current radio is LTE on CDMA. This |
| 5157 | * is a tri-state return value as for a period of time |
| 5158 | * the mode may be unknown. |
| 5159 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5160 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5161 | * @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] | 5162 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5163 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5164 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5165 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5166 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5167 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5168 | } |
| 5169 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5170 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5171 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5172 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5173 | try { |
| 5174 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5175 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5176 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5177 | } |
| 5178 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5179 | final long identity = Binder.clearCallingIdentity(); |
| 5180 | try { |
| 5181 | final Phone phone = getPhone(subId); |
| 5182 | if (phone == null) { |
| 5183 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5184 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5185 | return TelephonyProperties.lte_on_cdma_device() |
| 5186 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5187 | } |
| 5188 | } finally { |
| 5189 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5190 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5191 | } |
| 5192 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5193 | /** |
| 5194 | * {@hide} |
| 5195 | * Returns Default subId, 0 in the case of single standby. |
| 5196 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5197 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5198 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5199 | } |
| 5200 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5201 | private int getSlotForDefaultSubscription() { |
| 5202 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 5203 | } |
| 5204 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5205 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5206 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5207 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5208 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5209 | private boolean isActiveSubscription(int subId) { |
| 5210 | return mSubscriptionController.isActiveSubId(subId); |
| 5211 | } |
| 5212 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5213 | /** |
| 5214 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5215 | */ |
| 5216 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5217 | final long identity = Binder.clearCallingIdentity(); |
| 5218 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5219 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5220 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5221 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5222 | } finally { |
| 5223 | Binder.restoreCallingIdentity(identity); |
| 5224 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5225 | } |
| 5226 | |
| 5227 | /** |
| 5228 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5229 | */ |
| 5230 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5231 | final long identity = Binder.clearCallingIdentity(); |
| 5232 | try { |
| 5233 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5234 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5235 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5236 | } finally { |
| 5237 | Binder.restoreCallingIdentity(identity); |
| 5238 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5239 | } |
| 5240 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5241 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5242 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5243 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5244 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5245 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5246 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 5247 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 5248 | if (phoneId == -1) { |
| 5249 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 5250 | + " does not correspond to an active phone"); |
| 5251 | } |
| 5252 | return PhoneFactory.getPhone(phoneId); |
| 5253 | } |
| 5254 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5255 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5256 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 5257 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5258 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5259 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5260 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5261 | if (DBG) { |
| 5262 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 5263 | } |
| 5264 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 5265 | p2); |
| 5266 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5267 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5268 | |
| 5269 | @Override |
| 5270 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 5271 | int slotIndex, String callingPackage, String aid, int p2) { |
| 5272 | enforceModifyPermission(); |
| 5273 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5274 | if (DBG) { |
| 5275 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 5276 | } |
| 5277 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 5278 | callingPackage, aid, p2); |
| 5279 | } |
| 5280 | |
| 5281 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 5282 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5283 | final long identity = Binder.clearCallingIdentity(); |
| 5284 | try { |
| 5285 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 5286 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5287 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5288 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5289 | if (bestComponent == null |
| 5290 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5291 | loge("The calling package is not allowed to access ISD-R."); |
| 5292 | throw new SecurityException( |
| 5293 | "The calling package is not allowed to access ISD-R."); |
| 5294 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5295 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5296 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5297 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5298 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 5299 | null /* workSource */); |
| 5300 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5301 | return response; |
| 5302 | } finally { |
| 5303 | Binder.restoreCallingIdentity(identity); |
| 5304 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5305 | } |
| 5306 | |
| 5307 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5308 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5309 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5310 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5311 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 5312 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 5313 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5314 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5315 | @Override |
| 5316 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 5317 | enforceModifyPermission(); |
| 5318 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 5319 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 5320 | channel); |
| 5321 | } |
| 5322 | |
| 5323 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5324 | final long identity = Binder.clearCallingIdentity(); |
| 5325 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5326 | if (channel < 0) { |
| 5327 | return false; |
| 5328 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5329 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 5330 | null /* workSource */); |
| 5331 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5332 | return success; |
| 5333 | } finally { |
| 5334 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5335 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5336 | } |
| 5337 | |
| 5338 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5339 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5340 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5341 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5342 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5343 | if (DBG) { |
| 5344 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5345 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5346 | + p3 + " data=" + data); |
| 5347 | } |
| 5348 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5349 | command, p1, p2, p3, data); |
| 5350 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5351 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5352 | @Override |
| 5353 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 5354 | int command, int p1, int p2, int p3, String data) { |
| 5355 | enforceModifyPermission(); |
| 5356 | if (DBG) { |
| 5357 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 5358 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5359 | + p3 + " data=" + data); |
| 5360 | } |
| 5361 | return iccTransmitApduLogicalChannelWithPermission( |
| 5362 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 5363 | data); |
| 5364 | } |
| 5365 | |
| 5366 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5367 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5368 | final long identity = Binder.clearCallingIdentity(); |
| 5369 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5370 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5371 | return ""; |
| 5372 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5373 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5374 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5375 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5376 | null /* workSource */); |
| 5377 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5378 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5379 | // Append the returned status code to the end of the response payload. |
| 5380 | String s = Integer.toHexString( |
| 5381 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5382 | if (response.payload != null) { |
| 5383 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5384 | } |
| 5385 | return s; |
| 5386 | } finally { |
| 5387 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5388 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5389 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5390 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5391 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5392 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5393 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5394 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5395 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5396 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5397 | if (DBG) { |
| 5398 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5399 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5400 | } |
| 5401 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5402 | cla, command, p1, p2, p3, data); |
| 5403 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5404 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5405 | @Override |
| 5406 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 5407 | int command, int p1, int p2, int p3, String data) { |
| 5408 | enforceModifyPermission(); |
| 5409 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5410 | if (DBG) { |
| 5411 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 5412 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 5413 | + " data=" + data); |
| 5414 | } |
| 5415 | |
| 5416 | return iccTransmitApduBasicChannelWithPermission( |
| 5417 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 5418 | p2, p3, data); |
| 5419 | } |
| 5420 | |
| 5421 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5422 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5423 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5424 | final long identity = Binder.clearCallingIdentity(); |
| 5425 | try { |
| 5426 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5427 | && TextUtils.equals(ISDR_AID, data)) { |
| 5428 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5429 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5430 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5431 | if (bestComponent == null |
| 5432 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5433 | loge("The calling package is not allowed to select ISD-R."); |
| 5434 | throw new SecurityException( |
| 5435 | "The calling package is not allowed to select ISD-R."); |
| 5436 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5437 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5438 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5439 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5440 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5441 | null /* workSource */); |
| 5442 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5443 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5444 | // Append the returned status code to the end of the response payload. |
| 5445 | String s = Integer.toHexString( |
| 5446 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5447 | if (response.payload != null) { |
| 5448 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5449 | } |
| 5450 | return s; |
| 5451 | } finally { |
| 5452 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5453 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5454 | } |
| 5455 | |
| 5456 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5457 | 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] | 5458 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5459 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5460 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5461 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5462 | final long identity = Binder.clearCallingIdentity(); |
| 5463 | try { |
| 5464 | if (DBG) { |
| 5465 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5466 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5467 | } |
| 5468 | |
| 5469 | IccIoResult response = |
| 5470 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5471 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5472 | subId); |
| 5473 | |
| 5474 | if (DBG) { |
| 5475 | log("Exchange SIM_IO [R]" + response); |
| 5476 | } |
| 5477 | |
| 5478 | byte[] result = null; |
| 5479 | int length = 2; |
| 5480 | if (response.payload != null) { |
| 5481 | length = 2 + response.payload.length; |
| 5482 | result = new byte[length]; |
| 5483 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5484 | } else { |
| 5485 | result = new byte[length]; |
| 5486 | } |
| 5487 | |
| 5488 | result[length - 1] = (byte) response.sw2; |
| 5489 | result[length - 2] = (byte) response.sw1; |
| 5490 | return result; |
| 5491 | } finally { |
| 5492 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5493 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5494 | } |
| 5495 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5496 | /** |
| 5497 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5498 | * on a particular subscription |
| 5499 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5500 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5501 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5502 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5503 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5504 | return null; |
| 5505 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5506 | |
| 5507 | final long identity = Binder.clearCallingIdentity(); |
| 5508 | try { |
| 5509 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5510 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5511 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5512 | return null; |
| 5513 | } |
| 5514 | Object response = sendRequest( |
| 5515 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5516 | if (response instanceof String[]) { |
| 5517 | return (String[]) response; |
| 5518 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5519 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5520 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5521 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5522 | } finally { |
| 5523 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5524 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5525 | } |
| 5526 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5527 | /** |
| 5528 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5529 | * subscription. |
| 5530 | * |
| 5531 | * @param subId the id of the subscription. |
| 5532 | * @param appType the uicc app type, must be USIM or SIM. |
| 5533 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5534 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5535 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5536 | * @return number of fplmns that is successfully written to the SIM. |
| 5537 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5538 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5539 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5540 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5541 | mApp, subId, "setForbiddenPlmns"); |
| 5542 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5543 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5544 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5545 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5546 | } |
| 5547 | if (fplmns == null) { |
| 5548 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5549 | } |
| 5550 | for (String fplmn : fplmns) { |
| 5551 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5552 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5553 | } |
| 5554 | } |
| 5555 | final long identity = Binder.clearCallingIdentity(); |
| 5556 | try { |
| 5557 | Object response = sendRequest( |
| 5558 | CMD_SET_FORBIDDEN_PLMNS, |
| 5559 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5560 | subId); |
| 5561 | return (int) response; |
| 5562 | } finally { |
| 5563 | Binder.restoreCallingIdentity(identity); |
| 5564 | } |
| 5565 | } |
| 5566 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5567 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5568 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5569 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5570 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5571 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5572 | final long identity = Binder.clearCallingIdentity(); |
| 5573 | try { |
| 5574 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5575 | if (response.payload == null) { |
| 5576 | return ""; |
| 5577 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5578 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5579 | // Append the returned status code to the end of the response payload. |
| 5580 | String s = Integer.toHexString( |
| 5581 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5582 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5583 | return s; |
| 5584 | } finally { |
| 5585 | Binder.restoreCallingIdentity(identity); |
| 5586 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5587 | } |
| 5588 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5589 | /** |
| 5590 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5591 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5592 | * |
| 5593 | * @param itemID the ID of the item to read |
| 5594 | * @return the NV item as a String, or null on error. |
| 5595 | */ |
| 5596 | @Override |
| 5597 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5598 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5599 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5600 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5601 | |
| 5602 | final long identity = Binder.clearCallingIdentity(); |
| 5603 | try { |
| 5604 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5605 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5606 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5607 | return value; |
| 5608 | } finally { |
| 5609 | Binder.restoreCallingIdentity(identity); |
| 5610 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5611 | } |
| 5612 | |
| 5613 | /** |
| 5614 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5615 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5616 | * |
| 5617 | * @param itemID the ID of the item to read |
| 5618 | * @param itemValue the value to write, as a String |
| 5619 | * @return true on success; false on any failure |
| 5620 | */ |
| 5621 | @Override |
| 5622 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5623 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5624 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5625 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5626 | |
| 5627 | final long identity = Binder.clearCallingIdentity(); |
| 5628 | try { |
| 5629 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5630 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5631 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5632 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5633 | return success; |
| 5634 | } finally { |
| 5635 | Binder.restoreCallingIdentity(identity); |
| 5636 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5637 | } |
| 5638 | |
| 5639 | /** |
| 5640 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5641 | * Used for device configuration by some CDMA operators. |
| 5642 | * |
| 5643 | * @param preferredRoamingList byte array containing the new PRL |
| 5644 | * @return true on success; false on any failure |
| 5645 | */ |
| 5646 | @Override |
| 5647 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5648 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5649 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5650 | |
| 5651 | final long identity = Binder.clearCallingIdentity(); |
| 5652 | try { |
| 5653 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5654 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5655 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5656 | return success; |
| 5657 | } finally { |
| 5658 | Binder.restoreCallingIdentity(identity); |
| 5659 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5660 | } |
| 5661 | |
| 5662 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5663 | * 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] | 5664 | * Used for device configuration by some CDMA operators. |
| 5665 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5666 | * @param slotIndex - device slot. |
| 5667 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5668 | * @return true on success; false on any failure |
| 5669 | */ |
| 5670 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5671 | public boolean resetModemConfig(int slotIndex) { |
| 5672 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5673 | if (phone != null) { |
| 5674 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5675 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5676 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5677 | final long identity = Binder.clearCallingIdentity(); |
| 5678 | try { |
| 5679 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5680 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5681 | return success; |
| 5682 | } finally { |
| 5683 | Binder.restoreCallingIdentity(identity); |
| 5684 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5685 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5686 | return false; |
| 5687 | } |
| 5688 | |
| 5689 | /** |
| 5690 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5691 | * |
| 5692 | * @param slotIndex - device slot. |
| 5693 | * |
| 5694 | * @return true on success; false on any failure |
| 5695 | */ |
| 5696 | @Override |
| 5697 | public boolean rebootModem(int slotIndex) { |
| 5698 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5699 | if (phone != null) { |
| 5700 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5701 | mApp, phone.getSubId(), "rebootModem"); |
| 5702 | |
| 5703 | final long identity = Binder.clearCallingIdentity(); |
| 5704 | try { |
| 5705 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5706 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5707 | return success; |
| 5708 | } finally { |
| 5709 | Binder.restoreCallingIdentity(identity); |
| 5710 | } |
| 5711 | } |
| 5712 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5713 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5714 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5715 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5716 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5717 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5718 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5719 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5720 | return new String[0]; |
| 5721 | } |
| 5722 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5723 | final long identity = Binder.clearCallingIdentity(); |
| 5724 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5725 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5726 | } finally { |
| 5727 | Binder.restoreCallingIdentity(identity); |
| 5728 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5729 | } |
| 5730 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5731 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5732 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5733 | * {@link #disableIms(int)}. |
| 5734 | * @param slotIndex device slot. |
| 5735 | */ |
| 5736 | public void resetIms(int slotIndex) { |
| 5737 | enforceModifyPermission(); |
| 5738 | |
| 5739 | final long identity = Binder.clearCallingIdentity(); |
| 5740 | try { |
| 5741 | if (mImsResolver == null) { |
| 5742 | // may happen if the does not support IMS. |
| 5743 | return; |
| 5744 | } |
| 5745 | mImsResolver.disableIms(slotIndex); |
| 5746 | mImsResolver.enableIms(slotIndex); |
| 5747 | } finally { |
| 5748 | Binder.restoreCallingIdentity(identity); |
| 5749 | } |
| 5750 | } |
| 5751 | |
| 5752 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5753 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5754 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5755 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5756 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5757 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5758 | |
| 5759 | final long identity = Binder.clearCallingIdentity(); |
| 5760 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5761 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5762 | // may happen if the device does not support IMS. |
| 5763 | return; |
| 5764 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5765 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5766 | } finally { |
| 5767 | Binder.restoreCallingIdentity(identity); |
| 5768 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5769 | } |
| 5770 | |
| 5771 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5772 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5773 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5774 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5775 | public void disableIms(int slotId) { |
| 5776 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5777 | |
| 5778 | final long identity = Binder.clearCallingIdentity(); |
| 5779 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5780 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5781 | // may happen if the device does not support IMS. |
| 5782 | return; |
| 5783 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5784 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5785 | } finally { |
| 5786 | Binder.restoreCallingIdentity(identity); |
| 5787 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5788 | } |
| 5789 | |
| 5790 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5791 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5792 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5793 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5794 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5795 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5796 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5797 | |
| 5798 | final long identity = Binder.clearCallingIdentity(); |
| 5799 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5800 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5801 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5802 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5803 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5804 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5805 | } finally { |
| 5806 | Binder.restoreCallingIdentity(identity); |
| 5807 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5808 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5809 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5810 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5811 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5812 | @Override |
| 5813 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5814 | enforceModifyPermission(); |
| 5815 | |
| 5816 | final long identity = Binder.clearCallingIdentity(); |
| 5817 | try { |
| 5818 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5819 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5820 | } finally { |
| 5821 | Binder.restoreCallingIdentity(identity); |
| 5822 | } |
| 5823 | } |
| 5824 | |
| 5825 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5826 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5827 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5828 | */ |
| 5829 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5830 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5831 | |
| 5832 | final long identity = Binder.clearCallingIdentity(); |
| 5833 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5834 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5835 | // may happen if the device does not support IMS. |
| 5836 | return null; |
| 5837 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5838 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5839 | } finally { |
| 5840 | Binder.restoreCallingIdentity(identity); |
| 5841 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5842 | } |
| 5843 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5844 | /** |
| 5845 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5846 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5847 | */ |
| 5848 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5849 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5850 | |
| 5851 | final long identity = Binder.clearCallingIdentity(); |
| 5852 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5853 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5854 | // may happen if the device does not support IMS. |
| 5855 | return null; |
| 5856 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5857 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5858 | } finally { |
| 5859 | Binder.restoreCallingIdentity(identity); |
| 5860 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5861 | } |
| 5862 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5863 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5864 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5865 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5866 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5867 | * @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] | 5868 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5869 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5870 | * @param packageName The name of the package that the current configuration will be replaced |
| 5871 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5872 | * @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] | 5873 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5874 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5875 | int[] featureTypes, String packageName) { |
| 5876 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5877 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5878 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5879 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5880 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5881 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5882 | final long identity = Binder.clearCallingIdentity(); |
| 5883 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5884 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5885 | // may happen if the device does not support IMS. |
| 5886 | return false; |
| 5887 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5888 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5889 | for (int featureType : featureTypes) { |
| 5890 | featureConfig.put(featureType, packageName); |
| 5891 | } |
| 5892 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5893 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5894 | } finally { |
| 5895 | Binder.restoreCallingIdentity(identity); |
| 5896 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5897 | } |
| 5898 | |
| 5899 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5900 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5901 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5902 | * |
| 5903 | * This should only be used for testing. |
| 5904 | * |
| 5905 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5906 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5907 | */ |
| 5908 | @Override |
| 5909 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5910 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5911 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5912 | "clearCarrierImsServiceOverride"); |
| 5913 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5914 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5915 | "clearCarrierImsServiceOverride"); |
| 5916 | |
| 5917 | final long identity = Binder.clearCallingIdentity(); |
| 5918 | try { |
| 5919 | if (mImsResolver == null) { |
| 5920 | // may happen if the device does not support IMS. |
| 5921 | return false; |
| 5922 | } |
| 5923 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5924 | } finally { |
| 5925 | Binder.restoreCallingIdentity(identity); |
| 5926 | } |
| 5927 | } |
| 5928 | |
| 5929 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5930 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5931 | * |
| 5932 | * @param slotId The slot that the ImsService is associated with. |
| 5933 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5934 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5935 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5936 | * @return the package name of the ImsService configuration. |
| 5937 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5938 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5939 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5940 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5941 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5942 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5943 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5944 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5945 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5946 | final long identity = Binder.clearCallingIdentity(); |
| 5947 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5948 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5949 | // may happen if the device does not support IMS. |
| 5950 | return ""; |
| 5951 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5952 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5953 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5954 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5955 | } finally { |
| 5956 | Binder.restoreCallingIdentity(identity); |
| 5957 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5958 | } |
| 5959 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5960 | /** |
| 5961 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5962 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5963 | * @param callback A callback with an integer containing the |
| 5964 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5965 | */ |
| 5966 | @Override |
| 5967 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5968 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5969 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5970 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5971 | "IMS not available on device."); |
| 5972 | } |
| 5973 | final long token = Binder.clearCallingIdentity(); |
| 5974 | try { |
| 5975 | int slotId = getSlotIndex(subId); |
| 5976 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5977 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5978 | + subId + "'"); |
| 5979 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5980 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5981 | verifyImsMmTelConfiguredOrThrow(slotId); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5982 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5983 | try { |
| 5984 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5985 | } catch (RemoteException e) { |
| 5986 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5987 | + "Ignore"); |
| 5988 | } |
| 5989 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5990 | } catch (ImsException e) { |
| 5991 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5992 | } finally { |
| 5993 | Binder.restoreCallingIdentity(token); |
| 5994 | } |
| 5995 | } |
| 5996 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5997 | /** |
| 5998 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5999 | */ |
| 6000 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6001 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6002 | |
| 6003 | final long identity = Binder.clearCallingIdentity(); |
| 6004 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6005 | // NOTE: Before S, this method only set the default phone. |
| 6006 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6007 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6008 | phone.setImsRegistrationState(registered); |
| 6009 | } |
| 6010 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6011 | } finally { |
| 6012 | Binder.restoreCallingIdentity(identity); |
| 6013 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6014 | } |
| 6015 | |
| 6016 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6017 | * Set the network selection mode to automatic. |
| 6018 | * |
| 6019 | */ |
| 6020 | @Override |
| 6021 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6022 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6023 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6024 | |
| 6025 | final long identity = Binder.clearCallingIdentity(); |
| 6026 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6027 | if (!isActiveSubscription(subId)) { |
| 6028 | return; |
| 6029 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6030 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6031 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6032 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6033 | } finally { |
| 6034 | Binder.restoreCallingIdentity(identity); |
| 6035 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6036 | } |
| 6037 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6038 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6039 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6040 | * |
| 6041 | * @param subId the id of the subscription. |
| 6042 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6043 | * the operator to attach to. |
| 6044 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6045 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6046 | * normal network selection next time. |
| 6047 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6048 | */ |
| 6049 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6050 | public boolean setNetworkSelectionModeManual( |
| 6051 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6052 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6053 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6054 | |
| 6055 | if (!isActiveSubscription(subId)) { |
| 6056 | return false; |
| 6057 | } |
| 6058 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6059 | final long identity = Binder.clearCallingIdentity(); |
| 6060 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6061 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6062 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6063 | if (DBG) { |
| 6064 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6065 | + " operator: " + operatorInfo); |
| 6066 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6067 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6068 | } finally { |
| 6069 | Binder.restoreCallingIdentity(identity); |
| 6070 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6071 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6072 | /** |
| 6073 | * Get the manual network selection |
| 6074 | * |
| 6075 | * @param subId the id of the subscription. |
| 6076 | * |
| 6077 | * @return the previously saved user selected PLMN |
| 6078 | */ |
| 6079 | @Override |
| 6080 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6081 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6082 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6083 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 6084 | |
| 6085 | final long identity = Binder.clearCallingIdentity(); |
| 6086 | try { |
| 6087 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6088 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6089 | } |
| 6090 | |
| 6091 | final Phone phone = getPhone(subId); |
| 6092 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6093 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6094 | } |
| 6095 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6096 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6097 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6098 | } finally { |
| 6099 | Binder.restoreCallingIdentity(identity); |
| 6100 | } |
| 6101 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6102 | |
| 6103 | /** |
| 6104 | * Scans for available networks. |
| 6105 | */ |
| 6106 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6107 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6108 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6109 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6110 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6111 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6112 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6113 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6114 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6115 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6116 | .setCallingPid(Binder.getCallingPid()) |
| 6117 | .setCallingUid(Binder.getCallingUid()) |
| 6118 | .setMethod("getCellNetworkScanResults") |
| 6119 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6120 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6121 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6122 | .build()); |
| 6123 | switch (locationResult) { |
| 6124 | case DENIED_HARD: |
| 6125 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6126 | case DENIED_SOFT: |
| 6127 | return null; |
| 6128 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6129 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6130 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6131 | try { |
| 6132 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6133 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6134 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6135 | } finally { |
| 6136 | Binder.restoreCallingIdentity(identity); |
| 6137 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6138 | } |
| 6139 | |
| 6140 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6141 | * Get the call forwarding info, given the call forwarding reason. |
| 6142 | */ |
| 6143 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6144 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6145 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6146 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6147 | long identity = Binder.clearCallingIdentity(); |
| 6148 | try { |
| 6149 | if (DBG) { |
| 6150 | log("getCallForwarding: subId " + subId |
| 6151 | + " callForwardingReason" + callForwardingReason); |
| 6152 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6153 | |
| 6154 | Phone phone = getPhone(subId); |
| 6155 | if (phone == null) { |
| 6156 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6157 | callback.onError( |
| 6158 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6159 | } catch (RemoteException e) { |
| 6160 | // ignore |
| 6161 | } |
| 6162 | return; |
| 6163 | } |
| 6164 | |
| 6165 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6166 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6167 | @Override |
| 6168 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6169 | try { |
| 6170 | callback.onCallForwardingInfoAvailable(info); |
| 6171 | } catch (RemoteException e) { |
| 6172 | // ignore |
| 6173 | } |
| 6174 | } |
| 6175 | |
| 6176 | @Override |
| 6177 | public void onError(int error) { |
| 6178 | try { |
| 6179 | callback.onError(error); |
| 6180 | } catch (RemoteException e) { |
| 6181 | // ignore |
| 6182 | } |
| 6183 | } |
| 6184 | }); |
| 6185 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6186 | } finally { |
| 6187 | Binder.restoreCallingIdentity(identity); |
| 6188 | } |
| 6189 | } |
| 6190 | |
| 6191 | /** |
| 6192 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6193 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6194 | */ |
| 6195 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6196 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6197 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6198 | enforceModifyPermission(); |
| 6199 | long identity = Binder.clearCallingIdentity(); |
| 6200 | try { |
| 6201 | if (DBG) { |
| 6202 | log("setCallForwarding: subId " + subId |
| 6203 | + " callForwardingInfo" + callForwardingInfo); |
| 6204 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6205 | |
| 6206 | Phone phone = getPhone(subId); |
| 6207 | if (phone == null) { |
| 6208 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6209 | callback.accept( |
| 6210 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6211 | } catch (RemoteException e) { |
| 6212 | // ignore |
| 6213 | } |
| 6214 | return; |
| 6215 | } |
| 6216 | |
| 6217 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6218 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6219 | |
| 6220 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6221 | } finally { |
| 6222 | Binder.restoreCallingIdentity(identity); |
| 6223 | } |
| 6224 | } |
| 6225 | |
| 6226 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6227 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6228 | */ |
| 6229 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6230 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6231 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6232 | long identity = Binder.clearCallingIdentity(); |
| 6233 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6234 | Phone phone = getPhone(subId); |
| 6235 | if (phone == null) { |
| 6236 | try { |
| 6237 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6238 | } catch (RemoteException e) { |
| 6239 | // ignore |
| 6240 | } |
| 6241 | return; |
| 6242 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6243 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6244 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6245 | boolean requireUssd = c.getBoolean( |
| 6246 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6247 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6248 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6249 | if (requireUssd) { |
| 6250 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6251 | getSubscriptionCarrierId(subId)); |
| 6252 | String newUssdCommand = ""; |
| 6253 | try { |
| 6254 | newUssdCommand = carrierXmlParser.getFeature( |
| 6255 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6256 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6257 | } catch (NullPointerException e) { |
| 6258 | loge("Failed to generate USSD number" + e); |
| 6259 | } |
| 6260 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6261 | mMainThreadHandler, callback, carrierXmlParser, |
| 6262 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6263 | final String ussdCommand = newUssdCommand; |
| 6264 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6265 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6266 | }); |
| 6267 | } else { |
| 6268 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6269 | callback::accept); |
| 6270 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6271 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6272 | } finally { |
| 6273 | Binder.restoreCallingIdentity(identity); |
| 6274 | } |
| 6275 | } |
| 6276 | |
| 6277 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6278 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6279 | */ |
| 6280 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6281 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6282 | enforceModifyPermission(); |
| 6283 | long identity = Binder.clearCallingIdentity(); |
| 6284 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6285 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6286 | |
| 6287 | Phone phone = getPhone(subId); |
| 6288 | if (phone == null) { |
| 6289 | try { |
| 6290 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6291 | } catch (RemoteException e) { |
| 6292 | // ignore |
| 6293 | } |
| 6294 | return; |
| 6295 | } |
| 6296 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6297 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6298 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6299 | boolean requireUssd = c.getBoolean( |
| 6300 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6301 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6302 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6303 | if (requireUssd) { |
| 6304 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6305 | getSubscriptionCarrierId(subId)); |
| 6306 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6307 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6308 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6309 | String newUssdCommand = ""; |
| 6310 | try { |
| 6311 | newUssdCommand = carrierXmlParser.getFeature( |
| 6312 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6313 | .makeCommand(ssAction, null); |
| 6314 | } catch (NullPointerException e) { |
| 6315 | loge("Failed to generate USSD number" + e); |
| 6316 | } |
| 6317 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6318 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6319 | final String ussdCommand = newUssdCommand; |
| 6320 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6321 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6322 | }); |
| 6323 | } else { |
| 6324 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6325 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6326 | |
| 6327 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6328 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6329 | } finally { |
| 6330 | Binder.restoreCallingIdentity(identity); |
| 6331 | } |
| 6332 | } |
| 6333 | |
| 6334 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6335 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6336 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6337 | * @param subId id of the subscription |
| 6338 | * @param request contains the radio access networks with bands/channels to scan |
| 6339 | * @param messenger callback messenger for scan results or errors |
| 6340 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6341 | * @return the id of the requested scan which can be used to stop the scan. |
| 6342 | */ |
| 6343 | @Override |
| 6344 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6345 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6346 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6347 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6348 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6349 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6350 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6351 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6352 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6353 | .setCallingPid(Binder.getCallingPid()) |
| 6354 | .setCallingUid(Binder.getCallingUid()) |
| 6355 | .setMethod("requestNetworkScan") |
| 6356 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
James.cf Lin | 1d4d739 | 2020-07-03 18:22:53 +0800 | [diff] [blame] | 6357 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6358 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6359 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6360 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6361 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6362 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6363 | if (e != null) { |
| 6364 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6365 | throw e; |
| 6366 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6367 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6368 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6369 | } |
| 6370 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6371 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6372 | int callingUid = Binder.getCallingUid(); |
| 6373 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6374 | final long identity = Binder.clearCallingIdentity(); |
| 6375 | try { |
| 6376 | return mNetworkScanRequestTracker.startNetworkScan( |
| 6377 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6378 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6379 | } finally { |
| 6380 | Binder.restoreCallingIdentity(identity); |
| 6381 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6382 | } |
| 6383 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6384 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6385 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6386 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6387 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6388 | boolean hasNetworkScanPermission = |
| 6389 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6390 | == PERMISSION_GRANTED; |
| 6391 | |
| 6392 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6393 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6394 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6395 | } |
| 6396 | |
| 6397 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6398 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6399 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6400 | return new SecurityException("Specific channels must not be" |
| 6401 | + " scanned without location access."); |
| 6402 | } |
| 6403 | } |
| 6404 | } |
| 6405 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6406 | return null; |
| 6407 | } |
| 6408 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6409 | /** |
| 6410 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6411 | * |
| 6412 | * @param subId id of the subscription |
| 6413 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6414 | */ |
| 6415 | @Override |
| 6416 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6417 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6418 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6419 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6420 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6421 | final long identity = Binder.clearCallingIdentity(); |
| 6422 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6423 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6424 | } finally { |
| 6425 | Binder.restoreCallingIdentity(identity); |
| 6426 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6427 | } |
| 6428 | |
| 6429 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6430 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6431 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6432 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6433 | */ |
| 6434 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6435 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6436 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6437 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6438 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6439 | |
| 6440 | final long identity = Binder.clearCallingIdentity(); |
| 6441 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6442 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6443 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6444 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6445 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6446 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6447 | } finally { |
| 6448 | Binder.restoreCallingIdentity(identity); |
| 6449 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6450 | } |
| 6451 | |
| 6452 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6453 | * Get the allowed network types for certain reason. |
| 6454 | * |
| 6455 | * @param subId the id of the subscription. |
| 6456 | * @param reason the reason the allowed network type change is taking place |
| 6457 | * @return the allowed network types. |
| 6458 | */ |
| 6459 | @Override |
| 6460 | public long getAllowedNetworkTypesForReason(int subId, |
| 6461 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6462 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6463 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6464 | final long identity = Binder.clearCallingIdentity(); |
| 6465 | try { |
| 6466 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6467 | } finally { |
| 6468 | Binder.restoreCallingIdentity(identity); |
| 6469 | } |
| 6470 | } |
| 6471 | |
| 6472 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6473 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6474 | * @param subId subscription id of the sim card |
| 6475 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6476 | * This can be passed following states |
| 6477 | * <ol> |
| 6478 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6479 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6480 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6481 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6482 | * </ol> |
| 6483 | * @return operation result. |
| 6484 | */ |
| 6485 | @Override |
| 6486 | public int setNrDualConnectivityState(int subId, |
| 6487 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6488 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6489 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6490 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6491 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6492 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6493 | } |
| 6494 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6495 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6496 | final long identity = Binder.clearCallingIdentity(); |
| 6497 | try { |
| 6498 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6499 | nrDualConnectivityState, subId, |
| 6500 | workSource); |
| 6501 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6502 | return result; |
| 6503 | } finally { |
| 6504 | Binder.restoreCallingIdentity(identity); |
| 6505 | } |
| 6506 | } |
| 6507 | |
| 6508 | /** |
| 6509 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6510 | * @return true if dual connectivity is enabled else false |
| 6511 | */ |
| 6512 | @Override |
| 6513 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6514 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6515 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6516 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6517 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6518 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6519 | return false; |
| 6520 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6521 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6522 | final long identity = Binder.clearCallingIdentity(); |
| 6523 | try { |
| 6524 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6525 | null, subId, workSource); |
| 6526 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6527 | return isEnabled; |
| 6528 | } finally { |
| 6529 | Binder.restoreCallingIdentity(identity); |
| 6530 | } |
| 6531 | } |
| 6532 | |
| 6533 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6534 | * Set the allowed network types of the device and |
| 6535 | * provide the reason triggering the allowed network change. |
| 6536 | * |
| 6537 | * @param subId the id of the subscription. |
| 6538 | * @param reason the reason the allowed network type change is taking place |
| 6539 | * @param allowedNetworkTypes the allowed network types. |
| 6540 | * @return true on success; false on any failure. |
| 6541 | */ |
| 6542 | @Override |
| 6543 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6544 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6545 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6546 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6547 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6548 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6549 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6550 | return false; |
| 6551 | } |
| 6552 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6553 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6554 | return false; |
| 6555 | } |
| 6556 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6557 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6558 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6559 | |
| 6560 | |
| 6561 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6562 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6563 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6564 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6565 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6566 | final long identity = Binder.clearCallingIdentity(); |
| 6567 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6568 | Boolean success = (Boolean) sendRequest( |
| 6569 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6570 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6571 | |
| 6572 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6573 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6574 | } finally { |
| 6575 | Binder.restoreCallingIdentity(identity); |
| 6576 | } |
| 6577 | } |
| 6578 | |
| 6579 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6580 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6581 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6582 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6583 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6584 | * @hide |
| 6585 | */ |
| 6586 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6587 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6588 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6589 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6590 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6591 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6592 | if (phone != null) { |
| 6593 | return phone.hasMatchedTetherApnSetting(); |
| 6594 | } else { |
| 6595 | return false; |
| 6596 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6597 | } finally { |
| 6598 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6599 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6600 | } |
| 6601 | |
| 6602 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6603 | * Get the user enabled state of Mobile Data. |
| 6604 | * |
| 6605 | * TODO: remove and use isUserDataEnabled. |
| 6606 | * This can't be removed now because some vendor codes |
| 6607 | * calls through ITelephony directly while they should |
| 6608 | * use TelephonyManager. |
| 6609 | * |
| 6610 | * @return true on enabled |
| 6611 | */ |
| 6612 | @Override |
| 6613 | public boolean getDataEnabled(int subId) { |
| 6614 | return isUserDataEnabled(subId); |
| 6615 | } |
| 6616 | |
| 6617 | /** |
| 6618 | * Get whether mobile data is enabled per user setting. |
| 6619 | * |
| 6620 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6621 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6622 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6623 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6624 | * |
| 6625 | * @return {@code true} if data is enabled else {@code false} |
| 6626 | */ |
| 6627 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6628 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6629 | try { |
| 6630 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6631 | null); |
| 6632 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6633 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6634 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6635 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6636 | |
| 6637 | final long identity = Binder.clearCallingIdentity(); |
| 6638 | try { |
| 6639 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6640 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6641 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6642 | if (phone != null) { |
| 6643 | boolean retVal = phone.isUserDataEnabled(); |
| 6644 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6645 | return retVal; |
| 6646 | } else { |
| 6647 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6648 | return false; |
| 6649 | } |
| 6650 | } finally { |
| 6651 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6652 | } |
| 6653 | } |
| 6654 | |
| 6655 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6656 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6657 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6658 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6659 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6660 | * @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] | 6661 | */ |
| 6662 | @Override |
| 6663 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6664 | try { |
| 6665 | try { |
| 6666 | mApp.enforceCallingOrSelfPermission( |
| 6667 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6668 | null); |
| 6669 | } catch (Exception e) { |
| 6670 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6671 | "isDataEnabled"); |
| 6672 | } |
| 6673 | } catch (Exception e) { |
| 6674 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6675 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6676 | |
| 6677 | final long identity = Binder.clearCallingIdentity(); |
| 6678 | try { |
| 6679 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6680 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6681 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6682 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6683 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6684 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6685 | return retVal; |
| 6686 | } else { |
| 6687 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6688 | return false; |
| 6689 | } |
| 6690 | } finally { |
| 6691 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6692 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6693 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6694 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6695 | /** |
| 6696 | * Check if data is enabled for a specific reason |
| 6697 | * @param subId Subscription index |
| 6698 | * @param reason the reason the data enable change is taking place |
| 6699 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6700 | */ |
| 6701 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6702 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6703 | @TelephonyManager.DataEnabledReason int reason) { |
| 6704 | try { |
| 6705 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6706 | null); |
| 6707 | } catch (Exception e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame^] | 6708 | try { |
| 6709 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6710 | "isDataEnabledForReason"); |
| 6711 | } catch (Exception e2) { |
| 6712 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6713 | mApp, subId, "isDataEnabledForReason"); |
| 6714 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6715 | } |
| 6716 | |
| 6717 | |
| 6718 | final long identity = Binder.clearCallingIdentity(); |
| 6719 | try { |
| 6720 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6721 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6722 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6723 | + " reason=" + reason); |
| 6724 | } |
| 6725 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6726 | if (phone != null) { |
| 6727 | boolean retVal; |
| 6728 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6729 | retVal = phone.isUserDataEnabled(); |
| 6730 | } else { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6731 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6732 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6733 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6734 | return retVal; |
| 6735 | } else { |
| 6736 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6737 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6738 | + subId + " retVal=false"); |
| 6739 | } |
| 6740 | return false; |
| 6741 | } |
| 6742 | } finally { |
| 6743 | Binder.restoreCallingIdentity(identity); |
| 6744 | } |
| 6745 | } |
| 6746 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6747 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6748 | Phone phone) { |
Sarah Chin | 3394efe | 2021-04-09 10:37:15 -0700 | [diff] [blame] | 6749 | if (uid == Process.PHONE_UID) { |
| 6750 | // Skip the check if it's the phone UID (system UID removed in b/184713596) |
| 6751 | // 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] | 6752 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6753 | } |
| 6754 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6755 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6756 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6757 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6758 | || subController == null) return privilegeFromSim; |
| 6759 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6760 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6761 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6762 | |
| 6763 | final long identity = Binder.clearCallingIdentity(); |
| 6764 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6765 | int subId = phone.getSubId(); |
| 6766 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6767 | // A test override is in place for the privileges for this subId, so don't try to |
| 6768 | // read the subscription privileges. |
| 6769 | return privilegeFromSim; |
| 6770 | } |
| 6771 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6772 | SubscriptionManager subManager = (SubscriptionManager) |
| 6773 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6774 | for (String pkg : packages) { |
| 6775 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6776 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6777 | } |
| 6778 | } |
| 6779 | return privilegeFromSim; |
| 6780 | } finally { |
| 6781 | Binder.restoreCallingIdentity(identity); |
| 6782 | } |
| 6783 | } |
| 6784 | |
| 6785 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6786 | String pkgName) { |
| 6787 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6788 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6789 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6790 | || subController == null) return privilegeFromSim; |
| 6791 | |
| 6792 | final long identity = Binder.clearCallingIdentity(); |
| 6793 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6794 | int subId = phone.getSubId(); |
| 6795 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6796 | // A test override is in place for the privileges for this subId, so don't try to |
| 6797 | // read the subscription privileges. |
| 6798 | return privilegeFromSim; |
| 6799 | } |
| 6800 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6801 | SubscriptionManager subManager = (SubscriptionManager) |
| 6802 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6803 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6804 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6805 | } finally { |
| 6806 | Binder.restoreCallingIdentity(identity); |
| 6807 | } |
| 6808 | } |
| 6809 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6810 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6811 | public int getCarrierPrivilegeStatus(int subId) { |
| 6812 | final Phone phone = getPhone(subId); |
| 6813 | if (phone == null) { |
| 6814 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6815 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6816 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6817 | UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
| 6818 | if (port == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6819 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6820 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6821 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6822 | |
| 6823 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6824 | port.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6825 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6826 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6827 | |
| 6828 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6829 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6830 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6831 | final Phone phone = getPhone(subId); |
| 6832 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6833 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6834 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6835 | } |
| 6836 | UiccProfile profile = |
| 6837 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6838 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6839 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6840 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6841 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6842 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6843 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6844 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6845 | } |
| 6846 | |
| 6847 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6848 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6849 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6850 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6851 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6852 | } |
| 6853 | |
| 6854 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6855 | UiccPort port = UiccController.getInstance().getUiccPort(phoneId); |
| 6856 | if (port == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6857 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6858 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6859 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6860 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6861 | port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6862 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6863 | } |
| 6864 | |
| 6865 | @Override |
| 6866 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Sarah Chin | fc3169b | 2021-04-28 20:21:03 -0700 | [diff] [blame] | 6867 | // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6868 | if (TextUtils.isEmpty(pkgName)) |
| 6869 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6870 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6871 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6872 | UiccPort port = UiccController.getInstance().getUiccPort(i); |
| 6873 | if (port == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6874 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6875 | continue; |
| 6876 | } |
| 6877 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6878 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6879 | port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6880 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6881 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6882 | break; |
| 6883 | } |
| 6884 | } |
| 6885 | |
| 6886 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6887 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6888 | |
| 6889 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6890 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6891 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6892 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6893 | loge("phoneId " + phoneId + " is not valid."); |
| 6894 | return null; |
| 6895 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6896 | UiccPort port = UiccController.getInstance().getUiccPort(phoneId); |
| 6897 | if (port == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6898 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6899 | return null ; |
| 6900 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6901 | return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6902 | } |
| 6903 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6904 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6905 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6906 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6907 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6908 | List<String> privilegedPackages = new ArrayList<>(); |
| 6909 | List<PackageInfo> packages = null; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6910 | UiccPort port = UiccController.getInstance().getUiccPort(phoneId); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6911 | // has UICC in that slot. |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6912 | if (port != null) { |
| 6913 | if (port.hasCarrierPrivilegeRules()) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6914 | if (packages == null) { |
| 6915 | // Only check packages in user 0 for now |
| 6916 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6917 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6918 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6919 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6920 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6921 | } |
| 6922 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6923 | PackageInfo pkgInfo = packages.get(p); |
| 6924 | if (pkgInfo != null && pkgInfo.packageName != null |
Sooraj Sasindran | 97bce6f | 2021-09-28 21:37:29 +0000 | [diff] [blame] | 6925 | && getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6926 | port.getCarrierPrivilegeStatus(pkgInfo), |
| 6927 | getPhone(phoneId), pkgInfo.packageName) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6928 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6929 | privilegedPackages.add(pkgInfo.packageName); |
| 6930 | } |
| 6931 | } |
| 6932 | } |
| 6933 | } |
| 6934 | return privilegedPackages; |
| 6935 | } |
| 6936 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6937 | @Override |
| 6938 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6939 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6940 | |
| 6941 | final long identity = Binder.clearCallingIdentity(); |
| 6942 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6943 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6944 | try { |
| 6945 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6946 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6947 | } |
| 6948 | } finally { |
| 6949 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6950 | } |
| 6951 | return privilegedPackages; |
| 6952 | } |
| 6953 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6954 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6955 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6956 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 6957 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6958 | return null; |
| 6959 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6960 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6961 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6962 | return null; |
| 6963 | } |
| 6964 | return iccId; |
| 6965 | } |
| 6966 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6967 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6968 | public void setCallComposerStatus(int subId, int status) { |
| 6969 | enforceModifyPermission(); |
| 6970 | |
| 6971 | final long identity = Binder.clearCallingIdentity(); |
| 6972 | try { |
| 6973 | Phone phone = getPhone(subId); |
| 6974 | if (phone != null) { |
| 6975 | Phone defaultPhone = phone.getImsPhone(); |
| 6976 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6977 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6978 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6979 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6980 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6981 | } |
| 6982 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6983 | } catch (ImsException e) { |
| 6984 | throw new ServiceSpecificException(e.getCode()); |
| 6985 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6986 | Binder.restoreCallingIdentity(identity); |
| 6987 | } |
| 6988 | } |
| 6989 | |
| 6990 | @Override |
| 6991 | public int getCallComposerStatus(int subId) { |
| 6992 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6993 | |
| 6994 | final long identity = Binder.clearCallingIdentity(); |
| 6995 | try { |
| 6996 | Phone phone = getPhone(subId); |
| 6997 | if (phone != null) { |
| 6998 | Phone defaultPhone = phone.getImsPhone(); |
| 6999 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7000 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7001 | return imsPhone.getCallComposerStatus(); |
| 7002 | } |
| 7003 | } |
| 7004 | } finally { |
| 7005 | Binder.restoreCallingIdentity(identity); |
| 7006 | } |
| 7007 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7008 | } |
| 7009 | |
| 7010 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7011 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7012 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7013 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7014 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7015 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7016 | final long identity = Binder.clearCallingIdentity(); |
| 7017 | try { |
| 7018 | final String iccId = getIccId(subId); |
| 7019 | final Phone phone = getPhone(subId); |
| 7020 | if (phone == null) { |
| 7021 | return false; |
| 7022 | } |
| 7023 | final String subscriberId = phone.getSubscriberId(); |
| 7024 | |
| 7025 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7026 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7027 | + subscriberId + " to " + number); |
| 7028 | } |
| 7029 | |
| 7030 | if (TextUtils.isEmpty(iccId)) { |
| 7031 | return false; |
| 7032 | } |
| 7033 | |
| 7034 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7035 | |
| 7036 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7037 | if (alphaTag == null) { |
| 7038 | editor.remove(alphaTagPrefKey); |
| 7039 | } else { |
| 7040 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7041 | } |
| 7042 | |
| 7043 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7044 | // track all merged IMSIs based on line number |
| 7045 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7046 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7047 | if (number == null) { |
| 7048 | editor.remove(numberPrefKey); |
| 7049 | editor.remove(subscriberPrefKey); |
| 7050 | } else { |
| 7051 | editor.putString(numberPrefKey, number); |
| 7052 | editor.putString(subscriberPrefKey, subscriberId); |
| 7053 | } |
| 7054 | |
| 7055 | editor.commit(); |
| 7056 | return true; |
| 7057 | } finally { |
| 7058 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7059 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7060 | } |
| 7061 | |
| 7062 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7063 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7064 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7065 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7066 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7067 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7068 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7069 | return null; |
| 7070 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7071 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7072 | final long identity = Binder.clearCallingIdentity(); |
| 7073 | try { |
| 7074 | String iccId = getIccId(subId); |
| 7075 | if (iccId != null) { |
| 7076 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7077 | if (DBG_MERGE) { |
| 7078 | log("getLine1NumberForDisplay returning " |
| 7079 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7080 | } |
| 7081 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7082 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7083 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7084 | return null; |
| 7085 | } finally { |
| 7086 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7087 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7088 | } |
| 7089 | |
| 7090 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7091 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7092 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7093 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7094 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7095 | return null; |
| 7096 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7097 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7098 | final long identity = Binder.clearCallingIdentity(); |
| 7099 | try { |
| 7100 | String iccId = getIccId(subId); |
| 7101 | if (iccId != null) { |
| 7102 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7103 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7104 | } |
| 7105 | return null; |
| 7106 | } finally { |
| 7107 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7108 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7109 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7110 | |
| 7111 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7112 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7113 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7114 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7115 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7116 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7117 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7118 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7119 | return null; |
| 7120 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7121 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7122 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7123 | // the process, where TelephonyManager was instantiated. |
| 7124 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7125 | final long identity = Binder.clearCallingIdentity(); |
| 7126 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7127 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7128 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7129 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7130 | |
| 7131 | // Figure out what subscribers are currently active |
| 7132 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7133 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7134 | // Only consider subs which match the current subId |
| 7135 | // This logic can be simplified. See b/131189269 for progress. |
| 7136 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7137 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7138 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7139 | |
| 7140 | // First pass, find a number override for an active subscriber |
| 7141 | String mergeNumber = null; |
| 7142 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7143 | for (String key : prefs.keySet()) { |
| 7144 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7145 | final String subscriberId = (String) prefs.get(key); |
| 7146 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7147 | final String iccId = key.substring( |
| 7148 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7149 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7150 | mergeNumber = (String) prefs.get(numberKey); |
| 7151 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7152 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7153 | + " for active subscriber " + subscriberId); |
| 7154 | } |
| 7155 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7156 | break; |
| 7157 | } |
| 7158 | } |
| 7159 | } |
| 7160 | } |
| 7161 | |
| 7162 | // Shortcut when no active merged subscribers |
| 7163 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7164 | return null; |
| 7165 | } |
| 7166 | |
| 7167 | // Second pass, find all subscribers under that line override |
| 7168 | final ArraySet<String> result = new ArraySet<>(); |
| 7169 | for (String key : prefs.keySet()) { |
| 7170 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7171 | final String number = (String) prefs.get(key); |
| 7172 | if (mergeNumber.equals(number)) { |
| 7173 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7174 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7175 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7176 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7177 | result.add(subscriberId); |
| 7178 | } |
| 7179 | } |
| 7180 | } |
| 7181 | } |
| 7182 | |
| 7183 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7184 | Arrays.sort(resultArray); |
| 7185 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7186 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7187 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7188 | } |
| 7189 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7190 | } finally { |
| 7191 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7192 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7193 | } |
| 7194 | |
| 7195 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7196 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7197 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7198 | |
| 7199 | final long identity = Binder.clearCallingIdentity(); |
| 7200 | try { |
| 7201 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7202 | TelephonyManager.class); |
| 7203 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7204 | if (subscriberId == null) { |
| 7205 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7206 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7207 | + subId); |
| 7208 | } |
| 7209 | return null; |
| 7210 | } |
| 7211 | |
| 7212 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 7213 | .getSubscriptionInfo(subId); |
| 7214 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 7215 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7216 | if (groupUuid == null) { |
| 7217 | return new String[]{subscriberId}; |
| 7218 | } |
| 7219 | |
| 7220 | // Get all subscriberIds from the group. |
| 7221 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 7222 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7223 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7224 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7225 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7226 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7227 | if (subscriberId != null) { |
| 7228 | mergedSubscriberIds.add(subscriberId); |
| 7229 | } |
| 7230 | } |
| 7231 | |
| 7232 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7233 | } finally { |
| 7234 | Binder.restoreCallingIdentity(identity); |
| 7235 | |
| 7236 | } |
| 7237 | } |
| 7238 | |
| 7239 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7240 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7241 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7242 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7243 | |
| 7244 | final long identity = Binder.clearCallingIdentity(); |
| 7245 | try { |
| 7246 | final Phone phone = getPhone(subId); |
| 7247 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7248 | } finally { |
| 7249 | Binder.restoreCallingIdentity(identity); |
| 7250 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7251 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7252 | |
| 7253 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7254 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7255 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7256 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7257 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7258 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7259 | |
| 7260 | final long identity = Binder.clearCallingIdentity(); |
| 7261 | try { |
| 7262 | final Phone phone = getPhone(subId); |
| 7263 | if (phone == null) { |
| 7264 | return false; |
| 7265 | } |
| 7266 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7267 | cdmaNonRoamingList); |
| 7268 | } finally { |
| 7269 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7270 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7271 | } |
| 7272 | |
| 7273 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7274 | @Deprecated |
| 7275 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7276 | enforceModifyPermission(); |
| 7277 | |
| 7278 | int returnValue = 0; |
| 7279 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7280 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7281 | if(result.exception == null) { |
| 7282 | if (result.result != null) { |
| 7283 | byte[] responseData = (byte[])(result.result); |
| 7284 | if(responseData.length > oemResp.length) { |
| 7285 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7286 | responseData.length + "bytes. Buffer Size is " + |
| 7287 | oemResp.length + "bytes."); |
| 7288 | } |
| 7289 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7290 | returnValue = responseData.length; |
| 7291 | } |
| 7292 | } else { |
| 7293 | CommandException ex = (CommandException) result.exception; |
| 7294 | returnValue = ex.getCommandError().ordinal(); |
| 7295 | if(returnValue > 0) returnValue *= -1; |
| 7296 | } |
| 7297 | } catch (RuntimeException e) { |
| 7298 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7299 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7300 | if(returnValue > 0) returnValue *= -1; |
| 7301 | } |
| 7302 | |
| 7303 | return returnValue; |
| 7304 | } |
| 7305 | |
| 7306 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7307 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7308 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7309 | try { |
| 7310 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7311 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7312 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7313 | } catch (SecurityException e) { |
| 7314 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7315 | throw e; |
| 7316 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7317 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7318 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7319 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7320 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7321 | final long identity = Binder.clearCallingIdentity(); |
| 7322 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7323 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7324 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7325 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7326 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7327 | } finally { |
| 7328 | Binder.restoreCallingIdentity(identity); |
| 7329 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7330 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7331 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7332 | |
| 7333 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7334 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7335 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7336 | try { |
| 7337 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7338 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7339 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7340 | } |
| 7341 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7342 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7343 | } |
| 7344 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7345 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7346 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7347 | throw new SecurityException("App must be the dialer role holder to" |
| 7348 | + " upload a call composer pic"); |
| 7349 | } |
| 7350 | |
| 7351 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7352 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7353 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7354 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7355 | boolean readUntilEnd = false; |
| 7356 | int totalBytesRead = 0; |
| 7357 | byte[] buffer = new byte[16 * 1024]; |
| 7358 | while (true) { |
| 7359 | int numRead; |
| 7360 | try { |
| 7361 | numRead = input.read(buffer); |
| 7362 | } catch (IOException e) { |
| 7363 | try { |
| 7364 | fd.checkError(); |
| 7365 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7366 | null); |
| 7367 | } catch (IOException e1) { |
| 7368 | // This means that the other side closed explicitly with an error. If this |
| 7369 | // happens, log and ignore. |
| 7370 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7371 | } |
| 7372 | break; |
| 7373 | } |
| 7374 | if (numRead == -1) { |
| 7375 | readUntilEnd = true; |
| 7376 | break; |
| 7377 | } |
| 7378 | totalBytesRead += numRead; |
| 7379 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7380 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7381 | try { |
| 7382 | input.close(); |
| 7383 | } catch (IOException e) { |
| 7384 | // ignore |
| 7385 | } |
| 7386 | break; |
| 7387 | } |
| 7388 | output.write(buffer, 0, numRead); |
| 7389 | } |
| 7390 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7391 | // close is above, where the picture size is too big. |
| 7392 | |
| 7393 | try { |
| 7394 | fd.checkError(); |
| 7395 | } catch (IOException e) { |
| 7396 | loge("Remote end for call composer closed with an error: " + e); |
| 7397 | return; |
| 7398 | } |
| 7399 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7400 | if (!readUntilEnd) { |
| 7401 | loge("Did not finish reading entire image; aborting"); |
| 7402 | return; |
| 7403 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7404 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7405 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7406 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7407 | new CallComposerPictureTransfer.Factory() {}, |
| 7408 | imageData, |
| 7409 | (result) -> { |
| 7410 | if (result.first != null) { |
| 7411 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7412 | Bundle outputResult = new Bundle(); |
| 7413 | outputResult.putParcelable( |
| 7414 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7415 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7416 | outputResult); |
| 7417 | } else { |
| 7418 | callback.send(result.second, null); |
| 7419 | } |
| 7420 | } |
| 7421 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7422 | }); |
| 7423 | } |
| 7424 | |
| 7425 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7426 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7427 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7428 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7429 | |
| 7430 | final long identity = Binder.clearCallingIdentity(); |
| 7431 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7432 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7433 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7434 | } finally { |
| 7435 | Binder.restoreCallingIdentity(identity); |
| 7436 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7437 | } |
| 7438 | |
| 7439 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7440 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7441 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7442 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7443 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7444 | return false; |
| 7445 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7446 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7447 | final long identity = Binder.clearCallingIdentity(); |
| 7448 | try { |
| 7449 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7450 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7451 | // In the long run, we may instead need to check if there exists a connection service |
| 7452 | // which can support video calling. |
| 7453 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7454 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7455 | return imsManager.isVtEnabledByPlatform() |
| 7456 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7457 | && imsManager.isVtEnabledByUser(); |
| 7458 | } finally { |
| 7459 | Binder.restoreCallingIdentity(identity); |
| 7460 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7461 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7462 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7463 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7464 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7465 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7466 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7467 | mApp, subId, callingPackage, callingFeatureId, |
| 7468 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7469 | return false; |
| 7470 | } |
| 7471 | |
| 7472 | final long identity = Binder.clearCallingIdentity(); |
| 7473 | try { |
| 7474 | CarrierConfigManager configManager = |
| 7475 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7476 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7477 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7478 | } finally { |
| 7479 | Binder.restoreCallingIdentity(identity); |
| 7480 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7481 | } |
| 7482 | |
| 7483 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7484 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7485 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7486 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7487 | return false; |
| 7488 | } |
| 7489 | |
| 7490 | final long identity = Binder.clearCallingIdentity(); |
| 7491 | try { |
| 7492 | CarrierConfigManager configManager = |
| 7493 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7494 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7495 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7496 | } finally { |
| 7497 | Binder.restoreCallingIdentity(identity); |
| 7498 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7499 | } |
| 7500 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7501 | @Override |
| 7502 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7503 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7504 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7505 | } |
| 7506 | |
| 7507 | @Override |
| 7508 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7509 | final long identity = Binder.clearCallingIdentity(); |
| 7510 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7511 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7512 | } finally { |
| 7513 | Binder.restoreCallingIdentity(identity); |
| 7514 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7515 | } |
| 7516 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7517 | /** |
| 7518 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7519 | * support for the feature and device firmware support. |
| 7520 | * |
| 7521 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7522 | */ |
| 7523 | @Override |
| 7524 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7525 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7526 | final Phone phone = getPhone(subscriptionId); |
| 7527 | if (phone == null) { |
| 7528 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7529 | return false; |
| 7530 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7531 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7532 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7533 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7534 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7535 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7536 | return isCarrierSupported && isDeviceSupported; |
| 7537 | } finally { |
| 7538 | Binder.restoreCallingIdentity(identity); |
| 7539 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7540 | } |
| 7541 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7542 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7543 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7544 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7545 | * 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] | 7546 | */ |
| 7547 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7548 | final long identity = Binder.clearCallingIdentity(); |
| 7549 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7550 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7551 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7552 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7553 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7554 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7555 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7556 | } finally { |
| 7557 | Binder.restoreCallingIdentity(identity); |
| 7558 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7559 | } |
| 7560 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7561 | @Deprecated |
| 7562 | @Override |
| 7563 | public String getDeviceId(String callingPackage) { |
| 7564 | return getDeviceIdWithFeature(callingPackage, null); |
| 7565 | } |
| 7566 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7567 | /** |
| 7568 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7569 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7570 | * |
| 7571 | * <p>Requires Permission: |
| 7572 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7573 | */ |
| 7574 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7575 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7576 | try { |
| 7577 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7578 | } catch (SecurityException se) { |
| 7579 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7580 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7581 | + Binder.getCallingUid()); |
| 7582 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7583 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7584 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7585 | return null; |
| 7586 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7587 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7588 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7589 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7590 | return null; |
| 7591 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7592 | |
| 7593 | final long identity = Binder.clearCallingIdentity(); |
| 7594 | try { |
| 7595 | return phone.getDeviceId(); |
| 7596 | } finally { |
| 7597 | Binder.restoreCallingIdentity(identity); |
| 7598 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7599 | } |
| 7600 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7601 | /** |
| 7602 | * {@hide} |
| 7603 | * Returns the IMS Registration Status on a particular subid |
| 7604 | * |
| 7605 | * @param subId |
| 7606 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7607 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7608 | Phone phone = getPhone(subId); |
| 7609 | if (phone != null) { |
| 7610 | return phone.isImsRegistered(); |
| 7611 | } else { |
| 7612 | return false; |
| 7613 | } |
| 7614 | } |
| 7615 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7616 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7617 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7618 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7619 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7620 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7621 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7622 | } |
| 7623 | final long identity = Binder.clearCallingIdentity(); |
| 7624 | try { |
| 7625 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7626 | } finally { |
| 7627 | Binder.restoreCallingIdentity(identity); |
| 7628 | } |
| 7629 | } |
| 7630 | |
| 7631 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7632 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7633 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7634 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7635 | mApp, |
| 7636 | subscriptionId, |
| 7637 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7638 | final long identity = Binder.clearCallingIdentity(); |
| 7639 | try { |
| 7640 | Phone phone = getPhone(subscriptionId); |
| 7641 | if (phone == null) { |
| 7642 | return null; |
| 7643 | } |
| 7644 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7645 | } finally { |
| 7646 | Binder.restoreCallingIdentity(identity); |
| 7647 | } |
| 7648 | } |
| 7649 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7650 | /** |
| 7651 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7652 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7653 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7654 | final long identity = Binder.clearCallingIdentity(); |
| 7655 | try { |
| 7656 | Phone phone = getPhone(subId); |
| 7657 | if (phone != null) { |
| 7658 | return phone.isWifiCallingEnabled(); |
| 7659 | } else { |
| 7660 | return false; |
| 7661 | } |
| 7662 | } finally { |
| 7663 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7664 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7665 | } |
| 7666 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7667 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7668 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7669 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7670 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7671 | final long identity = Binder.clearCallingIdentity(); |
| 7672 | try { |
| 7673 | Phone phone = getPhone(subId); |
| 7674 | if (phone != null) { |
| 7675 | return phone.isVideoEnabled(); |
| 7676 | } else { |
| 7677 | return false; |
| 7678 | } |
| 7679 | } finally { |
| 7680 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7681 | } |
| 7682 | } |
| 7683 | |
| 7684 | /** |
| 7685 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7686 | * defined in {@link ImsRegistrationImplBase}. |
| 7687 | */ |
| 7688 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7689 | final long identity = Binder.clearCallingIdentity(); |
| 7690 | try { |
| 7691 | Phone phone = getPhone(subId); |
| 7692 | if (phone != null) { |
| 7693 | return phone.getImsRegistrationTech(); |
| 7694 | } else { |
| 7695 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7696 | } |
| 7697 | } finally { |
| 7698 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7699 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7700 | } |
| 7701 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7702 | @Override |
| 7703 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7704 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7705 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7706 | return; |
| 7707 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7708 | Phone defaultPhone = getDefaultPhone(); |
| 7709 | if (defaultPhone != null) { |
| 7710 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7711 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7712 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7713 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7714 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7715 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7716 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7717 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7718 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7719 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7720 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7721 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7722 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7723 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7724 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7725 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7726 | // There has been issues when Sms raw table somehow stores orphan |
| 7727 | // fragments. They lead to garbled message when new fragments come |
| 7728 | // in and combined with those stale ones. In case this happens again, |
| 7729 | // user can reset all network settings which will clean up this table. |
| 7730 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7731 | // Clean up IMS settings as well here. |
| 7732 | int slotId = getSlotIndex(subId); |
| 7733 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7734 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7735 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7736 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7737 | if (defaultPhone == null) { |
| 7738 | return; |
| 7739 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7740 | // Erase modem config if erase modem on network setting is enabled. |
| 7741 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7742 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7743 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7744 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7745 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7746 | |
| 7747 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7748 | } finally { |
| 7749 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7750 | } |
| 7751 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7752 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7753 | @VisibleForTesting |
| 7754 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7755 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7756 | return; |
| 7757 | } |
| 7758 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7759 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7760 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7761 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7762 | "user=" + defaultNetworkType); |
| 7763 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7764 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7765 | defaultNetworkType, null); |
| 7766 | } |
| 7767 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7768 | private void cleanUpSmsRawTable(Context context) { |
| 7769 | ContentResolver resolver = context.getContentResolver(); |
| 7770 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7771 | resolver.delete(uri, null, null); |
| 7772 | } |
| 7773 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7774 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7775 | public String getSimLocaleForSubscriber(int subId) { |
| 7776 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7777 | final Phone phone = getPhone(subId); |
| 7778 | if (phone == null) { |
| 7779 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7780 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7781 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7782 | final long identity = Binder.clearCallingIdentity(); |
| 7783 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7784 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7785 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7786 | if (info == null) { |
| 7787 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7788 | return null; |
| 7789 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7790 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7791 | // preferences (EF-PL and EF-LI)... |
| 7792 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7793 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7794 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7795 | if (localeFromDefaultSim != null) { |
| 7796 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7797 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7798 | + localeFromDefaultSim); |
| 7799 | return localeFromDefaultSim.toLanguageTag(); |
| 7800 | } else { |
| 7801 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7802 | } |
| 7803 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7804 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7805 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7806 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7807 | // the SIM and carrier preferences does not include a country we add the country |
| 7808 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7809 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7810 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7811 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7812 | return mccLocale.toLanguageTag(); |
| 7813 | } |
| 7814 | |
| 7815 | if (DBG) log("No locale found - returning null"); |
| 7816 | return null; |
| 7817 | } finally { |
| 7818 | Binder.restoreCallingIdentity(identity); |
| 7819 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7820 | } |
| 7821 | |
| 7822 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7823 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7824 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7825 | } |
| 7826 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7827 | /** |
| 7828 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7829 | */ |
| 7830 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7831 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7832 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7833 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7834 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7835 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7836 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7837 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7838 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7839 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7840 | * representing the state of the modem. |
| 7841 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7842 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7843 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7844 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7845 | */ |
| 7846 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7847 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7848 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7849 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7850 | |
| 7851 | final long identity = Binder.clearCallingIdentity(); |
| 7852 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7853 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7854 | } finally { |
| 7855 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7856 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7857 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7858 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7859 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7860 | // less than total activity duration. |
| 7861 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7862 | if (info == null) { |
| 7863 | return false; |
| 7864 | } |
| 7865 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7866 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7867 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7868 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7869 | return (info.isValid() |
| 7870 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7871 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7872 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7873 | && (totalTxTimeMs <= activityDurationMs)); |
| 7874 | } |
| 7875 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7876 | /** |
| 7877 | * {@hide} |
| 7878 | * Returns the service state information on specified subscription. |
| 7879 | */ |
| 7880 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7881 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7882 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7883 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7884 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7885 | return null; |
| 7886 | } |
| 7887 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7888 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7889 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7890 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7891 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7892 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7893 | .setCallingPid(Binder.getCallingPid()) |
| 7894 | .setCallingUid(Binder.getCallingUid()) |
| 7895 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7896 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7897 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7898 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7899 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7900 | .build()); |
| 7901 | |
| 7902 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7903 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7904 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7905 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7906 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7907 | .setCallingPid(Binder.getCallingPid()) |
| 7908 | .setCallingUid(Binder.getCallingUid()) |
| 7909 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7910 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7911 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7912 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7913 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7914 | .build()); |
| 7915 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7916 | boolean hasFinePermission = |
| 7917 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7918 | boolean hasCoarsePermission = |
| 7919 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7920 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7921 | final Phone phone = getPhone(subId); |
| 7922 | if (phone == null) { |
| 7923 | return null; |
| 7924 | } |
| 7925 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7926 | final long identity = Binder.clearCallingIdentity(); |
| 7927 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7928 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7929 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7930 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7931 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7932 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7933 | Rlog.d(LOG_TAG, |
| 7934 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7935 | return null; |
| 7936 | } |
| 7937 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7938 | ServiceState ss = phone.getServiceState(); |
| 7939 | |
| 7940 | // Scrub out the location info in ServiceState depending on what level of access |
| 7941 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7942 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7943 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7944 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7945 | } finally { |
| 7946 | Binder.restoreCallingIdentity(identity); |
| 7947 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7948 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7949 | |
| 7950 | /** |
| 7951 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7952 | * |
| 7953 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7954 | * voicemail ringtone. |
| 7955 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7956 | * PhoneAccount. |
| 7957 | */ |
| 7958 | @Override |
| 7959 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7960 | final long identity = Binder.clearCallingIdentity(); |
| 7961 | try { |
| 7962 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7963 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7964 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7965 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7966 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7967 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7968 | } finally { |
| 7969 | Binder.restoreCallingIdentity(identity); |
| 7970 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7971 | } |
| 7972 | |
| 7973 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7974 | * Sets the per-account voicemail ringtone. |
| 7975 | * |
| 7976 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7977 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7978 | * |
| 7979 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7980 | * voicemail ringtone. |
| 7981 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7982 | * PhoneAccount. |
| 7983 | */ |
| 7984 | @Override |
| 7985 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7986 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7987 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7988 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7989 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7990 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7991 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7992 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7993 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7994 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7995 | |
| 7996 | final long identity = Binder.clearCallingIdentity(); |
| 7997 | try { |
| 7998 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7999 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8000 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8001 | } |
| 8002 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8003 | } finally { |
| 8004 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8005 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8006 | } |
| 8007 | |
| 8008 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8009 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8010 | * |
| 8011 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8012 | * voicemail vibration setting. |
| 8013 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8014 | */ |
| 8015 | @Override |
| 8016 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8017 | final long identity = Binder.clearCallingIdentity(); |
| 8018 | try { |
| 8019 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8020 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8021 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8022 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8023 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8024 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8025 | } finally { |
| 8026 | Binder.restoreCallingIdentity(identity); |
| 8027 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8028 | } |
| 8029 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8030 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8031 | * Sets the per-account voicemail vibration. |
| 8032 | * |
| 8033 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8034 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8035 | * |
| 8036 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8037 | * voicemail vibration setting. |
| 8038 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8039 | * specific PhoneAccount. |
| 8040 | */ |
| 8041 | @Override |
| 8042 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8043 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8044 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8045 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8046 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8047 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8048 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8049 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8050 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8051 | } |
| 8052 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8053 | final long identity = Binder.clearCallingIdentity(); |
| 8054 | try { |
| 8055 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8056 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8057 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8058 | } |
| 8059 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8060 | } finally { |
| 8061 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8062 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8063 | } |
| 8064 | |
| 8065 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8066 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8067 | * |
| 8068 | * @throws SecurityException if the caller does not have the required permission |
| 8069 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8070 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8071 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8072 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8073 | } |
| 8074 | |
| 8075 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8076 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8077 | * permission. |
| 8078 | * |
| 8079 | * @throws SecurityException if the caller does not have the required permission |
| 8080 | */ |
| 8081 | private void enforceSendSmsPermission() { |
| 8082 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8083 | } |
| 8084 | |
| 8085 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8086 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8087 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8088 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8089 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8090 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8091 | final long identity = Binder.clearCallingIdentity(); |
| 8092 | try { |
| 8093 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8094 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8095 | if (componentName == null) { |
| 8096 | throw new SecurityException( |
| 8097 | "Caller not current active visual voicemail package[null]"); |
| 8098 | } |
| 8099 | String vvmPackage = componentName.getPackageName(); |
| 8100 | if (!callingPackage.equals(vvmPackage)) { |
| 8101 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 8102 | + vvmPackage + "]"); |
| 8103 | } |
| 8104 | } finally { |
| 8105 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8106 | } |
| 8107 | } |
| 8108 | |
| 8109 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8110 | * Return the application ID for the app type. |
| 8111 | * |
| 8112 | * @param subId the subscription ID that this request applies to. |
| 8113 | * @param appType the uicc app type. |
| 8114 | * @return Application ID for specificied app type, or null if no uicc. |
| 8115 | */ |
| 8116 | @Override |
| 8117 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8118 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8119 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8120 | |
| 8121 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8122 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8123 | if (phone == null) { |
| 8124 | return null; |
| 8125 | } |
| 8126 | String aid = null; |
| 8127 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8128 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8129 | .getApplicationByType(appType).getAid(); |
| 8130 | } catch (Exception e) { |
| 8131 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8132 | } |
| 8133 | return aid; |
| 8134 | } finally { |
| 8135 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8136 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8137 | } |
| 8138 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8139 | /** |
| 8140 | * Return the Electronic Serial Number. |
| 8141 | * |
| 8142 | * @param subId the subscription ID that this request applies to. |
| 8143 | * @return ESN or null if error. |
| 8144 | */ |
| 8145 | @Override |
| 8146 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8147 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8148 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8149 | |
| 8150 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8151 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8152 | if (phone == null) { |
| 8153 | return null; |
| 8154 | } |
| 8155 | String esn = null; |
| 8156 | try { |
| 8157 | esn = phone.getEsn(); |
| 8158 | } catch (Exception e) { |
| 8159 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8160 | } |
| 8161 | return esn; |
| 8162 | } finally { |
| 8163 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8164 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8165 | } |
| 8166 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8167 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8168 | * Return the Preferred Roaming List Version. |
| 8169 | * |
| 8170 | * @param subId the subscription ID that this request applies to. |
| 8171 | * @return PRLVersion or null if error. |
| 8172 | */ |
| 8173 | @Override |
| 8174 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8175 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8176 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8177 | |
| 8178 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8179 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8180 | if (phone == null) { |
| 8181 | return null; |
| 8182 | } |
| 8183 | String cdmaPrlVersion = null; |
| 8184 | try { |
| 8185 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8186 | } catch (Exception e) { |
| 8187 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8188 | } |
| 8189 | return cdmaPrlVersion; |
| 8190 | } finally { |
| 8191 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8192 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8193 | } |
| 8194 | |
| 8195 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8196 | * Get snapshot of Telephony histograms |
| 8197 | * @return List of Telephony histograms |
| 8198 | * @hide |
| 8199 | */ |
| 8200 | @Override |
| 8201 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8202 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8203 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8204 | |
| 8205 | final long identity = Binder.clearCallingIdentity(); |
| 8206 | try { |
| 8207 | return RIL.getTelephonyRILTimingHistograms(); |
| 8208 | } finally { |
| 8209 | Binder.restoreCallingIdentity(identity); |
| 8210 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8211 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8212 | |
| 8213 | /** |
| 8214 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8215 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8216 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8217 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8218 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8219 | * @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] | 8220 | */ |
| 8221 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8222 | @TelephonyManager.SetCarrierRestrictionResult |
| 8223 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8224 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8225 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8226 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8227 | if (carrierRestrictionRules == null) { |
| 8228 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8229 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8230 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8231 | final long identity = Binder.clearCallingIdentity(); |
| 8232 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8233 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8234 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8235 | } finally { |
| 8236 | Binder.restoreCallingIdentity(identity); |
| 8237 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8238 | } |
| 8239 | |
| 8240 | /** |
| 8241 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8242 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8243 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8244 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8245 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8246 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8247 | */ |
| 8248 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8249 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8250 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8251 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8252 | |
| 8253 | final long identity = Binder.clearCallingIdentity(); |
| 8254 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8255 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8256 | if (response instanceof CarrierRestrictionRules) { |
| 8257 | return (CarrierRestrictionRules) response; |
| 8258 | } |
| 8259 | // Response is an Exception of some kind, |
| 8260 | // which is signalled to the user as a NULL retval |
| 8261 | return null; |
| 8262 | } catch (Exception e) { |
| 8263 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8264 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8265 | } finally { |
| 8266 | Binder.restoreCallingIdentity(identity); |
| 8267 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8268 | } |
| 8269 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8270 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8271 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8272 | * @param subId the subscription ID that this action applies to. |
| 8273 | * @param enabled control enable or disable radio. |
| 8274 | * {@hide} |
| 8275 | */ |
| 8276 | @Override |
| 8277 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8278 | enforceModifyPermission(); |
| 8279 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8280 | |
| 8281 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8282 | if (phone == null) { |
| 8283 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8284 | return; |
| 8285 | } |
| 8286 | try { |
| 8287 | phone.carrierActionSetRadioEnabled(enabled); |
| 8288 | } catch (Exception e) { |
| 8289 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8290 | } finally { |
| 8291 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8292 | } |
| 8293 | } |
| 8294 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8295 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8296 | * Enable or disable Voice over NR (VoNR) |
| 8297 | * @param subId the subscription ID that this action applies to. |
| 8298 | * @param enabled enable or disable VoNR. |
| 8299 | * @return operation result. |
| 8300 | */ |
| 8301 | @Override |
| 8302 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8303 | enforceModifyPermission(); |
| 8304 | final Phone phone = getPhone(subId); |
| 8305 | |
| 8306 | final long identity = Binder.clearCallingIdentity(); |
| 8307 | if (phone == null) { |
| 8308 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8309 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8310 | } |
| 8311 | |
| 8312 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8313 | try { |
| 8314 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8315 | workSource); |
| 8316 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8317 | |
| 8318 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8319 | if (DBG) { |
| 8320 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8321 | } |
| 8322 | SubscriptionManager.setSubscriptionProperty( |
| 8323 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8324 | (enabled ? "1" : "0")); |
| 8325 | } |
| 8326 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8327 | return result; |
| 8328 | } finally { |
| 8329 | Binder.restoreCallingIdentity(identity); |
| 8330 | } |
| 8331 | } |
| 8332 | |
| 8333 | /** |
| 8334 | * Is voice over NR enabled |
| 8335 | * @return true if VoNR is enabled else false |
| 8336 | */ |
| 8337 | @Override |
| 8338 | public boolean isVoNrEnabled(int subId) { |
| 8339 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8340 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8341 | final long identity = Binder.clearCallingIdentity(); |
| 8342 | try { |
| 8343 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8344 | null, subId, workSource); |
| 8345 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8346 | return isEnabled; |
| 8347 | } finally { |
| 8348 | Binder.restoreCallingIdentity(identity); |
| 8349 | } |
| 8350 | } |
| 8351 | |
| 8352 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8353 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8354 | * network status based on which carrier apps could apply actions accordingly, |
| 8355 | * enable/disable default url handler for example. |
| 8356 | * |
| 8357 | * @param subId the subscription ID that this action applies to. |
| 8358 | * @param report control start/stop reporting the default network status. |
| 8359 | * {@hide} |
| 8360 | */ |
| 8361 | @Override |
| 8362 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8363 | enforceModifyPermission(); |
| 8364 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8365 | |
| 8366 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8367 | if (phone == null) { |
| 8368 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8369 | return; |
| 8370 | } |
| 8371 | try { |
| 8372 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8373 | } catch (Exception e) { |
| 8374 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8375 | } finally { |
| 8376 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8377 | } |
| 8378 | } |
| 8379 | |
| 8380 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8381 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8382 | * @param subId the subscription ID that this action applies to. |
| 8383 | * {@hide} |
| 8384 | */ |
| 8385 | @Override |
| 8386 | public void carrierActionResetAll(int subId) { |
| 8387 | enforceModifyPermission(); |
| 8388 | final Phone phone = getPhone(subId); |
| 8389 | if (phone == null) { |
| 8390 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8391 | return; |
| 8392 | } |
| 8393 | try { |
| 8394 | phone.carrierActionResetAll(); |
| 8395 | } catch (Exception e) { |
| 8396 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8397 | } |
| 8398 | } |
| 8399 | |
| 8400 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8401 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8402 | * bug report is being generated. |
| 8403 | */ |
| 8404 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8405 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8406 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8407 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8408 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8409 | + Binder.getCallingPid() |
| 8410 | + ", uid=" + Binder.getCallingUid() |
| 8411 | + "without permission " |
| 8412 | + android.Manifest.permission.DUMP); |
| 8413 | return; |
| 8414 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8415 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8416 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8417 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8418 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8419 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8420 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8421 | @NonNull String[] args) { |
| 8422 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8423 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8424 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8425 | } |
| 8426 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8427 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8428 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8429 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8430 | * @param reason the reason the data enable change is taking place |
| 8431 | * @param enabled True if enabling the data, otherwise disabling. |
| 8432 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8433 | */ |
| 8434 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8435 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8436 | boolean enabled) { |
| 8437 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8438 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8439 | try { |
| 8440 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8441 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8442 | } catch (SecurityException se) { |
| 8443 | enforceModifyPermission(); |
| 8444 | } |
| 8445 | } else { |
| 8446 | enforceModifyPermission(); |
| 8447 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8448 | |
| 8449 | final long identity = Binder.clearCallingIdentity(); |
| 8450 | try { |
| 8451 | Phone phone = getPhone(subId); |
| 8452 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8453 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8454 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8455 | } else { |
| 8456 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 8457 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8458 | } |
| 8459 | } finally { |
| 8460 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8461 | } |
| 8462 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8463 | |
| 8464 | /** |
| 8465 | * Get Client request stats |
| 8466 | * @return List of Client Request Stats |
| 8467 | * @hide |
| 8468 | */ |
| 8469 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8470 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8471 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8472 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8473 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8474 | return null; |
| 8475 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8476 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8477 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8478 | final long identity = Binder.clearCallingIdentity(); |
| 8479 | try { |
| 8480 | if (phone != null) { |
| 8481 | return phone.getClientRequestStats(); |
| 8482 | } |
| 8483 | |
| 8484 | return null; |
| 8485 | } finally { |
| 8486 | Binder.restoreCallingIdentity(identity); |
| 8487 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8488 | } |
| 8489 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8490 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8491 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8492 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8493 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8494 | |
| 8495 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8496 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8497 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8498 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8499 | * @param state State of SIM (power down, power up, pass through) |
| 8500 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8501 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8502 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8503 | * |
| 8504 | **/ |
| 8505 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8506 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8507 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8508 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8509 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8510 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8511 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8512 | final long identity = Binder.clearCallingIdentity(); |
| 8513 | try { |
| 8514 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8515 | phone.setSimPowerState(state, null, workSource); |
| 8516 | } |
| 8517 | } finally { |
| 8518 | Binder.restoreCallingIdentity(identity); |
| 8519 | } |
| 8520 | } |
| 8521 | |
| 8522 | /** |
| 8523 | * Set SIM card power state. |
| 8524 | * |
| 8525 | * @param slotIndex SIM slot id. |
| 8526 | * @param state State of SIM (power down, power up, pass through) |
| 8527 | * @param callback callback to trigger after success or failure |
| 8528 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8529 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8530 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8531 | * |
| 8532 | **/ |
| 8533 | @Override |
| 8534 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8535 | IIntegerConsumer callback) { |
| 8536 | enforceModifyPermission(); |
| 8537 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8538 | |
| 8539 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8540 | |
| 8541 | final long identity = Binder.clearCallingIdentity(); |
| 8542 | try { |
| 8543 | if (phone != null) { |
| 8544 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8545 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8546 | } |
| 8547 | } finally { |
| 8548 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8549 | } |
| 8550 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8551 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8552 | private boolean isUssdApiAllowed(int subId) { |
| 8553 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8554 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8555 | if (configManager == null) { |
| 8556 | return false; |
| 8557 | } |
| 8558 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8559 | if (pb == null) { |
| 8560 | return false; |
| 8561 | } |
| 8562 | return pb.getBoolean( |
| 8563 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8564 | } |
| 8565 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8566 | /** |
| 8567 | * Check if phone is in emergency callback mode |
| 8568 | * @return true if phone is in emergency callback mode |
| 8569 | * @param subId sub id |
| 8570 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8571 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8572 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8573 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8574 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8575 | |
| 8576 | final long identity = Binder.clearCallingIdentity(); |
| 8577 | try { |
| 8578 | if (phone != null) { |
| 8579 | return phone.isInEcm(); |
| 8580 | } else { |
| 8581 | return false; |
| 8582 | } |
| 8583 | } finally { |
| 8584 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8585 | } |
| 8586 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8587 | |
| 8588 | /** |
| 8589 | * Get the current signal strength information for the given subscription. |
| 8590 | * Because this information is not updated when the device is in a low power state |
| 8591 | * it should not be relied-upon to be current. |
| 8592 | * @param subId Subscription index |
| 8593 | * @return the most recent cached signal strength info from the modem |
| 8594 | */ |
| 8595 | @Override |
| 8596 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8597 | final long identity = Binder.clearCallingIdentity(); |
| 8598 | try { |
| 8599 | Phone p = getPhone(subId); |
| 8600 | if (p == null) { |
| 8601 | return null; |
| 8602 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8603 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8604 | return p.getSignalStrength(); |
| 8605 | } finally { |
| 8606 | Binder.restoreCallingIdentity(identity); |
| 8607 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8608 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8609 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8610 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8611 | * Get the current modem radio state for the given slot. |
| 8612 | * @param slotIndex slot index. |
| 8613 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8614 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8615 | * @return the current radio power state from the modem |
| 8616 | */ |
| 8617 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8618 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8619 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8620 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8621 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8622 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8623 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8624 | } |
| 8625 | |
| 8626 | final long identity = Binder.clearCallingIdentity(); |
| 8627 | try { |
| 8628 | return phone.getRadioPowerState(); |
| 8629 | } finally { |
| 8630 | Binder.restoreCallingIdentity(identity); |
| 8631 | } |
| 8632 | } |
| 8633 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8634 | } |
| 8635 | |
| 8636 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8637 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8638 | * |
| 8639 | * <p>Requires one of the following permissions: |
| 8640 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8641 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8642 | * privileges. |
| 8643 | * |
| 8644 | * @param subId subscription id |
| 8645 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8646 | * {@code false}. |
| 8647 | */ |
| 8648 | @Override |
| 8649 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8650 | try { |
| 8651 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8652 | null); |
| 8653 | } catch (Exception e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8654 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8655 | mApp, subId, "isDataRoamingEnabled"); |
| 8656 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8657 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8658 | boolean isEnabled = false; |
| 8659 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8660 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8661 | Phone phone = getPhone(subId); |
| 8662 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8663 | } finally { |
| 8664 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8665 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8666 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8667 | } |
| 8668 | |
| 8669 | |
| 8670 | /** |
| 8671 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8672 | * |
| 8673 | * <p> Requires permission: |
| 8674 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8675 | * privileges. |
| 8676 | * |
| 8677 | * @param subId subscription id |
| 8678 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8679 | */ |
| 8680 | @Override |
| 8681 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8682 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8683 | mApp, subId, "setDataRoamingEnabled"); |
| 8684 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8685 | final long identity = Binder.clearCallingIdentity(); |
| 8686 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8687 | Phone phone = getPhone(subId); |
| 8688 | if (phone != null) { |
| 8689 | phone.setDataRoamingEnabled(isEnabled); |
| 8690 | } |
| 8691 | } finally { |
| 8692 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8693 | } |
| 8694 | } |
| 8695 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8696 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8697 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8698 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8699 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8700 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8701 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8702 | boolean isAllowed = true; |
| 8703 | final long identity = Binder.clearCallingIdentity(); |
| 8704 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8705 | Phone phone = getPhone(subId); |
| 8706 | if (phone != null) { |
| 8707 | isAllowed = phone.isCspPlmnEnabled(); |
| 8708 | } |
| 8709 | } finally { |
| 8710 | Binder.restoreCallingIdentity(identity); |
| 8711 | } |
| 8712 | return isAllowed; |
| 8713 | } |
| 8714 | |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8715 | private boolean haveCarrierPrivilegeAccess(UiccCard card, String callingPackage) { |
| 8716 | // TODO once MEP API refactoring CL is merged, loop port list from UiccCardInfo, |
| 8717 | // and if find the matching UiccPort by UiccController.getUiccPortForSlot(slot, portIdx) |
| 8718 | // Update each UiccPort object based on privilege access |
| 8719 | UiccPort[] uiccPorts = card.getUiccPortList(); |
| 8720 | for (UiccPort port : uiccPorts) { |
| 8721 | UiccProfile profile = port.getUiccProfile(); |
| 8722 | if (profile == null || |
| 8723 | profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8724 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8725 | return false; |
| 8726 | } |
| 8727 | } |
| 8728 | return true; |
| 8729 | } |
| 8730 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8731 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8732 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8733 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8734 | mApp.getSystemService(AppOpsManager.class) |
| 8735 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8736 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8737 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8738 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8739 | try { |
| 8740 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8741 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8742 | } catch (SecurityException e) { |
| 8743 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8744 | // has carrier privileges on an active UICC |
| 8745 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8746 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8747 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8748 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8749 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8750 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8751 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8752 | Binder.getCallingUid())) { |
| 8753 | isIccIdAccessRestricted = true; |
| 8754 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8755 | final long identity = Binder.clearCallingIdentity(); |
| 8756 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8757 | UiccController uiccController = UiccController.getInstance(); |
| 8758 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8759 | if (hasReadPermission) { |
| 8760 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8761 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8762 | |
| 8763 | // Remove private info if the caller doesn't have access |
| 8764 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8765 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8766 | //setting the value after compatibility check |
| 8767 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8768 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8769 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8770 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8771 | // TODO remove card.getUiccPortList().length once MEP API refactoring CL is merged |
| 8772 | // Get UiccPortInfo from CardInfo and process further based on each UiccPort |
| 8773 | if (card == null || card.getUiccPortList().length == 0) { |
| 8774 | // assume no access if the card or ports are unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8775 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8776 | continue; |
| 8777 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8778 | if (haveCarrierPrivilegeAccess(card, callingPackage)) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8779 | filteredInfos.add(cardInfo); |
| 8780 | } else { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8781 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8782 | } |
| 8783 | } |
| 8784 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8785 | } finally { |
| 8786 | Binder.restoreCallingIdentity(identity); |
| 8787 | } |
| 8788 | } |
| 8789 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8790 | /** |
| 8791 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 8792 | * generally private and require carrier privileges to view. |
| 8793 | * |
| 8794 | * @hide |
| 8795 | */ |
| 8796 | @NonNull |
| 8797 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 8798 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 8799 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 8800 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 8801 | } |
| 8802 | return new UiccCardInfo( |
| 8803 | cardInfo.isEuicc(), |
| 8804 | cardInfo.getCardId(), |
| 8805 | null, |
| 8806 | cardInfo.getPhysicalSlotIndex(), |
| 8807 | cardInfo.isRemovable(), |
| 8808 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8809 | portinfo |
| 8810 | ); |
| 8811 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8812 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8813 | /** |
| 8814 | * @hide |
| 8815 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 8816 | * These values are generally private and require carrier privileges to view. |
| 8817 | */ |
| 8818 | @NonNull |
| 8819 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 8820 | return new UiccPortInfo( |
| 8821 | UiccPortInfo.ICCID_REDACTED, |
| 8822 | portInfo.getPortIndex(), |
| 8823 | portInfo.getLogicalSlotIndex(), |
| 8824 | portInfo.isActive() |
| 8825 | ); |
| 8826 | } |
| 8827 | @Override |
| 8828 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8829 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8830 | mApp.getSystemService(AppOpsManager.class) |
| 8831 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8832 | |
| 8833 | boolean hasReadPermission = false; |
| 8834 | boolean isLogicalSlotAccessRestricted = false; |
| 8835 | String iccId; |
| 8836 | |
| 8837 | try { |
| 8838 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
| 8839 | hasReadPermission = true; |
| 8840 | } catch (SecurityException e) { |
| 8841 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8842 | // has carrier privileges on an active UICC |
| 8843 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8844 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8845 | hasReadPermission = true; |
| 8846 | } |
| 8847 | } |
| 8848 | |
| 8849 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8850 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8851 | Binder.getCallingUid())) { |
| 8852 | isLogicalSlotAccessRestricted = true; |
| 8853 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8854 | final long identity = Binder.clearCallingIdentity(); |
| 8855 | try { |
| 8856 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8857 | if (slots == null) { |
| 8858 | Rlog.i(LOG_TAG, "slots is null."); |
| 8859 | return null; |
| 8860 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8861 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8862 | for (int i = 0; i < slots.length; i++) { |
| 8863 | UiccSlot slot = slots[i]; |
| 8864 | if (slot == null) { |
| 8865 | continue; |
| 8866 | } |
| 8867 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8868 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8869 | UiccCard card = slot.getUiccCard(); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8870 | //if has read permission |
| 8871 | if (hasReadPermission) { |
| 8872 | iccId = slot.getIccId(); |
| 8873 | } else { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8874 | if (card != null) { |
| 8875 | // if no read permission checking carrier |
| 8876 | if (haveCarrierPrivilegeAccess(card, callingPackage)) { |
| 8877 | iccId = slot.getIccId(); |
| 8878 | } else { |
| 8879 | //if no carrier permission redact ICCID |
| 8880 | iccId = IccUtils.TEST_ICCID; |
| 8881 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8882 | } else { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8883 | iccId = null; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8884 | } |
| 8885 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8886 | if (card != null) { |
| 8887 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8888 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8889 | cardId = slot.getEid(); |
| 8890 | if (TextUtils.isEmpty(cardId)) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8891 | cardId = iccId; |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8892 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8893 | } |
| 8894 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8895 | if (cardId != null) { |
| 8896 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8897 | // if cardId is an EID, it's all digits so this is fine |
| 8898 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8899 | } |
| 8900 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8901 | int cardState = 0; |
| 8902 | switch (slot.getCardState()) { |
| 8903 | case CARDSTATE_ABSENT: |
| 8904 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8905 | break; |
| 8906 | case CARDSTATE_PRESENT: |
| 8907 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8908 | break; |
| 8909 | case CARDSTATE_ERROR: |
| 8910 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8911 | break; |
| 8912 | case CARDSTATE_RESTRICTED: |
| 8913 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8914 | break; |
| 8915 | default: |
| 8916 | break; |
| 8917 | |
| 8918 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8919 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8920 | slot.isEuicc(), |
| 8921 | cardId, |
| 8922 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8923 | slot.isExtendedApduSupported(), |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8924 | slot.isRemovable(), Collections.singletonList( |
| 8925 | new UiccPortInfo( |
| 8926 | iccId, |
| 8927 | 0 /* TODO: to use portList from UiccSlots */, |
| 8928 | slot.getPhoneId(), |
| 8929 | slot.isActive()))); |
| 8930 | //setting the value after compatibility check |
| 8931 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8932 | } |
| 8933 | return infos; |
| 8934 | } finally { |
| 8935 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8936 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8937 | } |
| 8938 | |
| 8939 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8940 | @Deprecated |
| 8941 | //TODO : once integrating with HAL Changes we can clean up this Internal API. |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8942 | public boolean switchSlots(int[] physicalSlots) { |
| 8943 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8944 | |
| 8945 | final long identity = Binder.clearCallingIdentity(); |
| 8946 | try { |
| 8947 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8948 | } finally { |
| 8949 | Binder.restoreCallingIdentity(identity); |
| 8950 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8951 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8952 | |
| 8953 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8954 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 8955 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 8956 | enforceModifyPermission(); |
| 8957 | |
| 8958 | final long identity = Binder.clearCallingIdentity(); |
| 8959 | try { |
| 8960 | //TODO: once integrating the HAL changes we can proceed with to work on the parsing side |
| 8961 | int[] physicalSlots = new int[slotMapping.size()]; |
| 8962 | for (int i = 0; i < physicalSlots.length; i++) { |
| 8963 | physicalSlots[i] = slotMapping.get(i).getPhysicalSlotIndex(); |
| 8964 | } |
| 8965 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8966 | } finally { |
| 8967 | Binder.restoreCallingIdentity(identity); |
| 8968 | } |
| 8969 | } |
| 8970 | |
| 8971 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8972 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8973 | final long identity = Binder.clearCallingIdentity(); |
| 8974 | try { |
| 8975 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8976 | } finally { |
| 8977 | Binder.restoreCallingIdentity(identity); |
| 8978 | } |
| 8979 | } |
| 8980 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8981 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8982 | * A test API to reload the UICC profile. |
| 8983 | * |
| 8984 | * <p>Requires that the calling app has permission |
| 8985 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8986 | * @hide |
| 8987 | */ |
| 8988 | @Override |
| 8989 | public void refreshUiccProfile(int subId) { |
| 8990 | enforceModifyPermission(); |
| 8991 | |
| 8992 | final long identity = Binder.clearCallingIdentity(); |
| 8993 | try { |
| 8994 | Phone phone = getPhone(subId); |
| 8995 | if (phone == null) { |
| 8996 | return; |
| 8997 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8998 | UiccPort uiccPort = phone.getUiccPort(); |
| 8999 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9000 | return; |
| 9001 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9002 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9003 | if (uiccProfile == null) { |
| 9004 | return; |
| 9005 | } |
| 9006 | uiccProfile.refresh(); |
| 9007 | } finally { |
| 9008 | Binder.restoreCallingIdentity(identity); |
| 9009 | } |
| 9010 | } |
| 9011 | |
| 9012 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9013 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9014 | */ |
| 9015 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9016 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9017 | } |
| 9018 | |
| 9019 | /** |
| 9020 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9021 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9022 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9023 | */ |
| 9024 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9025 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9026 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9027 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9028 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9029 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9030 | return isDataRoamingEnabled; |
| 9031 | } |
| 9032 | |
| 9033 | /** |
| 9034 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9035 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9036 | */ |
| 9037 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9038 | List<Integer> list = TelephonyProperties.default_network(); |
| 9039 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 9040 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9041 | return list.get(phoneId); |
| 9042 | } |
| 9043 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9044 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9045 | |
| 9046 | @Override |
| 9047 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9048 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9049 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9050 | |
| 9051 | final long identity = Binder.clearCallingIdentity(); |
| 9052 | try { |
| 9053 | final Phone phone = getPhone(subId); |
| 9054 | if (phone == null) { |
| 9055 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9056 | return; |
| 9057 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9058 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9059 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9060 | if (carrierPrivilegeRules == null) { |
| 9061 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9062 | } else { |
| 9063 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9064 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9065 | } finally { |
| 9066 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9067 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9068 | } |
| 9069 | |
| 9070 | @Override |
| 9071 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9072 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9073 | |
| 9074 | final long identity = Binder.clearCallingIdentity(); |
| 9075 | try { |
| 9076 | final Phone phone = getPhone(subId); |
| 9077 | if (phone == null) { |
| 9078 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9079 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9080 | } |
| 9081 | return phone.getCarrierIdListVersion(); |
| 9082 | } finally { |
| 9083 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9084 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9085 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9086 | |
| 9087 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9088 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9089 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9090 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9091 | mApp, subId, callingPackage, callingFeatureId, |
| 9092 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9093 | return -1; |
| 9094 | } |
| 9095 | |
| 9096 | final long identity = Binder.clearCallingIdentity(); |
| 9097 | try { |
| 9098 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9099 | } finally { |
| 9100 | Binder.restoreCallingIdentity(identity); |
| 9101 | } |
| 9102 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9103 | |
| 9104 | @Override |
| 9105 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9106 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9107 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9108 | mApp, subId, "getCdmaRoamingMode"); |
| 9109 | |
| 9110 | final long identity = Binder.clearCallingIdentity(); |
| 9111 | try { |
| 9112 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9113 | } finally { |
| 9114 | Binder.restoreCallingIdentity(identity); |
| 9115 | } |
| 9116 | } |
| 9117 | |
| 9118 | @Override |
| 9119 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9120 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9121 | mApp, subId, "setCdmaRoamingMode"); |
| 9122 | |
| 9123 | final long identity = Binder.clearCallingIdentity(); |
| 9124 | try { |
| 9125 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9126 | } finally { |
| 9127 | Binder.restoreCallingIdentity(identity); |
| 9128 | } |
| 9129 | } |
| 9130 | |
| 9131 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9132 | public int getCdmaSubscriptionMode(int subId) { |
| 9133 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9134 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9135 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9136 | |
| 9137 | final long identity = Binder.clearCallingIdentity(); |
| 9138 | try { |
| 9139 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9140 | } finally { |
| 9141 | Binder.restoreCallingIdentity(identity); |
| 9142 | } |
| 9143 | } |
| 9144 | |
| 9145 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9146 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9147 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9148 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9149 | |
| 9150 | final long identity = Binder.clearCallingIdentity(); |
| 9151 | try { |
| 9152 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9153 | } finally { |
| 9154 | Binder.restoreCallingIdentity(identity); |
| 9155 | } |
| 9156 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9157 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9158 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9159 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9160 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9161 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9162 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9163 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9164 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9165 | } |
| 9166 | final long identity = Binder.clearCallingIdentity(); |
| 9167 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9168 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9169 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9170 | if (phone.getEmergencyNumberTracker() != null |
| 9171 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9172 | emergencyNumberListInternal.put( |
| 9173 | phone.getSubId(), |
| 9174 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9175 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9176 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9177 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9178 | } finally { |
| 9179 | Binder.restoreCallingIdentity(identity); |
| 9180 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9181 | } |
| 9182 | |
| 9183 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9184 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9185 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9186 | if (!exactMatch) { |
| 9187 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9188 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9189 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9190 | } |
| 9191 | final long identity = Binder.clearCallingIdentity(); |
| 9192 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9193 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9194 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9195 | && phone.getEmergencyNumberTracker() |
| 9196 | .isEmergencyNumber(number, exactMatch)) { |
| 9197 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9198 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9199 | } |
| 9200 | return false; |
| 9201 | } finally { |
| 9202 | Binder.restoreCallingIdentity(identity); |
| 9203 | } |
| 9204 | } |
| 9205 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9206 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9207 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9208 | */ |
| 9209 | @Override |
| 9210 | public void startEmergencyCallbackMode() { |
| 9211 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9212 | "startEmergencyCallbackMode"); |
| 9213 | enforceModifyPermission(); |
| 9214 | final long identity = Binder.clearCallingIdentity(); |
| 9215 | try { |
| 9216 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9217 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9218 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9219 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9220 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9221 | gsmCdmaPhone.obtainMessage( |
| 9222 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9223 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9224 | } |
| 9225 | } |
| 9226 | } finally { |
| 9227 | Binder.restoreCallingIdentity(identity); |
| 9228 | } |
| 9229 | } |
| 9230 | |
| 9231 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9232 | * Update emergency number list for test mode. |
| 9233 | */ |
| 9234 | @Override |
| 9235 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9236 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9237 | "updateEmergencyNumberListTestMode"); |
| 9238 | |
| 9239 | final long identity = Binder.clearCallingIdentity(); |
| 9240 | try { |
| 9241 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9242 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9243 | if (tracker != null) { |
| 9244 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9245 | } |
| 9246 | } |
| 9247 | } finally { |
| 9248 | Binder.restoreCallingIdentity(identity); |
| 9249 | } |
| 9250 | } |
| 9251 | |
| 9252 | /** |
| 9253 | * Get the full emergency number list for test mode. |
| 9254 | */ |
| 9255 | @Override |
| 9256 | public List<String> getEmergencyNumberListTestMode() { |
| 9257 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9258 | "getEmergencyNumberListTestMode"); |
| 9259 | |
| 9260 | final long identity = Binder.clearCallingIdentity(); |
| 9261 | try { |
| 9262 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9263 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9264 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9265 | if (tracker != null) { |
| 9266 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9267 | emergencyNumbers.add(num.getNumber()); |
| 9268 | } |
| 9269 | } |
| 9270 | } |
| 9271 | return new ArrayList<>(emergencyNumbers); |
| 9272 | } finally { |
| 9273 | Binder.restoreCallingIdentity(identity); |
| 9274 | } |
| 9275 | } |
| 9276 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9277 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9278 | public int getEmergencyNumberDbVersion(int subId) { |
| 9279 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9280 | |
| 9281 | final long identity = Binder.clearCallingIdentity(); |
| 9282 | try { |
| 9283 | final Phone phone = getPhone(subId); |
| 9284 | if (phone == null) { |
| 9285 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9286 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9287 | } |
| 9288 | return phone.getEmergencyNumberDbVersion(); |
| 9289 | } finally { |
| 9290 | Binder.restoreCallingIdentity(identity); |
| 9291 | } |
| 9292 | } |
| 9293 | |
| 9294 | @Override |
| 9295 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9296 | enforceModifyPermission(); |
| 9297 | |
| 9298 | final long identity = Binder.clearCallingIdentity(); |
| 9299 | try { |
| 9300 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9301 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9302 | if (tracker != null) { |
| 9303 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9304 | } |
| 9305 | } |
| 9306 | } finally { |
| 9307 | Binder.restoreCallingIdentity(identity); |
| 9308 | } |
| 9309 | } |
| 9310 | |
| 9311 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9312 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9313 | enforceActiveEmergencySessionPermission(); |
| 9314 | |
| 9315 | final long identity = Binder.clearCallingIdentity(); |
| 9316 | try { |
| 9317 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9318 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9319 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9320 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9321 | } |
| 9322 | } |
| 9323 | } finally { |
| 9324 | Binder.restoreCallingIdentity(identity); |
| 9325 | } |
| 9326 | } |
| 9327 | |
| 9328 | @Override |
| 9329 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9330 | enforceActiveEmergencySessionPermission(); |
| 9331 | |
| 9332 | final long identity = Binder.clearCallingIdentity(); |
| 9333 | try { |
| 9334 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9335 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9336 | if (tracker != null) { |
| 9337 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9338 | } |
| 9339 | } |
| 9340 | } finally { |
| 9341 | Binder.restoreCallingIdentity(identity); |
| 9342 | } |
| 9343 | } |
| 9344 | |
| 9345 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9346 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9347 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9348 | Phone phone = getPhone(subId); |
| 9349 | if (phone == null) { |
| 9350 | return null; |
| 9351 | } |
| 9352 | final long identity = Binder.clearCallingIdentity(); |
| 9353 | try { |
| 9354 | UiccProfile profile = UiccController.getInstance() |
| 9355 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9356 | if (profile != null) { |
| 9357 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9358 | } |
| 9359 | } finally { |
| 9360 | Binder.restoreCallingIdentity(identity); |
| 9361 | } |
| 9362 | return null; |
| 9363 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9364 | |
| 9365 | /** |
| 9366 | * Enable or disable a modem stack. |
| 9367 | */ |
| 9368 | @Override |
| 9369 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9370 | enforceModifyPermission(); |
| 9371 | |
| 9372 | final long identity = Binder.clearCallingIdentity(); |
| 9373 | try { |
| 9374 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9375 | if (phone == null) { |
| 9376 | return false; |
| 9377 | } else { |
| 9378 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9379 | } |
| 9380 | } finally { |
| 9381 | Binder.restoreCallingIdentity(identity); |
| 9382 | } |
| 9383 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9384 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9385 | /** |
| 9386 | * Whether a modem stack is enabled or not. |
| 9387 | */ |
| 9388 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9389 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9390 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9391 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9392 | if (phone == null) return false; |
| 9393 | |
| 9394 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9395 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9396 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9397 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9398 | } |
| 9399 | |
| 9400 | final long identity = Binder.clearCallingIdentity(); |
| 9401 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9402 | try { |
| 9403 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9404 | } catch (NoSuchElementException ex) { |
| 9405 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9406 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9407 | } finally { |
| 9408 | Binder.restoreCallingIdentity(identity); |
| 9409 | } |
| 9410 | } |
| 9411 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9412 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9413 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9414 | enforceModifyPermission(); |
| 9415 | |
| 9416 | final long identity = Binder.clearCallingIdentity(); |
| 9417 | try { |
| 9418 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9419 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9420 | .commit(); |
| 9421 | } finally { |
| 9422 | Binder.restoreCallingIdentity(identity); |
| 9423 | } |
| 9424 | } |
| 9425 | |
| 9426 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9427 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9428 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9429 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9430 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9431 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9432 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9433 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9434 | |
| 9435 | final long identity = Binder.clearCallingIdentity(); |
| 9436 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9437 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9438 | } finally { |
| 9439 | Binder.restoreCallingIdentity(identity); |
| 9440 | } |
| 9441 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9442 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9443 | @TelephonyManager.IsMultiSimSupportedResult |
| 9444 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9445 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9446 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9447 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9448 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9449 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9450 | } |
| 9451 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9452 | // supported by the modem, indicate that it is restricted. |
| 9453 | PhoneCapability staticCapability = |
| 9454 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9455 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9456 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9457 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9458 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9459 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9460 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9461 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9462 | } |
| 9463 | // Check if support of multiple SIMs is restricted by carrier |
| 9464 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9465 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9466 | } |
| 9467 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9468 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9469 | } |
| 9470 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9471 | /** |
| 9472 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9473 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9474 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9475 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9476 | * @param numOfSims number of active sims we want to switch to |
| 9477 | */ |
| 9478 | @Override |
| 9479 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9480 | if (numOfSims == 1) { |
| 9481 | enforceModifyPermission(); |
| 9482 | } else { |
| 9483 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9484 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9485 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9486 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9487 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9488 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9489 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9490 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9491 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9492 | return; |
| 9493 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9494 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9495 | } finally { |
| 9496 | Binder.restoreCallingIdentity(identity); |
| 9497 | } |
| 9498 | } |
| 9499 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9500 | @Override |
| 9501 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9502 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9503 | Phone phone = getPhone(subId); |
| 9504 | if (phone == null) { |
| 9505 | return false; |
| 9506 | } |
| 9507 | final long identity = Binder.clearCallingIdentity(); |
| 9508 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9509 | UiccPort uiccPort = phone.getUiccPort(); |
| 9510 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9511 | return false; |
| 9512 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9513 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9514 | if (uiccProfile == null) { |
| 9515 | return false; |
| 9516 | } |
| 9517 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9518 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9519 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9520 | } |
| 9521 | return false; |
| 9522 | } finally { |
| 9523 | Binder.restoreCallingIdentity(identity); |
| 9524 | } |
| 9525 | } |
| 9526 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9527 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9528 | * Get whether making changes to modem configurations will trigger reboot. |
| 9529 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9530 | */ |
| 9531 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9532 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9533 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9534 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9535 | mApp, subId, callingPackage, callingFeatureId, |
| 9536 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9537 | return false; |
| 9538 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9539 | final long identity = Binder.clearCallingIdentity(); |
| 9540 | try { |
| 9541 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9542 | } finally { |
| 9543 | Binder.restoreCallingIdentity(identity); |
| 9544 | } |
| 9545 | } |
| 9546 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9547 | private void updateModemStateMetrics() { |
| 9548 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9549 | // TODO: check the state for each modem if the api is ready. |
| 9550 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9551 | } |
| 9552 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9553 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9554 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9555 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9556 | // Verify that the callingPackage belongs to the calling UID |
| 9557 | mApp.getSystemService(AppOpsManager.class) |
| 9558 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9559 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9560 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9561 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9562 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 9563 | if (slotInfos != null) { |
| 9564 | for (int i = 0; i < slotInfos.length; i++) { |
| 9565 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 9566 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 9567 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 9568 | portInfo.getLogicalSlotIndex())); |
| 9569 | } |
| 9570 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9571 | } |
| 9572 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9573 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9574 | } finally { |
| 9575 | Binder.restoreCallingIdentity(identity); |
| 9576 | } |
| 9577 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9578 | |
| 9579 | /** |
| 9580 | * Get the IRadio HAL Version |
| 9581 | */ |
| 9582 | @Override |
| 9583 | public int getRadioHalVersion() { |
| 9584 | Phone phone = getDefaultPhone(); |
| 9585 | if (phone == null) return -1; |
| 9586 | HalVersion hv = phone.getHalVersion(); |
| 9587 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9588 | return hv.major * 100 + hv.minor; |
| 9589 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9590 | |
| 9591 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9592 | * Get the current calling package name. |
| 9593 | * @return the current calling package name |
| 9594 | */ |
| 9595 | @Override |
| 9596 | public String getCurrentPackageName() { |
| 9597 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9598 | } |
| 9599 | |
| 9600 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9601 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9602 | * corresponding network requests on a subId. |
| 9603 | * |
| 9604 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9605 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9606 | * 2) APN is un-metered for this subscription, or |
| 9607 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9608 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9609 | * |
| 9610 | * @return whether data is allowed for a apn type. |
| 9611 | * |
| 9612 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9613 | */ |
| 9614 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9615 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9616 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9617 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9618 | |
| 9619 | // Now that all security checks passes, perform the operation as ourselves. |
| 9620 | final long identity = Binder.clearCallingIdentity(); |
| 9621 | try { |
| 9622 | Phone phone = getPhone(subId); |
| 9623 | if (phone == null) return false; |
| 9624 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9625 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9626 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9627 | } finally { |
| 9628 | Binder.restoreCallingIdentity(identity); |
| 9629 | } |
| 9630 | } |
| 9631 | |
| 9632 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9633 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9634 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9635 | |
| 9636 | // Now that all security checks passes, perform the operation as ourselves. |
| 9637 | final long identity = Binder.clearCallingIdentity(); |
| 9638 | try { |
| 9639 | Phone phone = getPhone(subId); |
| 9640 | if (phone == null) return true; // By default return true. |
| 9641 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9642 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9643 | } finally { |
| 9644 | Binder.restoreCallingIdentity(identity); |
| 9645 | } |
| 9646 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9647 | |
| 9648 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9649 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9650 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9651 | enforceModifyPermission(); |
| 9652 | long token = Binder.clearCallingIdentity(); |
| 9653 | try { |
| 9654 | Phone phone = getPhone(subscriptionId); |
| 9655 | if (phone == null) { |
| 9656 | try { |
| 9657 | if (resultCallback != null) { |
| 9658 | resultCallback.accept(false); |
| 9659 | } |
| 9660 | } catch (RemoteException e) { |
| 9661 | // ignore |
| 9662 | } |
| 9663 | return; |
| 9664 | } |
| 9665 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9666 | Pair.create(specifiers, (x) -> { |
| 9667 | try { |
| 9668 | if (resultCallback != null) { |
| 9669 | resultCallback.accept(x); |
| 9670 | } |
| 9671 | } catch (RemoteException e) { |
| 9672 | // ignore |
| 9673 | } |
| 9674 | }); |
| 9675 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9676 | } finally { |
| 9677 | Binder.restoreCallingIdentity(token); |
| 9678 | } |
| 9679 | } |
| 9680 | |
| 9681 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9682 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9683 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9684 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9685 | mApp, subId, "getSystemSelectionChannels"); |
| 9686 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9687 | final long identity = Binder.clearCallingIdentity(); |
| 9688 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 9689 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 9690 | if (result instanceof IllegalStateException) { |
| 9691 | throw (IllegalStateException) result; |
| 9692 | } |
| 9693 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9694 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9695 | return specifiers; |
| 9696 | } finally { |
| 9697 | Binder.restoreCallingIdentity(identity); |
| 9698 | } |
| 9699 | } |
| 9700 | |
| 9701 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9702 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9703 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9704 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9705 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9706 | if (iccRecords == null) { |
| 9707 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9708 | return false; |
| 9709 | } |
| 9710 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9711 | } |
| 9712 | |
| 9713 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9714 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9715 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9716 | if (callingPackage == null) { |
| 9717 | callingPackage = getCurrentPackageName(); |
| 9718 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9719 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9720 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9721 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9722 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9723 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9724 | } |
| 9725 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9726 | Intent intent = new Intent(); |
| 9727 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9728 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9729 | // Bring up choose default SMS subscription dialog right now |
| 9730 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9731 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9732 | mApp.startActivity(intent); |
| 9733 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9734 | |
| 9735 | @Override |
| 9736 | public String getMmsUAProfUrl(int subId) { |
| 9737 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9738 | final long identity = Binder.clearCallingIdentity(); |
| 9739 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9740 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9741 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9742 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9743 | return carrierUAProfUrl; |
| 9744 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9745 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9746 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9747 | } finally { |
| 9748 | Binder.restoreCallingIdentity(identity); |
| 9749 | } |
| 9750 | } |
| 9751 | |
| 9752 | @Override |
| 9753 | public String getMmsUserAgent(int subId) { |
| 9754 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9755 | final long identity = Binder.clearCallingIdentity(); |
| 9756 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9757 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9758 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9759 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9760 | return carrierUserAgent; |
| 9761 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9762 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9763 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9764 | } finally { |
| 9765 | Binder.restoreCallingIdentity(identity); |
| 9766 | } |
| 9767 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9768 | |
| 9769 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9770 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9771 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9772 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9773 | final long identity = Binder.clearCallingIdentity(); |
| 9774 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9775 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9776 | if (phone == null) return false; |
| 9777 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9778 | switch (policy) { |
| 9779 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9780 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9781 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9782 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9783 | default: |
| 9784 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9785 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9786 | } finally { |
| 9787 | Binder.restoreCallingIdentity(identity); |
| 9788 | } |
| 9789 | } |
| 9790 | |
| 9791 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9792 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9793 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9794 | enforceModifyPermission(); |
| 9795 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9796 | final long identity = Binder.clearCallingIdentity(); |
| 9797 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9798 | Phone phone = getPhone(subscriptionId); |
| 9799 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9800 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9801 | switch (policy) { |
| 9802 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9803 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9804 | break; |
| 9805 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9806 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9807 | break; |
| 9808 | default: |
| 9809 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9810 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9811 | } finally { |
| 9812 | Binder.restoreCallingIdentity(identity); |
| 9813 | } |
| 9814 | } |
| 9815 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9816 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9817 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9818 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9819 | * otherwise. |
| 9820 | */ |
| 9821 | @Override |
| 9822 | public void setCepEnabled(boolean isCepEnabled) { |
| 9823 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9824 | |
| 9825 | final long identity = Binder.clearCallingIdentity(); |
| 9826 | try { |
| 9827 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9828 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9829 | Phone defaultPhone = phone.getImsPhone(); |
| 9830 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9831 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9832 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9833 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9834 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9835 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9836 | + imsPhone.getMsisdn()); |
| 9837 | } |
| 9838 | } |
| 9839 | } finally { |
| 9840 | Binder.restoreCallingIdentity(identity); |
| 9841 | } |
| 9842 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9843 | |
| 9844 | /** |
| 9845 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9846 | * |
| 9847 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9848 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9849 | * before being read. |
| 9850 | */ |
| 9851 | @Override |
| 9852 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9853 | isCompressed) { |
| 9854 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9855 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9856 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9857 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9858 | } |
| 9859 | if (!isImsAvailableOnDevice()) { |
| 9860 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9861 | "IMS not available on device."); |
| 9862 | } |
| 9863 | |
| 9864 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9865 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9866 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9867 | } finally { |
| 9868 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9869 | } |
| 9870 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9871 | |
| 9872 | @Override |
| 9873 | public boolean isIccLockEnabled(int subId) { |
| 9874 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9875 | |
| 9876 | // Now that all security checks passes, perform the operation as ourselves. |
| 9877 | final long identity = Binder.clearCallingIdentity(); |
| 9878 | try { |
| 9879 | Phone phone = getPhone(subId); |
| 9880 | if (phone != null && phone.getIccCard() != null) { |
| 9881 | return phone.getIccCard().getIccLockEnabled(); |
| 9882 | } else { |
| 9883 | return false; |
| 9884 | } |
| 9885 | } finally { |
| 9886 | Binder.restoreCallingIdentity(identity); |
| 9887 | } |
| 9888 | } |
| 9889 | |
| 9890 | /** |
| 9891 | * Set the ICC pin lock enabled or disabled. |
| 9892 | * |
| 9893 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9894 | * three cases: |
| 9895 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9896 | * successfully. |
| 9897 | * - Positive number and zero for remaining password attempts. |
| 9898 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9899 | * |
| 9900 | */ |
| 9901 | @Override |
| 9902 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9903 | enforceModifyPermission(); |
| 9904 | |
| 9905 | Phone phone = getPhone(subId); |
| 9906 | if (phone == null) { |
| 9907 | return 0; |
| 9908 | } |
| 9909 | // Now that all security checks passes, perform the operation as ourselves. |
| 9910 | final long identity = Binder.clearCallingIdentity(); |
| 9911 | try { |
| 9912 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9913 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9914 | return attemptsRemaining; |
| 9915 | |
| 9916 | } catch (Exception e) { |
| 9917 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9918 | } finally { |
| 9919 | Binder.restoreCallingIdentity(identity); |
| 9920 | } |
| 9921 | return 0; |
| 9922 | } |
| 9923 | |
| 9924 | /** |
| 9925 | * Change the ICC password used in ICC pin lock. |
| 9926 | * |
| 9927 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9928 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9929 | * - Positive number and zero for remaining password attempts. |
| 9930 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9931 | * |
| 9932 | */ |
| 9933 | @Override |
| 9934 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9935 | enforceModifyPermission(); |
| 9936 | |
| 9937 | Phone phone = getPhone(subId); |
| 9938 | if (phone == null) { |
| 9939 | return 0; |
| 9940 | } |
| 9941 | // Now that all security checks passes, perform the operation as ourselves. |
| 9942 | final long identity = Binder.clearCallingIdentity(); |
| 9943 | try { |
| 9944 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9945 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9946 | return attemptsRemaining; |
| 9947 | |
| 9948 | } catch (Exception e) { |
| 9949 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9950 | } finally { |
| 9951 | Binder.restoreCallingIdentity(identity); |
| 9952 | } |
| 9953 | return 0; |
| 9954 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9955 | |
| 9956 | /** |
| 9957 | * Request for receiving user activity notification |
| 9958 | */ |
| 9959 | @Override |
| 9960 | public void requestUserActivityNotification() { |
| 9961 | if (!mNotifyUserActivity.get() |
| 9962 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9963 | mNotifyUserActivity.set(true); |
| 9964 | } |
| 9965 | } |
| 9966 | |
| 9967 | /** |
| 9968 | * Called when userActivity is signalled in the power manager. |
| 9969 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9970 | */ |
| 9971 | @Override |
| 9972 | public void userActivity() { |
| 9973 | // *************************************** |
| 9974 | // * Inherited from PhoneWindowManager * |
| 9975 | // *************************************** |
| 9976 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9977 | // WITH ITS LOCKS HELD. |
| 9978 | // |
| 9979 | // This code must be VERY careful about the locks |
| 9980 | // it acquires. |
| 9981 | // In fact, the current code acquires way too many, |
| 9982 | // and probably has lurking deadlocks. |
| 9983 | |
| 9984 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9985 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9986 | } |
| 9987 | |
| 9988 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9989 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9990 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9991 | } |
| 9992 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9993 | |
| 9994 | @Override |
| 9995 | public boolean canConnectTo5GInDsdsMode() { |
| 9996 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9997 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9998 | |
| 9999 | @Override |
| 10000 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10001 | String callingFeatureId) { |
| 10002 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10003 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10004 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10005 | } |
| 10006 | |
| 10007 | Phone phone = getPhone(subId); |
| 10008 | if (phone == null) { |
| 10009 | throw new RuntimeException("phone is not available"); |
| 10010 | } |
| 10011 | // Now that all security checks passes, perform the operation as ourselves. |
| 10012 | final long identity = Binder.clearCallingIdentity(); |
| 10013 | try { |
| 10014 | return phone.getEquivalentHomePlmns(); |
| 10015 | } finally { |
| 10016 | Binder.restoreCallingIdentity(identity); |
| 10017 | } |
| 10018 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10019 | |
| 10020 | @Override |
| 10021 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10022 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10023 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10024 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10025 | if (radioInterfaceCapabilities == null) { |
| 10026 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10027 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10028 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10029 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10030 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10031 | @Override |
| 10032 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10033 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10034 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10035 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10036 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10037 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10038 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10039 | if (DBG) { |
| 10040 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10041 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10042 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10043 | } |
| 10044 | |
| 10045 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10046 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10047 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10048 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10049 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10050 | if (callback != null) { |
| 10051 | try { |
| 10052 | callback.onAuthenticationFailure( |
| 10053 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10054 | } catch (RemoteException exception) { |
| 10055 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10056 | } |
| 10057 | return; |
| 10058 | } |
| 10059 | } |
| 10060 | |
| 10061 | final long token = Binder.clearCallingIdentity(); |
| 10062 | try { |
| 10063 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10064 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 10065 | forceBootStrapping, callback)); |
| 10066 | } finally { |
| 10067 | Binder.restoreCallingIdentity(token); |
| 10068 | } |
| 10069 | } |
| 10070 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10071 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10072 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10073 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10074 | * requested radio power state will actually be set. See {@link |
| 10075 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10076 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10077 | * @param enable {@code true} if trying to turn radio on. |
| 10078 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10079 | * false}. |
| 10080 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10081 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10082 | boolean isPhoneAvailable = false; |
| 10083 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10084 | Phone phone = PhoneFactory.getPhone(i); |
| 10085 | if (phone != null) { |
| 10086 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 10087 | isPhoneAvailable = true; |
| 10088 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10089 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10090 | |
| 10091 | // return true if successfully informed the phone object about the thermal radio power |
| 10092 | // request. |
| 10093 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10094 | } |
| 10095 | |
| 10096 | private int handleDataThrottlingRequest(int subId, |
| 10097 | DataThrottlingRequest dataThrottlingRequest) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10098 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10099 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10100 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10101 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10102 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10103 | } |
| 10104 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10105 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10106 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10107 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10108 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10109 | } |
| 10110 | |
| 10111 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 10112 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10113 | if (isDataThrottlingSupported) { |
| 10114 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10115 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10116 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10117 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10118 | } else if (thermalMitigationResult |
| 10119 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10120 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10121 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10122 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10123 | } |
| 10124 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10125 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10126 | |
| 10127 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10128 | } |
| 10129 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10130 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10131 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10132 | for (String pckg : context.getResources() |
| 10133 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10134 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10135 | } |
| 10136 | } |
| 10137 | |
| 10138 | return sThermalMitigationAllowlistedPackages; |
| 10139 | } |
| 10140 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10141 | private boolean isAnyPhoneInEmergencyState() { |
| 10142 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10143 | if (tm.isInEmergencyCall()) { |
| 10144 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10145 | return true; |
| 10146 | } |
| 10147 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10148 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10149 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10150 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10151 | + phone.isInEcm()); |
| 10152 | return true; |
| 10153 | } |
| 10154 | } |
| 10155 | |
| 10156 | return false; |
| 10157 | } |
| 10158 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10159 | /** |
| 10160 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10161 | * @param packageName name of package to be allowlisted |
| 10162 | * @param context |
| 10163 | */ |
| 10164 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10165 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10166 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10167 | } |
| 10168 | |
| 10169 | /** |
| 10170 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10171 | * @param packageName name of package to remove from allowlist |
| 10172 | * @param context |
| 10173 | */ |
| 10174 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10175 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10176 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10177 | } |
| 10178 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10179 | /** |
| 10180 | * Thermal mitigation request to control functionalities at modem. |
| 10181 | * |
| 10182 | * @param subId the id of the subscription. |
| 10183 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10184 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10185 | * |
| 10186 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10187 | */ |
| 10188 | @Override |
| 10189 | @ThermalMitigationResult |
| 10190 | public int sendThermalMitigationRequest( |
| 10191 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10192 | ThermalMitigationRequest thermalMitigationRequest, |
| 10193 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10194 | enforceModifyPermission(); |
| 10195 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10196 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10197 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10198 | .contains(callingPackage)) { |
| 10199 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10200 | + "calling package: " + callingPackage); |
| 10201 | } |
| 10202 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10203 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10204 | final long identity = Binder.clearCallingIdentity(); |
| 10205 | |
| 10206 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10207 | try { |
| 10208 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10209 | switch (thermalMitigationAction) { |
| 10210 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10211 | thermalMitigationResult = |
| 10212 | handleDataThrottlingRequest(subId, |
| 10213 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 10214 | break; |
| 10215 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10216 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10217 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10218 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10219 | } |
| 10220 | |
| 10221 | // Ensure that radio is on. If not able to power on due to phone being |
| 10222 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10223 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10224 | thermalMitigationResult = |
| 10225 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10226 | break; |
| 10227 | } |
| 10228 | |
| 10229 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 10230 | false); |
| 10231 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10232 | break; |
| 10233 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10234 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10235 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10236 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10237 | } |
| 10238 | |
| 10239 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10240 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10241 | Phone phone = getPhone(subId); |
| 10242 | if (phone == null) { |
| 10243 | thermalMitigationResult = |
| 10244 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10245 | break; |
| 10246 | } |
| 10247 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10248 | TelephonyConnectionService service = |
| 10249 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10250 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10251 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10252 | thermalMitigationResult = |
| 10253 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10254 | break; |
| 10255 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10256 | thermalMitigationResult = |
| 10257 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10258 | break; |
| 10259 | } |
| 10260 | } else { |
| 10261 | thermalMitigationResult = |
| 10262 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10263 | break; |
| 10264 | } |
| 10265 | |
| 10266 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10267 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10268 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10269 | thermalMitigationResult = |
| 10270 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10271 | break; |
| 10272 | } |
| 10273 | thermalMitigationResult = |
| 10274 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10275 | break; |
| 10276 | default: |
| 10277 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10278 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10279 | } |
| 10280 | } catch (IllegalArgumentException e) { |
| 10281 | throw e; |
| 10282 | } catch (Exception e) { |
| 10283 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10284 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10285 | } finally { |
| 10286 | Binder.restoreCallingIdentity(identity); |
| 10287 | } |
| 10288 | |
| 10289 | if (DBG) { |
| 10290 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10291 | + thermalMitigationResult); |
| 10292 | } |
| 10293 | |
| 10294 | return thermalMitigationResult; |
| 10295 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10296 | |
| 10297 | /** |
| 10298 | * Set the GbaService Package Name that Telephony will bind to. |
| 10299 | * |
| 10300 | * @param subId The sim that the GbaService is associated with. |
| 10301 | * @param packageName The name of the package to be replaced with. |
| 10302 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10303 | */ |
| 10304 | @Override |
| 10305 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10306 | enforceModifyPermission(); |
| 10307 | |
| 10308 | final long identity = Binder.clearCallingIdentity(); |
| 10309 | try { |
| 10310 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10311 | } finally { |
| 10312 | Binder.restoreCallingIdentity(identity); |
| 10313 | } |
| 10314 | } |
| 10315 | |
| 10316 | /** |
| 10317 | * Return the package name of the currently bound GbaService. |
| 10318 | * |
| 10319 | * @param subId The sim that the GbaService is associated with. |
| 10320 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10321 | */ |
| 10322 | @Override |
| 10323 | public String getBoundGbaService(int subId) { |
| 10324 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10325 | |
| 10326 | final long identity = Binder.clearCallingIdentity(); |
| 10327 | try { |
| 10328 | return getGbaManager(subId).getServicePackage(); |
| 10329 | } finally { |
| 10330 | Binder.restoreCallingIdentity(identity); |
| 10331 | } |
| 10332 | } |
| 10333 | |
| 10334 | /** |
| 10335 | * Set the release time for telephony to unbind GbaService. |
| 10336 | * |
| 10337 | * @param subId The sim that the GbaService is associated with. |
| 10338 | * @param interval The release time to unbind GbaService by millisecond. |
| 10339 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10340 | */ |
| 10341 | @Override |
| 10342 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10343 | enforceModifyPermission(); |
| 10344 | |
| 10345 | final long identity = Binder.clearCallingIdentity(); |
| 10346 | try { |
| 10347 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10348 | } finally { |
| 10349 | Binder.restoreCallingIdentity(identity); |
| 10350 | } |
| 10351 | } |
| 10352 | |
| 10353 | /** |
| 10354 | * Return the release time for telephony to unbind GbaService. |
| 10355 | * |
| 10356 | * @param subId The sim that the GbaService is associated with. |
| 10357 | * @return The release time to unbind GbaService by millisecond. |
| 10358 | */ |
| 10359 | @Override |
| 10360 | public int getGbaReleaseTime(int subId) { |
| 10361 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10362 | |
| 10363 | final long identity = Binder.clearCallingIdentity(); |
| 10364 | try { |
| 10365 | return getGbaManager(subId).getReleaseTime(); |
| 10366 | } finally { |
| 10367 | Binder.restoreCallingIdentity(identity); |
| 10368 | } |
| 10369 | } |
| 10370 | |
| 10371 | private GbaManager getGbaManager(int subId) { |
| 10372 | GbaManager instance = GbaManager.getInstance(subId); |
| 10373 | if (instance == null) { |
| 10374 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10375 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10376 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10377 | } |
| 10378 | return instance; |
| 10379 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10380 | |
| 10381 | /** |
| 10382 | * indicate whether the device and the carrier can support |
| 10383 | * RCS VoLTE single registration. |
| 10384 | */ |
| 10385 | @Override |
| 10386 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10387 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10388 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10389 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10390 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10391 | |
| 10392 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10393 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10394 | } |
| 10395 | |
| 10396 | final long identity = Binder.clearCallingIdentity(); |
| 10397 | try { |
| 10398 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10399 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10400 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10401 | if (isCapable != null) { |
| 10402 | return isCapable; |
| 10403 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10404 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10405 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10406 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10407 | } finally { |
| 10408 | Binder.restoreCallingIdentity(identity); |
| 10409 | } |
| 10410 | } |
| 10411 | |
| 10412 | /** |
| 10413 | * Register RCS provisioning callback. |
| 10414 | */ |
| 10415 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10416 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10417 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10418 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10419 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10420 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10421 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10422 | |
| 10423 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10424 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10425 | } |
| 10426 | if (!isImsAvailableOnDevice()) { |
| 10427 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10428 | "IMS not available on device."); |
| 10429 | } |
| 10430 | |
| 10431 | final long identity = Binder.clearCallingIdentity(); |
| 10432 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10433 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10434 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10435 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10436 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10437 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10438 | } finally { |
| 10439 | Binder.restoreCallingIdentity(identity); |
| 10440 | } |
| 10441 | } |
| 10442 | |
| 10443 | /** |
| 10444 | * Unregister RCS provisioning callback. |
| 10445 | */ |
| 10446 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10447 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10448 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10449 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10450 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10451 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10452 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10453 | |
| 10454 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10455 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10456 | } |
| 10457 | if (!isImsAvailableOnDevice()) { |
| 10458 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10459 | "IMS not available on device."); |
| 10460 | } |
| 10461 | |
| 10462 | final long identity = Binder.clearCallingIdentity(); |
| 10463 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10464 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10465 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10466 | } finally { |
| 10467 | Binder.restoreCallingIdentity(identity); |
| 10468 | } |
| 10469 | } |
| 10470 | |
| 10471 | /** |
| 10472 | * trigger RCS reconfiguration. |
| 10473 | */ |
| 10474 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10475 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10476 | "triggerRcsReconfiguration", |
| 10477 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10478 | |
| 10479 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10480 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10481 | } |
| 10482 | if (!isImsAvailableOnDevice()) { |
| 10483 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10484 | "IMS not available on device."); |
| 10485 | } |
| 10486 | |
| 10487 | final long identity = Binder.clearCallingIdentity(); |
| 10488 | try { |
| 10489 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10490 | } finally { |
| 10491 | Binder.restoreCallingIdentity(identity); |
| 10492 | } |
| 10493 | } |
| 10494 | |
| 10495 | /** |
| 10496 | * Provide the client configuration parameters of the RCS application. |
| 10497 | */ |
| 10498 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10499 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10500 | "setRcsClientConfiguration", |
| 10501 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10502 | |
| 10503 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10504 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10505 | } |
| 10506 | if (!isImsAvailableOnDevice()) { |
| 10507 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10508 | "IMS not available on device."); |
| 10509 | } |
| 10510 | |
| 10511 | final long identity = Binder.clearCallingIdentity(); |
| 10512 | |
| 10513 | try { |
| 10514 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10515 | if (configBinder == null) { |
| 10516 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10517 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10518 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10519 | } else { |
| 10520 | configBinder.setRcsClientConfiguration(rcc); |
| 10521 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 10522 | |
| 10523 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 10524 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10525 | } catch (RemoteException e) { |
| 10526 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10527 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10528 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10529 | } finally { |
| 10530 | Binder.restoreCallingIdentity(identity); |
| 10531 | } |
| 10532 | } |
| 10533 | |
| 10534 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10535 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10536 | */ |
| 10537 | @Override |
| 10538 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10539 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10540 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10541 | |
| 10542 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10543 | } |
| 10544 | |
| 10545 | /** |
| 10546 | * Gets the test mode for RCS VoLTE single registration. |
| 10547 | */ |
| 10548 | @Override |
| 10549 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10550 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10551 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10552 | |
| 10553 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10554 | } |
| 10555 | |
| 10556 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10557 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10558 | */ |
| 10559 | @Override |
| 10560 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10561 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10562 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10563 | enforceModifyPermission(); |
| 10564 | |
| 10565 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10566 | : Boolean.parseBoolean(enabledStr); |
| 10567 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10568 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10569 | } |
| 10570 | |
| 10571 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10572 | * Sends a device to device communication message. Only usable via shell. |
| 10573 | * @param message message to send. |
| 10574 | * @param value message value. |
| 10575 | */ |
| 10576 | @Override |
| 10577 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10578 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10579 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10580 | enforceModifyPermission(); |
| 10581 | |
| 10582 | final long identity = Binder.clearCallingIdentity(); |
| 10583 | try { |
| 10584 | TelephonyConnectionService service = |
| 10585 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10586 | if (service == null) { |
| 10587 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10588 | return; |
| 10589 | } |
| 10590 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10591 | } finally { |
| 10592 | Binder.restoreCallingIdentity(identity); |
| 10593 | } |
| 10594 | } |
| 10595 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10596 | /** |
| 10597 | * Sets the specified device to device transport active. |
| 10598 | * @param transport The transport to set active. |
| 10599 | */ |
| 10600 | @Override |
| 10601 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10602 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10603 | "setActiveDeviceToDeviceTransport"); |
| 10604 | enforceModifyPermission(); |
| 10605 | |
| 10606 | final long identity = Binder.clearCallingIdentity(); |
| 10607 | try { |
| 10608 | TelephonyConnectionService service = |
| 10609 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10610 | if (service == null) { |
| 10611 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10612 | return; |
| 10613 | } |
| 10614 | service.setActiveDeviceToDeviceTransport(transport); |
| 10615 | } finally { |
| 10616 | Binder.restoreCallingIdentity(identity); |
| 10617 | } |
| 10618 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10619 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10620 | @Override |
| 10621 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10622 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10623 | "setDeviceToDeviceForceEnabled"); |
| 10624 | |
| 10625 | final long identity = Binder.clearCallingIdentity(); |
| 10626 | try { |
| 10627 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10628 | p -> { |
| 10629 | Phone thePhone = p.getImsPhone(); |
| 10630 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10631 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10632 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10633 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10634 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10635 | (ImsPhoneCallTracker) tracker; |
| 10636 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10637 | } |
| 10638 | } |
| 10639 | } |
| 10640 | ); |
| 10641 | } finally { |
| 10642 | Binder.restoreCallingIdentity(identity); |
| 10643 | } |
| 10644 | } |
| 10645 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10646 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10647 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10648 | */ |
| 10649 | @Override |
| 10650 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10651 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10652 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10653 | } |
| 10654 | |
| 10655 | /** |
| 10656 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10657 | */ |
| 10658 | @Override |
| 10659 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10660 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10661 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10662 | enforceModifyPermission(); |
| 10663 | |
| 10664 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10665 | : Boolean.parseBoolean(enabledStr); |
| 10666 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10667 | subId, enabled); |
| 10668 | } |
| 10669 | |
| 10670 | /** |
| 10671 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10672 | */ |
| 10673 | @Override |
| 10674 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10675 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10676 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10677 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10678 | |
| 10679 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 10680 | * Overrides the ims feature validation result |
| 10681 | */ |
| 10682 | @Override |
| 10683 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 10684 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10685 | "setImsFeatureValidationOverride"); |
| 10686 | |
| 10687 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10688 | : Boolean.parseBoolean(enabledStr); |
| 10689 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 10690 | subId, enabled); |
| 10691 | } |
| 10692 | |
| 10693 | /** |
| 10694 | * Gets the ims feature validation override value |
| 10695 | */ |
| 10696 | @Override |
| 10697 | public boolean getImsFeatureValidationOverride(int subId) { |
| 10698 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10699 | "getImsFeatureValidationOverride"); |
| 10700 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 10701 | } |
| 10702 | |
| 10703 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10704 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10705 | * their mobile plan. |
| 10706 | */ |
| 10707 | @Override |
| 10708 | public String getMobileProvisioningUrl() { |
| 10709 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10710 | final long identity = Binder.clearCallingIdentity(); |
| 10711 | try { |
| 10712 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10713 | } finally { |
| 10714 | Binder.restoreCallingIdentity(identity); |
| 10715 | } |
| 10716 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10717 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10718 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10719 | * Get the EAB contact from the EAB database. |
| 10720 | */ |
| 10721 | @Override |
| 10722 | public String getContactFromEab(String contact) { |
| 10723 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10724 | enforceModifyPermission(); |
| 10725 | final long identity = Binder.clearCallingIdentity(); |
| 10726 | try { |
| 10727 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10728 | } finally { |
| 10729 | Binder.restoreCallingIdentity(identity); |
| 10730 | } |
| 10731 | } |
| 10732 | |
| 10733 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 10734 | * Get the EAB capability from the EAB database. |
| 10735 | */ |
| 10736 | @Override |
| 10737 | public String getCapabilityFromEab(String contact) { |
| 10738 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 10739 | enforceModifyPermission(); |
| 10740 | final long identity = Binder.clearCallingIdentity(); |
| 10741 | try { |
| 10742 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 10743 | } finally { |
| 10744 | Binder.restoreCallingIdentity(identity); |
| 10745 | } |
| 10746 | } |
| 10747 | |
| 10748 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10749 | * Remove the EAB contacts from the EAB database. |
| 10750 | */ |
| 10751 | @Override |
| 10752 | public int removeContactFromEab(int subId, String contacts) { |
| 10753 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10754 | enforceModifyPermission(); |
| 10755 | final long identity = Binder.clearCallingIdentity(); |
| 10756 | try { |
| 10757 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10758 | } finally { |
| 10759 | Binder.restoreCallingIdentity(identity); |
| 10760 | } |
| 10761 | } |
| 10762 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10763 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10764 | public boolean getDeviceUceEnabled() { |
| 10765 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10766 | final long identity = Binder.clearCallingIdentity(); |
| 10767 | try { |
| 10768 | return mApp.getDeviceUceEnabled(); |
| 10769 | } finally { |
| 10770 | Binder.restoreCallingIdentity(identity); |
| 10771 | } |
| 10772 | } |
| 10773 | |
| 10774 | @Override |
| 10775 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10776 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10777 | final long identity = Binder.clearCallingIdentity(); |
| 10778 | try { |
| 10779 | mApp.setDeviceUceEnabled(isEnabled); |
| 10780 | } finally { |
| 10781 | Binder.restoreCallingIdentity(identity); |
| 10782 | } |
| 10783 | } |
| 10784 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10785 | /** |
| 10786 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10787 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10788 | */ |
| 10789 | // Used for SHELL command only right now. |
| 10790 | @Override |
| 10791 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 10792 | List<String> featureTags) { |
| 10793 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10794 | "addUceRegistrationOverrideShell"); |
| 10795 | final long identity = Binder.clearCallingIdentity(); |
| 10796 | try { |
| 10797 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 10798 | new ArraySet<>(featureTags)); |
| 10799 | } catch (ImsException e) { |
| 10800 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10801 | } finally { |
| 10802 | Binder.restoreCallingIdentity(identity); |
| 10803 | } |
| 10804 | } |
| 10805 | |
| 10806 | /** |
| 10807 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10808 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10809 | */ |
| 10810 | // Used for SHELL command only right now. |
| 10811 | @Override |
| 10812 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 10813 | List<String> featureTags) { |
| 10814 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10815 | "removeUceRegistrationOverrideShell"); |
| 10816 | final long identity = Binder.clearCallingIdentity(); |
| 10817 | try { |
| 10818 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 10819 | new ArraySet<>(featureTags)); |
| 10820 | } catch (ImsException e) { |
| 10821 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10822 | } finally { |
| 10823 | Binder.restoreCallingIdentity(identity); |
| 10824 | } |
| 10825 | } |
| 10826 | |
| 10827 | /** |
| 10828 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 10829 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10830 | */ |
| 10831 | // Used for SHELL command only right now. |
| 10832 | @Override |
| 10833 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 10834 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10835 | "clearUceRegistrationOverrideShell"); |
| 10836 | final long identity = Binder.clearCallingIdentity(); |
| 10837 | try { |
| 10838 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 10839 | } catch (ImsException e) { |
| 10840 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10841 | } finally { |
| 10842 | Binder.restoreCallingIdentity(identity); |
| 10843 | } |
| 10844 | } |
| 10845 | |
| 10846 | /** |
| 10847 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10848 | */ |
| 10849 | // Used for SHELL command only right now. |
| 10850 | @Override |
| 10851 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 10852 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10853 | "getLatestRcsContactUceCapabilityShell"); |
| 10854 | final long identity = Binder.clearCallingIdentity(); |
| 10855 | try { |
| 10856 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 10857 | } catch (ImsException e) { |
| 10858 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10859 | } finally { |
| 10860 | Binder.restoreCallingIdentity(identity); |
| 10861 | } |
| 10862 | } |
| 10863 | |
| 10864 | /** |
| 10865 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 10866 | * device does not have an active PUBLISH. |
| 10867 | */ |
| 10868 | // Used for SHELL command only right now. |
| 10869 | @Override |
| 10870 | public String getLastUcePidfXmlShell(int subId) { |
| 10871 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 10872 | final long identity = Binder.clearCallingIdentity(); |
| 10873 | try { |
| 10874 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 10875 | } catch (ImsException e) { |
| 10876 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10877 | } finally { |
| 10878 | Binder.restoreCallingIdentity(identity); |
| 10879 | } |
| 10880 | } |
| 10881 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 10882 | /** |
| 10883 | * Remove UCE requests cannot be sent to the network status. |
| 10884 | */ |
| 10885 | // Used for SHELL command only right now. |
| 10886 | @Override |
| 10887 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 10888 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 10889 | final long identity = Binder.clearCallingIdentity(); |
| 10890 | try { |
| 10891 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 10892 | } catch (ImsException e) { |
| 10893 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10894 | } finally { |
| 10895 | Binder.restoreCallingIdentity(identity); |
| 10896 | } |
| 10897 | } |
| 10898 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 10899 | /** |
| 10900 | * Remove UCE requests cannot be sent to the network status. |
| 10901 | */ |
| 10902 | // Used for SHELL command only. |
| 10903 | @Override |
| 10904 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 10905 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 10906 | final long identity = Binder.clearCallingIdentity(); |
| 10907 | try { |
| 10908 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 10909 | } catch (ImsException e) { |
| 10910 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10911 | } finally { |
| 10912 | Binder.restoreCallingIdentity(identity); |
| 10913 | } |
| 10914 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10915 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10916 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10917 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10918 | String callingPackage) { |
| 10919 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10920 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 10921 | |
| 10922 | final int callingUid = Binder.getCallingUid(); |
| 10923 | // Verify that tha callingPackage belongs to the calling UID |
| 10924 | mApp.getSystemService(AppOpsManager.class) |
| 10925 | .checkPackage(callingUid, callingPackage); |
| 10926 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 10927 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10928 | |
| 10929 | final long identity = Binder.clearCallingIdentity(); |
| 10930 | try { |
| 10931 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10932 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10933 | |
| 10934 | if (result instanceof IllegalStateException) { |
| 10935 | throw (IllegalStateException) result; |
| 10936 | } |
| 10937 | } finally { |
| 10938 | Binder.restoreCallingIdentity(identity); |
| 10939 | } |
| 10940 | } |
| 10941 | |
| 10942 | @Override |
| 10943 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10944 | String callingPackage) { |
| 10945 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10946 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 10947 | |
| 10948 | final int callingUid = Binder.getCallingUid(); |
| 10949 | // Verify that tha callingPackage belongs to the calling UID |
| 10950 | mApp.getSystemService(AppOpsManager.class) |
| 10951 | .checkPackage(callingUid, callingPackage); |
| 10952 | |
| 10953 | final long identity = Binder.clearCallingIdentity(); |
| 10954 | try { |
| 10955 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10956 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10957 | |
| 10958 | if (result instanceof IllegalStateException) { |
| 10959 | throw (IllegalStateException) result; |
| 10960 | } |
| 10961 | } finally { |
| 10962 | Binder.restoreCallingIdentity(identity); |
| 10963 | } |
| 10964 | } |
| 10965 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 10966 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 10967 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10968 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 10969 | // phone/system process do not have further restriction on request |
| 10970 | return; |
| 10971 | } |
| 10972 | |
| 10973 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 10974 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10975 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 10976 | context.enforceCallingOrSelfPermission( |
| 10977 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 10978 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10979 | } |
| 10980 | |
| 10981 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 10982 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 10983 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 10984 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 10985 | || info.isEnabled()) { |
| 10986 | throw new IllegalArgumentException( |
| 10987 | "Only system can set hide fields in SignalThresholdInfo"); |
| 10988 | } |
| 10989 | |
| 10990 | // Thresholds length for each RAN need in range. This has been validated in |
| 10991 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 10992 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 10993 | final int[] thresholds = info.getThresholds(); |
| 10994 | Objects.requireNonNull(thresholds); |
| 10995 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 10996 | || thresholds.length |
| 10997 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 10998 | throw new IllegalArgumentException( |
| 10999 | "thresholds length is out of range: " + thresholds.length); |
| 11000 | } |
| 11001 | } |
| 11002 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11003 | |
| 11004 | /** |
| 11005 | * Gets the current phone capability. |
| 11006 | * |
| 11007 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11008 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11009 | * It's used to evaluate possible phone config change, for example from single |
| 11010 | * SIM device to multi-SIM device. |
| 11011 | */ |
| 11012 | @Override |
| 11013 | public PhoneCapability getPhoneCapability() { |
| 11014 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11015 | final long identity = Binder.clearCallingIdentity(); |
| 11016 | try { |
| 11017 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11018 | } finally { |
| 11019 | Binder.restoreCallingIdentity(identity); |
| 11020 | } |
| 11021 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11022 | |
| 11023 | /** |
| 11024 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11025 | * required to be done shortly after the API is invoked. |
| 11026 | */ |
| 11027 | @Override |
| 11028 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11029 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11030 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11031 | enforceRebootPermission(); |
| 11032 | |
| 11033 | final long identity = Binder.clearCallingIdentity(); |
| 11034 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11035 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11036 | } finally { |
| 11037 | Binder.restoreCallingIdentity(identity); |
| 11038 | } |
| 11039 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11040 | |
| 11041 | /** |
| 11042 | * Request to get the current slicing configuration including URSP rules and |
| 11043 | * NSSAIs (configured, allowed and rejected). |
| 11044 | * |
| 11045 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11046 | */ |
| 11047 | @Override |
| 11048 | public void getSlicingConfig(ResultReceiver callback) { |
| 11049 | enforceReadPrivilegedPermission("getSlicingConfig"); |
| 11050 | |
| 11051 | final long identity = Binder.clearCallingIdentity(); |
| 11052 | try { |
| 11053 | Phone phone = getDefaultPhone(); |
| 11054 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11055 | } finally { |
| 11056 | Binder.restoreCallingIdentity(identity); |
| 11057 | } |
| 11058 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11059 | |
| 11060 | /** |
| 11061 | * Register an IMS connection state callback |
| 11062 | */ |
| 11063 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11064 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11065 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11066 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11067 | // ImsMmTelManager |
| 11068 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11069 | TelephonyPermissions |
| 11070 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11071 | mApp, subId, "registerImsStateCallback"); |
| 11072 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11073 | // ImsRcsManager or SipDelegateManager |
| 11074 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11075 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11076 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11077 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11078 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11079 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11080 | } |
| 11081 | |
| 11082 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11083 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11084 | "IMS not available on device."); |
| 11085 | } |
| 11086 | |
| 11087 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11088 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11089 | } |
| 11090 | |
| 11091 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11092 | if (controller == null) { |
| 11093 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11094 | "IMS not available on device."); |
| 11095 | } |
| 11096 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11097 | if (callingPackage == null) { |
| 11098 | callingPackage = getCurrentPackageName(); |
| 11099 | } |
| 11100 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11101 | final long token = Binder.clearCallingIdentity(); |
| 11102 | try { |
| 11103 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11104 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11105 | } catch (ImsException e) { |
| 11106 | throw new ServiceSpecificException(e.getCode()); |
| 11107 | } finally { |
| 11108 | Binder.restoreCallingIdentity(token); |
| 11109 | } |
| 11110 | } |
| 11111 | |
| 11112 | /** |
| 11113 | * Unregister an IMS connection state callback |
| 11114 | */ |
| 11115 | @Override |
| 11116 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11117 | final long token = Binder.clearCallingIdentity(); |
| 11118 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11119 | if (controller == null) { |
| 11120 | return; |
| 11121 | } |
| 11122 | try { |
| 11123 | controller.unregisterImsStateCallback(cb); |
| 11124 | } finally { |
| 11125 | Binder.restoreCallingIdentity(token); |
| 11126 | } |
| 11127 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 11128 | } |